Where microservice development benefits from automation

A look at the stages of designing an API and service.

By Andy Oram
February 28, 2018
Texture Texture (source: Pxhere.com)

The growing popularity of microservices and APIs has led developers to automate the repetitive aspects of these technologies, such as defining all the RESTful requests, generating templates for the target code, and scaling out new instances. In this article, I’ll explore the tasks in designing a microservice and suggest the parts that can respond to automation.

Microservices are just a cloud-friendly and Agile-friendly implementation of the decades-old concept of modularity. I suggested the radical modular breakdown of applications in a 2002 article, saying that: “the application, once the central fixture of computer use, would dissolve into a soup of servers, application fragments, and user interfaces.” By encapsulating tasks into separate services, parts of an application can be developed independently, deployed efficiently as containers, and scaled out automatically with new instances as traffic grows.

Learn faster. Dig deeper. See farther.

Join the O'Reilly online learning platform. Get a free trial today and find answers on the fly, or master something new and useful.

Learn more

Microservice creation falls into a few distinct stages.

The design stage

After first deciding what goes into each microservice—an architectural task on its own—the developer has to determine what “verbs” or “actions” to offer. For instance, the verbs on a retail site might include browsing, adding to a shopping cart, buying, and rating.

You also have to decide how fine-grained and nested your RESTful API should be. Does a clothing site offer subdivisions into garments (blouses, pants) that are further subdivided by style, fabric, size, and color? The API would be simpler if it just accepted a product ID that is unique to each garment type, style, fabric, size, and color. However, a more granular and nested subdivision may make it easier to call up the particular garments the visitor wants while browsing. (For instance, a visitor who is allergic to some fabrics or who has to match a certain color may want to restrict the search.)

Numerous decisions require a high-level view and discussion of the API. The API can also get quite complex, as just shown with the clothing example, and may be hard to keep consistent. Visualization tools and automation can save valuable time and avoid errors.

The coding stage

The API functions as a specification or contract defining inputs, outputs, and the expected behavior of the service. Generating the service itself and the client that sends requests can get very complicated. Here again, it makes sense to automate the generation of JSON specifications or JavaScript stubs instead of asking programmers to write them by hand. A programmer can then fill in the stub. Some of the operations exposed by API providers may also benefit from boilerplate implementations, such as database access or error messaging.

The deployment stage

Finally, although microservices simplify and speed up deployment, a lot of configuration is still required in the background. You need to retrieve the latest source code from a repository, build it, and submit it to the target system for testing or deployment. It’s also critical to install updates quickly as bugs are found and fixed. Furthermore, you have to decide when to start a new instance because of heavy traffic and handle other container issues, which calls for interaction with the platform on which you run your code (such as Kubernetes) or other deployment tools that help you scale your microservices. There are ways to automate these processes.

Conclusion

Microservices are currently understood to be the most effective way to serve large groups of users and make the best use of virtualization and the cloud. Organizations that can automate key parts of the development process will deploy their applications faster and suffer fewer embarrassing bugs. You don’t have to reinvent the wheel: several companies offer tools for this automation.

This post is a collaboration between O’Reilly and TIBCO. See our statement of editorial independence.

Post topics: Software Architecture
Share: