News and Notes from the Makers of Nexus | Sonatype Blog

10 Best Practices for Microservice Architectures

Written by Derek Weeks | May 27, 2018

Switching to microservice architecture will solve all of your software architecture problems.

Right?  Okay, it won’t.  But there is value to be found in the journey.

Hüseyin Babal recently made the point the a microservices based architecture would not solve all problems. However, it is a solid move to modernize your infrastructure. We all know the challenges of sustaining a monolithic architecture over many years, so we seek new alternatives to sustainability, flexibility, and ease of integration.  Implementing microservices architecture with a foundation of best practices can drastically improve your software architecture.

Hüseyin is a Chief Software Architect at Aurea and consults for Kloia. His recent talk, Ultimate Guide to Microservice Architecture, covers much of the experiences  he works through each day and presents best practices to implement microservice architectures.

In his talk, he uses Spring Boot for application development, Consul for service discovery, Elasticsearch & Kibana for Monitoring, and Docker & Jenkins for Continuous Delivery. He covers each, including numerous code examples, with ten best practices.

 

Best Practice #1 - Try to reach Glory of REST.


Realize the benefits (nay, the glory) of REST APIs. Looking at Leonard Richardson’s Maturity Model, there are four levels of using REST. You can start a level 0, which is soft resources, using one endpoint; then Level 1, which has different resources, but has the same HTTP method; Level 2, which uses different HTTP methods, such as POST, PUT, DELETE, etc.; finally, Level 3 - you have navigational resources on your API responses. Behold, the glory!

 

Best Practice #2 - Using Spring HATEOAS. This helps you use navigable, restful APIs.

 

Best Practice #3 - Use distributed configuration so you aren’t configuring 50 different configurations one at a time. Consul can be used to keep config at Key/Value.


Best Practice #4 - Client code generation. Hüseyin suggests, “either using Swagger to generate your client code on any supported language or use feign client with a little annotation and client side load balancing with Ribbon.”



Best Practice #5 - Continuous Delivery. Hüseyin walks through some examples using Jenkins and Docker.



Best Practice #6 - Monitor. In fact, monitor everything.


Best Practice #7 - Logging. Hüseyin points out there are numerous Docker log drivers. He walks through examples with GELF (Graylog Extended Log Format).

Best Practice #8 - APM - Application performance management. This collects extra details to help you troubleshoot issues. Zipkin is an open source option Hüseyin walks through.

Best Practice #9 - API gateways to aggregate data to specific clients.


Best Practice #10 - Event sourcing and CQRS (Command and Query Responsibility Segregation). A Command alters the state of an object, but does not return data. A Query returns data, but does not alter the state of the object.

You can watch Hüseyin’s full talk here. He walks through technical examples and solutions to each best practice.

Craving more on Modern Infrastructure and DevOps?  Binge watch any of the 20 sessions, free of charge, from All Day DevOps here.