iTranslated by AI
How We Automate Development for Zenn: A Community for Engineers
I am dyoshikawa from the Zenn team.
I recently gave a presentation at Open Seminar Hiroshima 2024 titled "Automation Mechanisms Supporting the Development Team of the Engineer-Focused Community Zenn."
According to Connpass, there were 57 participants.
The event theme was "XRE - Organizations Supporting Engineers." Since many of the other speakers were SREs and I am not, I was wondering what I should talk about. However, the organizers told me:
"It's fine as long as it fits broadly within the theme of 'something that supports engineers.'"
So, I decided to present under this title.
You can find the SpeakerDeck here:
I prepared the script word-for-word for this presentation, so I've decided to refine it slightly and post it as an article.
Introduction and Self-Introduction

Let's get started.
My name is Yoshikawa from the Zenn team at Classmethod, Inc. Today, I will be speaking on the theme of "Automation Mechanisms Supporting the Development Team of the Engineer-Focused Community Zenn." Thank you for having me.

I have already uploaded the slides to SpeakerDeck. If you would like to follow along with the materials, please check the "Materials" section at the bottom of the Open Seminar Hiroshima 2024 Connpass page to open the SpeakerDeck link.
Let's begin.

Here is a brief self-introduction.
I operate under the handle dyoshikawa. I am a software engineer living in Hiroshima City.
Currently, I develop the Zenn service using Next.js for the frontend, Ruby on Rails for the backend, and Google Cloud for infrastructure. Previously, I developed using AWS serverless architectures with AWS Lambda and DynamoDB, as well as Node.js, PHP Laravel, and Vue.js for backends.
My certifications include the Applied Information Technology Engineer Examination and AWS Certified Security - Specialty.

Recently, I have also been working on leveraging generative AI. As a finalist in the "Generative AI Innovation Awards" at the Google Cloud Generative AI Summit Tokyo 2024 Autumn, I participated in the final pitch competition.
There must have been 200 or 300 people listening. I was incredibly nervous, and for some reason, I couldn't stop coughing right before my turn, but I managed to finish my speech. Unfortunately, I didn't win an award, but it was a very good experience.
I will discuss the case study I presented there later in the section on specific initiatives.

Here is what I will talk about today.
First, I will introduce Zenn and discuss why we tackle automation in the first place and why we should.
Next, I will introduce our specific initiatives. I will cover the introduction of static analysis through linters, formatters, and type checking for source code, as well as test automation, CI/CD setup, and the use of generative AI.
Finally, I will discuss what is necessary for further automation and provide an overall summary.
Introduction
About Zenn

First, I would like to introduce Zenn.
May I ask a quick question? Is there anyone here who is familiar with Zenn? Even just having heard of it is fine.
(Most of the audience raised their hands.)
Thank you.

Now, has anyone here ever read or actually written an article on Zenn?
(About 70-80% of the audience raised their hands.)
Thank you.

Zenn is an information-sharing community for engineers.
I think it is easier to understand if you actually take a look, so if you don't mind, I would appreciate it if you could access zenn.dev on your devices while listening to this presentation.
On Zenn, you can share knowledge through three posting formats: Articles for reflecting on problem-solving, Books for selling summarized content in more volume than articles, and Scraps for personal notes or discussions with other users. Authors of articles can also receive financial compensation.
Another strength is our active community. We have over 13 million monthly page views, more than 120,000 registered users, and over 900 Publications—a group feature that allows companies and organizations to aggregate their articles.

Zenn was released in 2020 as a personally developed service by someone named Catnose.
After that, Classmethod became the operating company in 2021.
Currently, it is operated by a team of six: three engineers, one designer, one business member, and one operator.

Here is the technical stack of Zenn.
Zenn is built primarily on Google Cloud. We use Cloud Run for computing, hosting the frontend (Next.js) and the backend (Ruby on Rails) applications. We also use Rails and Cloud Run for task workers involved in batch processing. Our databases are hosted on Cloud SQL.
Although not shown in this diagram, we have recently introduced Cloudflare for CDN and WAF, using it alongside Google Cloud.
Why We Automate

