10 Best Practices for Microservice Architectures
Make sure you're striving for these microservices best practices in your distributed systems, like monitoring and REST maturity.
Join the DZone community and get the full member experience.Join For Free
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 that 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 the 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 — Use Spring HATEOAS
This helps you use navigable, restful APIs.
Best Practice #3 — Use Distributed Configuration
This way, 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
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.
Published at DZone with permission of Derek Weeks, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.