Best Practices in Microservices Architecture

Best Practices in Microservices Architecture

I am trying to summarize the best practices in microservices architecture. Please check the followings and try to follow most out of them:

Design philosophy: The granularity of microservices should be based on following design principles:

  • Business functionality: Each microservice should be designed to depict one business functionality.
  • Independence: Each microservice should be independently upgradeable without impacting the service consumers. The database, storage systems should be managed by microservices.
  • Coupling and Cohesion: Coupling between microservices should be avoided and each microservice should have high functionality cohesion.

Governance: We should define standards for development, deployment and functionality/performance validation.

Distributed Design: As the system is composed of multiple microservices, we need to have optimal service decomposition, clean interfaces for services and appropriate databases for each service.

Naming Conventions: The microservices’ URL is usually a noun that represents a resource. We will use the schema to perform the appropriate actions. For example:

  • GET api/v1/accounts will list all accounts
  • PUT api/v1/account/1234 adds/updates the account id 1234
  • DELETE api/v1/account/1234 deletes the account id 1234

Versioning: The microservice releases are managed through versions, which are a part of the microservices endpoint.

DevOps setup: We need to set up the DevOps ecosystem to include the build and deployment pipeline.

Automation: To reduce the operational complexity of microservices architecture, we need to automate operational tasks such as build, deployment, error reporting, alerting, monitoring, auto-scaling and others.

Design for failure: We need to implement features such as the following to handle failures:

  • Auto-scaling: Leverage the auto-scaling feature of the container ecosystem to automatically scale based on the user load.
  • Circuit Breaker: Design the circuit breaker pattern to handle the service exception and fallback to default service response.

Logging: Logging must be enabled to capture the errors using centralized dashboard tools such as Kibana, Splunk to monitor the logs and errors. We should design and log unique request ids that can help us to trace a user transaction end to end.

Monitoring and alerting: Monitoring tools should be used to observe the performance and availability of the microservices. Additional monitoring services can be configured to monitor the disk space, CPU utilization and others. Appropriate thresholds should be configured to alert the operations teams in case of SLA violation.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了