{"id":81,"date":"2025-11-02T08:20:28","date_gmt":"2025-11-02T08:20:28","guid":{"rendered":"https:\/\/axedgeconsulting.com\/blog\/?p=81"},"modified":"2026-09-05T05:22:41","modified_gmt":"2026-09-05T05:22:41","slug":"microservices-patterns","status":"publish","type":"post","link":"https:\/\/axedgeconsulting.com\/blog\/?p=81","title":{"rendered":"Microservices Patterns"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>What are microservices?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Microservices &#8211; also known as the\nmicroservice architecture &#8211; is an architectural style that structures an\napplication as a collection of services that are<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Highly maintainable and testable<\/li><li>Loosely coupled<\/li><li>Independently deployable<\/li><li>Organized around business capabilities<\/li><li>Owned by a small team<\/li><li>Design Patterns for Microservices<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Microservice architecture has\nbecome the de facto choice for modern application development. Though it solves\ncertain problems, it is not a silver bullet. It has several drawbacks and when\nusing this architecture, there are numerous issues that must be addressed. This\nbrings about the need to learn common patterns in these problems and solve them\nwith reusable solutions. Thus, design patterns for microservices need to be\ndiscussed. Before we dive into the design patterns, we need to understand on\nwhat principles microservice architecture has been built:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Scalability<\/li><li>Availability<\/li><li>Resiliency<\/li><li>Independent, autonomous<\/li><li>Decentralized governance<\/li><li>Failure isolation<\/li><li>Auto-Provisioning<\/li><li>Continuous delivery through DevOps<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The microservice architecture is\nnot a silver bullet. It has several drawbacks. Moreover, when using this\narchitecture there are numerous issues that you must address.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The microservice architecture\npattern language is a collection of patterns for applying the microservice\narchitecture. It has two goals:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The pattern language enables you to decide\nwhether microservices are a good fit for your application.<\/li><li>The pattern language enables you to use the\nmicroservice architecture successfully.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Applying all these principles\nbrings several challenges and issues. Let&#8217;s discuss those problems and their\nsolutions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Application architecture patterns<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Decomposition<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to decompose an application\ninto services?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Decompose by business capability &#8211; define\nservices corresponding to business capabilities<\/li><li>Decompose by subdomain &#8211; define services\ncorresponding to DDD subdomains<\/li><li>Self-contained Service &#8211; design services to\nhandle synchronous requests without waiting for other services to respond<\/li><li>Service per team &#8211; Each service is owned by a\nteam, which has sole responsibility for making changes.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. Data management<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to maintain data consistency\nand implement queries?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Database per Service &#8211; each service has its own\nprivate database<\/li><li>Shared database &#8211; services share a database<\/li><li>Saga &#8211; use sagas, which a sequences of local\ntransactions, to maintain data consistency across services<\/li><li>API Composition &#8211; implement queries by invoking\nthe services that own the data and performing an in-memory join<\/li><li>CQRS &#8211; implement queries by maintaining one or\nmore materialized views that can be efficiently queried<\/li><li>Domain event &#8211; publish an event whenever data\nchanges<\/li><li>Event sourcing &#8211; persist aggregates as a\nsequence of events<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. Transactional messaging<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to publish messages as part\nof a database transaction?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Transactional outbox<\/li><li>Transaction log tailing<\/li><li>Polling publisher<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4. Testing<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to make testing easier?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Consumer-driven contract test &#8211; a test suite for\na service that is written by the developers of another service that consumes it<\/li><li>Consumer-side contract test &#8211; a test suite for a\nservice client (e.g. another service) that verifies that it can communicate\nwith the service<\/li><li>Service component test &#8211; a test suite that tests\na service in isolation using test doubles for any services that it invokes<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5. Deployment patterns<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to deploy an application\u2019s\nservices?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Multiple service instances per host &#8211; deploy\nmultiple service instances on a single host<\/li><li>Service instance per host &#8211; deploy each service\ninstance in its own host<\/li><li>Service instance per VM &#8211; deploy each service\ninstance in its VM<\/li><li>Service instance per Container &#8211; deploy each\nservice instance in its container<\/li><li>Serverless deployment &#8211; deploy a service using\nserverless deployment platform<\/li><li>Service deployment platform &#8211; deploy services\nusing a highly automated deployment platform that provides a service\nabstraction<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>6. Cross cutting concerns<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to handle cross cutting\nconcerns?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Microservice chassis &#8211; a framework that handles\ncross-cutting concerns and simplifies the development of services<\/li><li>Externalized configuration &#8211; externalize all\nconfiguration such as database location and credentials<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Communication patterns<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Style<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Which communication mechanisms do\nservices use to communicate with each other and their external clients?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Remote Procedure Invocation &#8211; use an RPI-based\nprotocol for inter-service communication<\/li><li>Messaging &#8211; use asynchronous messaging for\ninter-service communication<\/li><li>Domain-specific protocol &#8211; use a domain-specific\nprotocol<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. External API<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How do external clients\ncommunicate with the services?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>API gateway &#8211; a service that provides each\nclient with unified interface to services<\/li><li>Backend for front-end &#8211; a separate API gateway\nfor each kind of client<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. Service discovery<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How does the client of an\nRPI-based service discover the network location of a service instance?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Client-side discovery &#8211; client queries a service\nregistry to discover the locations of service instances<\/li><li>Server-side discovery &#8211; router queries a service\nregistry to discover the locations of service instances<\/li><li>Service registry &#8211; a database of service instance\nlocations<\/li><li>Self-registration &#8211; service instance registers\nitself with the service registry<\/li><li>3rd party registration &#8211; a 3rd party registers a\nservice instance with the service registry<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4. Reliability<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to prevent a network or\nservice failure from cascading to other services?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Circuit Breaker &#8211; invoke a remote service via a\nproxy that fails immediately when the failure rate of the remote call exceeds a\nthreshold<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5. Security<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to communicate the identity\nof the requestor to the services that handle the request?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Access Token &#8211; a token that securely stores\ninformation about user that is exchanged between services<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>6. Observability<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to understand the behavior of\nan application and troubleshoot problems?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Log aggregation &#8211; aggregate application logs<\/li><li>Application metrics &#8211; instrument a service\u2019s\ncode to gather statistics about operations<\/li><li>Audit logging &#8211; record user activity in a\ndatabase<\/li><li>Distributed tracing &#8211; instrument services with\ncode that assigns each external request an unique identifier that is passed\nbetween services. Record information (e.g. start time, end time) about the work\n(e.g. service requests) performed when handling the external request in a\ncentralized service<\/li><li>Exception tracking &#8211; report all exceptions to a\ncentralized exception tracking service that aggregates and tracks exceptions\nand notifies developers.<\/li><li>Health check API &#8211; service API (e.g. HTTP\nendpoint) that returns the health of the service and can be pinged, for\nexample, by a monitoring service<\/li><li>Log deployments and changes<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>UI patterns<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to implement a UI screen or\npage that displays data from multiple services?<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Server-side page fragment composition &#8211; build a\nwebpage on the server by composing HTML fragments generated by multiple,\nbusiness capability\/subdomain-specific web applications<\/li><li>Client-side UI composition &#8211; Build a UI on the\nclient by composing UI fragments rendered by multiple, business\ncapability\/subdomain-specific UI components<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>What are microservices? Microservices &#8211; also known as the microservice architecture &#8211; is an architectural style that structures an application as a collection of services that are Highly maintainable and testable Loosely coupled Independently deployable Organized around business capabilities Owned by a small team Design Patterns for Microservices Microservice architecture has become the de facto &hellip; <a href=\"https:\/\/axedgeconsulting.com\/blog\/?p=81\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Microservices Patterns&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[31],"class_list":["post-81","post","type-post","status-publish","format-standard","hentry","category-computing","tag-microservices"],"_links":{"self":[{"href":"https:\/\/axedgeconsulting.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/axedgeconsulting.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/axedgeconsulting.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/axedgeconsulting.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/axedgeconsulting.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=81"}],"version-history":[{"count":1,"href":"https:\/\/axedgeconsulting.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":82,"href":"https:\/\/axedgeconsulting.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/81\/revisions\/82"}],"wp:attachment":[{"href":"https:\/\/axedgeconsulting.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/axedgeconsulting.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/axedgeconsulting.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}