Before entering the section on specific initiatives, I would like to share my thoughts on why we automate in the first place.
First of all, for automatable tasks, especially routine ones, it is simply "faster and more accurate" than doing them manually. Once the mechanism is complete, repetitive routine work can be finished instantly. Unlike humans, it does not make careless mistakes, nor is it affected by fatigue or a decline in concentration.
Furthermore, I believe that the more we advance the automation of development and operations, the more we can scale the value we produce while keeping the team size the same.

I believe that by creating time through automation, we can tackle more creative tasks.
If the majority of your day is filled with immediate routine tasks, you will be so busy with existing work that you won't have time to improve your flow. Even when new issues arise, you won't have the leisure to deliberate thoroughly, so you will often end up dealing with them manually in a makeshift manner. This creates a vicious cycle where routine tasks continue to increase.

Conversely, if you can compress the time spent on routine tasks through automation, you can dedicate the saved time to deliberation. Even when new issues arise, you will be able to build mechanisms that go beyond temporary fixes.
Additionally, beyond new issues, you can also start working on further improving the efficiency of existing operations for which you have already built automation mechanisms.

Some might say, "No, real-world work isn't that simple."
I think so myself as well.
For example, what if you could automate something, but it is so difficult that the effort to create the mechanism exceeds the man-hours saved by automation? Also, should you immediately automate a simple task that might only be performed once?
To these questions, I believe that if you are careful about selecting the target and the timing, you can achieve high effects with little effort.
Breaking down tasks and finding tasks with high cost-effectiveness by automating them—this is target selection. For example, it is difficult to automate all of code review, but it is easy to automate checking coding styles using a Linter or Formatter.
Deciding to automate only after it is confirmed that you will repeat the same task—this is timing selection. For testing and deployment, since it is confirmed that they will be repeated, it is better to have automation in mind from the start. On the other hand, for example, regarding data patch support in response to user inquiries, it is debatable whether you should prepare an administrative function that can update data with a single button from the very first time. I think it is best to start building the mechanism at the point when it has happened a few times and you judge that it will continue to be repeated in the future.
In this presentation, while focusing mainly on initiatives where it is almost certain that the return will exceed the introduction cost in an engineering organization, I will also interweave and introduce issues that arose specifically at Zenn.
Specific Initiatives

Now, I would like to introduce the specific initiatives we are implementing at Zenn.
Static Code Analysis

First, let's talk about static code analysis.
For Zenn's frontend, we have adopted Prettier as our formatter, ESLint as our linter, and TypeScript as our language to perform type checking.
In the backend, we use RuboCop, which serves as both our formatter and linter.

By introducing a formatter and linter, we can automate the checks for routine aspects of code review.
What do we mean by routine aspects of code review? It is the unification of coding style. Since this is an item that can be checked mechanically, it is faster and more accurate to let a tool handle it rather than a human.

A formatter handles the unification of spaces, indentation, line breaks, and so on.
Generally, you will set coding guidelines for spaces and indentation to maintain readability, but I believe it is impossible to have these fully adhered to through human review. It is not worth the effort for a reviewer to count the spaces in every changed line of code, nor is it essential.
However, if there is no unification at all, the code will gradually become harder to read. Therefore, by introducing a formatter, you can reliably unify these elements at a very low cost.

And it is the linter that unifies the code from the perspective of so-called "how to write."
For example, in JavaScript and TypeScript, it can suggest using let or const instead of var for variable definitions, or in Ruby, it can ensure that conditions are unified across the entire codebase—for instance, choosing between if not foo and unless foo.
Furthermore, linters are extremely useful for detecting unused variables, redundant code, and code that deviates from best practices, then issuing errors.

By automating routine code review checks with a formatter and linter, reviewers can concentrate on non-routine aspects such as software design, performance, and secure coding.
Overall, the formatter and linter lower the burden of code review, and since code review is something that is guaranteed to be repeated during development, I believe this initiative is extremely cost-effective.

