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.
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 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.
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.