10 Microservices Best Practices for the Optimal Architecture Design

Sandeep Jandhyala
May 26 · 7 min read
3 figurines of male construction workers wearing yellow hats, standing on a black computer keyboard
3 figurines of male construction workers wearing yellow hats, standing on a black computer keyboard

Microservices have fundamentally changed the way server side engines are architected. Rather than a single giant monolithic codebase hosting all the business logic of your application, microservices reflect the distributed systems model, where a group of application components work together to deliver the business needs. By following ten basic microservices best practices, you can achieve an efficient microservices ecosystem devoid of unnecessary architectural complexities.

Benefits of a Microservices Architecture

  1. You should be able to develop a microservice in a language of your choice, release it independently at your own pace, and scale it independently.
  2. Since different teams in an organization can independently own certain microservices, time to market should be faster as there is parallel development with more reuse.
  3. You get better fault isolation, as errors in one particular microservice can be contained, so the rest of the ecosystem would not be impacted.

However, if proper principles are not followed when building microservices, you can end up with an entangled spaghetti like this.

web of grey rectangles with black text in it pointing to grey cylinder with black text in it
web of grey rectangles with black text in it pointing to grey cylinder with black text in it

This becomes very difficult to maintain, as it requires a lot of coordination with multiple teams to make changes, release or achieve fault tolerance.

Making the most of microservices is a science and involves some discipline. The microservices best practices and design principles below will help you build microservices that are loosely coupled, distributed, and optimized to deliver best value.

10 Microservices Best Practices

1. The Single Responsibility Principle

Example: Let’s say you are building microservices for ordering a pizza. You can consider building the following components based on the functionality each supports like InventoryService, OrderService, PaymentsService, UserProfileService, DeliveryNotificationService, etc. InventoryService would only have APIs that fetch or update the inventory of pizza types or toppings, and likewise others would carry the APIs for their functionality.

2. Have a separate data store(s) for your microservice

3. Use asynchronous communication to achieve loose coupling

a. Make calls to your dependencies asynchronously, example below.

Example: Let’s say you have a Service A that calls Service B. Once Service B returns a response, Service A returns success to the caller. If the caller is not interested in Service B’s output, then Service A can asynchronously invoke Service B and instantly respond with a success to the caller.

b. An even better option is to use events for communicating between microservices. Your microservice would publish an event to a message bus either indicating a state change or a failure and whichever microservice is interested in that event, would pick it up and process it.

Example: In the pizza order system above, sending a notification to the customer once their order is captured, or status messages as the order gets fulfilled and delivered, can happen using asynchronous communication. A notification service can listen to an event that an order has been submitted and process the notification to the customer.

4. Fail fast by using a circuit breaker to achieve fault tolerance

5. Proxy your microservice requests through an API Gateway

6. Ensure your API changes are backwards compatible

7. Version your microservices for breaking changes

8. Have dedicated infrastructure hosting your microservice

Example: In the pizza order example above, let’s say the inventory microservice uses an inventory database. It is not only important for the Inventory Service to have dedicated host machines, but also the inventory database needs to have dedicated host machines.

9. Create a separate release train

10. Create Organizational Efficiencies

***

References

Circuit Breaker
bliki: CircuitBreaker
It’s common for software systems to make remote calls to software running in different processes, probably on different…martinfowler.com

Originally published at https://www.capitalone.com.

Related:

Image for post
Image for post

DISCLOSURE STATEMENT: © 2020 Capital One. Opinions are those of the individual author. Unless noted otherwise in this post, Capital One is not affiliated with, nor endorsed by, any of the companies mentioned. All trademarks and other intellectual property used or displayed are property of their respective owners.

Capital One Tech

The low down on our high tech from the engineering experts…

Sandeep Jandhyala

Written by

Technologist , Leader , Blogger

Capital One Tech

The low down on our high tech from the engineering experts at Capital One. Learn about the solutions, ideas and stories driving our tech transformation.

Sandeep Jandhyala

Written by

Technologist , Leader , Blogger

Capital One Tech

The low down on our high tech from the engineering experts at Capital One. Learn about the solutions, ideas and stories driving our tech transformation.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store