For the frontend, because we have adopted the TypeScript language, type checking is added to our static analysis. This allows for the detection of many errors before the code is executed.
Type checking is, in fact, a form of testing, known as static testing. The reason it is called "static" is that the test is conducted without executing the code.
The commonly referred to "testing" is strictly dynamic testing. This involves tests in which the code is actually executed.
In the frontend of web services, it feels like there are quite a few workplaces that don't write many dynamic test codes, but rather make the decision to use manual testing from a browser and automated E2E testing as a base, combined with static testing via TypeScript. As for the reason, I think that in web service frontends, there is often heavy reliance on browser APIs which makes mocking difficult, there is less business logic compared to the backend, and the specifications are less stable and change more frequently than in the backend, making it relatively harder to feel the value of writing tests.
Given these circumstances, I believe that the presence of TypeScript in modern frontend application quality assurance is very significant.
Also, as is the strength of statically typed languages in general, another benefit of adopting TypeScript is that accurate code completion is realized on the IDE, which improves development efficiency.
Test Automation

The next initiative is test automation.
For the frontend, we perform automated tests using Vitest and React Testing Library, and for the backend, we use RSpec.
Additionally, to test the frontend and backend in an integrated manner, we have adopted Playwright as our E2E testing tool.

When we talk about frontend testing, there are tests that involve rendering React components in a Node.js environment, as well as visual regression tests that check whether the UI is broken before and after code changes. However, at present, Zenn's tests are limited to utility functions and React Hooks.
We do feel this is an area for improvement, but given that quality is ensured to a certain extent by TypeScript and E2E tests, and with only three engineers on the team, we are currently in a situation where we cannot easily expand our frontend tests.

For backend tests, we use RSpec to write tests at the model and controller level. Since most of these involve behavioral tests that include reading from and writing to the RDB, our integration tests are larger in volume than our unit tests.
Compared to the frontend, our testing is in a much more robust state.

And then there is E2E testing.
This is achieved with Playwright. We used to use Cypress, but we decided to migrate about a year ago because it was difficult to use all the features without paying the developers of Cypress, and because Playwright was gaining prominence as an E2E testing tool at the time.
By automatically manipulating the browser, we can test the frontend and backend in one go. Even if you test the frontend and backend thoroughly, it is common for things not to work due to discrepancies in the definitions of the interfaces connecting them, so the existence of this test is also extremely important.
However, because the effort required to write and maintain tests tends to be higher compared to RSpec, because test results can be unstable—that is, they sometimes fail—and because automated tests take time to run, it is generally said in concepts like the Testing Pyramid and Testing Trophy that it is most cost-effective to limit E2E test cases to a certain extent. In fact, I agree with this.

I am committed to test automation because I want to scale the service without increasing the size of the team, and without sacrificing development speed or quality.
Here, let's consider a case of creating a service from zero to one.
In this service development, we decided not to introduce automated testing at all and to ensure quality through manual testing.
First, we developed and tested only the initial feature A, and performed the first release. The testing effort was 1 person-month.
Next, we added feature B, which affects feature A, and released it. The testing effort for feature B was also 1 person-month. Since it affects feature A, we need to test both feature A and feature B. Therefore, it took 2 person-months for testing.
Furthermore, we added feature C, which affects feature A and feature B, and released it. The testing effort for feature C was 1 person-month. Since it affects the existing features A and B, we need to test all of feature A, feature B, and feature C. Therefore, 3 person-months were required for testing.

On the other hand, let's consider another case of creating a service from zero to one.
In this service development, we decided to write test code and automate the testing.
First, we developed and tested only the initial feature A, and performed the first release. The effort to create the test code was 1 person-month.
Next, we added feature B, which affects feature A, and released it. The effort to create the test code for feature B was also 1 person-month. Although it affects feature A, the test code for feature A already exists, so we only needed 0.1 person-months of corrections. Therefore, adding and modifying the test code took 1.1 person-months.
Furthermore, we added feature C, which affects feature A and feature B, and released it. The effort to create the test code for feature C was 1 person-month. Although it affects the existing features A and B, the test codes for feature A and feature B already exist, so we only needed 0.2 person-months of corrections for this as well. Therefore, 1.2 person-months were required for the test code.

This may have been a somewhat extreme assumption, but what do you think?
In the automated testing example, I factored in a little bit of the effort required to modify existing features. I think this trend exists in actual projects as well.
No matter how much you automate testing, the size of the codebase—10,000 lines versus 100,000 lines—will affect development speed and the difficulty of quality assurance. However, I believe that by introducing automated testing, you can significantly moderate the decline in productivity. Even if the scale of the service expands, you can prevent testing effort from snowballing like a double-your-money game.
This allows you to scale the service without increasing the number of people on the development team. Also, the cost of executing test code is extremely low, so basically, it can be run instantaneously as many times as you like. Therefore, with automated testing, it is possible to increase test coverage each time you release. While manual testing resets every time you perform it and change the source code, test code can be accumulated.
As for automated testing, since it is almost certain that you will repeatedly execute it throughout the project, I believe it is an investment that requires more effort than introducing static analysis, but also brings a greater return.
CI/CD Setup

Next is the CI/CD setup.
At Zenn, we have implemented CI/CD using this mechanism.
Currently, we use a combination of GitHub Actions and Google Cloud's Cloud Build as our CI/CD foundation. GitHub Actions does not handle deployment; it focuses on static analysis and automated testing. Cloud Build is used for building and pushing Docker images, as well as for deploying to Cloud Run. Source code is managed in a GitHub repository.
When a developer creates a pull request, GitHub Actions is triggered, and static analysis and automated tests are executed.
Once it passes GitHub Actions and code review, the developer merges the code into the main branch. This triggers Cloud Build to create a new container image and push it to the Artifact Registry.
Then, via the gcloud command, we create a new revision of Cloud Run and send a command to Slack for traffic switching.
Finally, the developer executes the traffic switching command in Cloud Shell to complete the release.

Here, let's briefly review the definitions of CI and CD.
CI stands for Continuous Integration.
It is a development method where code changes are automatically and frequently integrated into a repository. By running automated tests and builds frequently, we can achieve early detection of issues.

CD stands for either Continuous Delivery or Continuous Deployment.
I also learned this when researching for this presentation, but CD is the step that follows CI. Continuous Delivery refers to maintaining a state where deployment to the production environment is always possible—in other words, it covers everything up to the point just before deployment.
On the other hand, Continuous Deployment refers to automating the deployment to the production environment itself.

At Zenn, I consider the static analysis checks and automated tests performed via GitHub Actions to be CI, and the container image building and sending of deployment commands to Slack via Cloud Build to be the Continuous Delivery side of CD.
The reason we distinguish them this way is that our policy is not to include Google Cloud access keys or secret keys in GitHub Actions.
We utilize Slack in a ChatOps manner, allowing administrators to release just by copying and pasting the command displayed in Slack. Even when executing commands, we use Cloud Shell to ensure that release commands are executed regardless of the individual terminal environment.
We have not fully automated the final deployment—meaning we haven't implemented Continuous Deployment, but rather Continuous Delivery. While this leaves some room for manual intervention, I believe it has settled into a good balance considering the size of our team.
Utilizing Generative AI

Next, let's talk about utilizing generative AI.
Up until now, only routine tasks were the target of automation—that's true for static analysis, automated testing, and CI/CD.
However, with the advent of generative AI, I believe there is now room to automate non-routine tasks as well.

So, what can it be used for?
Here, I will introduce a case where we actually applied generative AI to Zenn's operational tasks.
I'll explain from the background of why we needed the power of generative AI. Around June of this year, spam posts increased rapidly on Zenn. Large amounts of spam content, such as content leading to specific URLs, were being posted. At its worst, the new arrival list was completely buried in spam. I felt that this would severely degrade the reader experience, so an immediate response was required.

Therefore, we built a system that has generative AI crawl through new content to perform spam detection and report violations. For the generative AI model, we selected Gemini on Google Cloud.
First, we provide the criteria for what constitutes spam to Gemini via a prompt. Then, a Ruby on Rails worker equipped with Gemini crawls the content and performs spam detection.
If it is suspected to be spam, it reports a violation. Human administrators confirm the violation report and take action against the target account or content.
Through this effort, we were able to minimize human labor. As a result, we achieved an 85% reduction in suspected spam posts and, while it is an estimate, a 75% reduction in operational costs.
This kind of effort was difficult to achieve with traditional string matching or rule-based methods. While addressing issues beyond those frameworks previously required specialists in machine learning and natural language processing, for us, who do not have such specialists, it was groundbreaking in that we could achieve decent results just by thinking about natural language prompts.
By the way, as an aside, I talked about this case at a Google Cloud event pitch competition, and a judge commented, "So you're saying that generative AI has made machine learning specialists unnecessary, right?" Of course, they said this in a positive context, and I don't think the judge meant anything else by it, but I personally do not think that "such talent has become unnecessary." I believe that if we had specialists in machine learning in the team, there would have been a higher possibility of achieving our goals more flexibly and with higher accuracy. The pitch was limited to 5 minutes, so I think my explanation was insufficient.
I would just like to emphasize that "people without that know-how were able to achieve something decent. In that sense, generative AI is groundbreaking."

Utilization of generative AI is also advancing in development work. I think many people are already using ChatGPT, Claude, and Gemini in combination with Google Search during development.
Personally, when developing with libraries or frameworks I'm using for the first time, I have the impression that the work that previously required writing code while referring to tutorial documents or StackOverflow code has been significantly streamlined. GitHub Copilot, which has a more integrated experience with coding editors, is also becoming widespread. It has been introduced in our company as well.

At our company, development combining GitHub Copilot and an in-house tool called AI-Starter is becoming the standard.
To explain AI-Starter briefly, it is a tool that allows you to switch between major generative AI models such as GPT, Claude, and Gemini from a single UI. We utilize GitHub Copilot as coding support when developing in VSCode, and use AI-Starter for general questions or when we want to use models other than those from OpenAI.

However, one thing to be careful about is that generative AI is not all-knowing or all-powerful.
Since I am not an expert in this field, I looked it up myself, and generative AI outputs text by taking in a massive amount of text in the world and stringing together words that have a high probability of coming next. This means that generative AI's responses are determined by a majority vote based on the massive amount of text it has absorbed. And, what is decided by a majority vote is not necessarily correct, is it? Therefore, there may be mistakes when viewed by an expert.
There are also reports that when code generation is requested from ChatGPT's o1-preview model, code with vulnerabilities is generated.

When using generative AI, I think it is best to operate on the premise of developing by multiplying yourself—the specialist—with generative AI, rather than having the mindset of leaving everything to it.
And above all, I want to keep in mind that it is humans who are responsible for the quality of the deliverables.
Conclusion

Thank you for listening this far.
This is the "Conclusion."
To Further Automate

Finally, I would like to wrap up with the topic of "further automation."
First, take steps and introduce things incrementally. If you try to do too much at once, you will likely end up achieving nothing and failing.
Also, I think it is important to start small. Break down existing tasks and look for areas where it is easy to start automating.
And by reliably completing small automations, I hope you can accumulate success stories within the organization. As concrete examples accumulate, the benefits of automation will move from theoretical merits to something the entire team is convinced of, and they should start to work on it proactively.

Another thing is to cherish HRT. HRT stands for Humility, Respect, and Trust.
First, recognize that there is no such thing as an environment without issues. And do not get frustrated and view team members who don't seem to be working toward a solution as enemies. There is almost always a rational reason why an issue remains unsolved or appears to be.
Even if you blame those around you and turn them into enemies, it only takes you further away from solving the issue. They say "hate the sin, not the sinner," and it is just like that—I want to think "versus the problem" rather than "versus someone."
I myself sometimes have arrogant feelings, expect things from others on my own and get disappointed on my own, and end up getting frustrated. This was also a reminder to myself.

Summary
Here is the summary.
First, I talked about why we automate in the first place. For this, I mentioned that it is because machines are faster and more accurate than humans, and that we want to create time to dedicate to more creative tasks.
Next, I introduced our concrete efforts. These include the automation of routine tasks such as static analysis to streamline code reviews, automated testing to make development more scalable, and the maintenance of CI/CD.
I also introduced the automation of non-routine tasks using generative AI and its application to development work. And, to promote automation, I talked about proceeding incrementally without trying to bite off more than we can chew.
Finally, I stated that the most important thing is to move forward while cherishing HRT.

That is all for my presentation. I would be happy if this talk serves as even a small reference for you all. Thank you very much.
Discussion
HRTは大事ですね!ふだん働いてるなかで、「これはHRTが不足しているな」と感じる言動や予兆はありますか?