Microservice Design Patterns

From bibbleWiki
Jump to navigation Jump to search

Introduction

This page is to provide an override of microservice design patterns

Patterns and Dates Introduced

  • Circuit Breaker (1998-2000s)
  • Event Sourcing (2005-2010s)
  • CQRS (2008-2010s)
  • Saga Pattern (2010s)
  • API Gateway (2010s)
  • Sidecar Pattern (2014-2016)
  • Database Per Service (2015-2017)
  • Backend for Frontend (BFF) (2015-2018)

Database Per Service - Popular

This pattern ensures each microservice has its own database, reducing dependencies and enabling scalability. It prevents cross-service data issues but requires careful synchronization strategies. Widely used in microservices architecture, companies like Netflix and Amazon implement this to ensure service autonomy.

API Gateway Highly Popular

An API Gateway acts as a single entry point for client requests, routing them to appropriate microservices while handling authentication, rate limiting, and caching. It simplifies management and security. Popular solutions like AWS API Gateway, Kong, and NGINX are widely adopted by enterprises.

Backend For Frontend (BFF) Gaining Popularity

BFF is a specialized API layer that tailors backend responses for specific front-end clients, improving efficiency and user experience. It is commonly used in multi-platform applications by companies like Spotify and Netflix to optimize performance.

CQRS - Moderately Popular

CQRS separates read and write operations into different models, improving scalability and performance. This is particularly useful for event-driven applications and high-traffic systems. It’s widely used in banking, e-commerce, and real-time applications.

Event Sourcing - Niche

Instead of storing only the current state, event sourcing logs all state changes as events. This ensures auditability and allows time-travel debugging. Popular in financial systems and blockchain-based applications, it’s used by companies like Uber and Walmart.

Saga - Popular in distributed systems

The Saga pattern manages distributed transactions in microservices through a series of compensating actions, ensuring consistency without locking resources. Common in e-commerce and banking, it’s used by businesses like Shopify and PayPal.

Sidecar Highly Popular in Cloud-Native Apps

Sidecar deploys auxiliary services alongside main applications, enhancing observability, security, and networking without modifying the core service. It’s a key component of service meshes like Istio and Linkerd, widely used in Kubernetes deployments.

Circuit Breaker - Very Popular

A circuit breaker prevents system failures by detecting faults and stopping requests to failing services, allowing recovery. Netflix popularized this with Hystrix, and it remains a best practice in resilient microservice architectures.

Database Per Service,API Gateway,BFF,CQRS,Event Sourcing,Saga,Sidecar,Circuit Breaker

Other Stuff

Watch this here and very entertaining about the death of Microservices.

  • Cost of Software will be minimized if parts can be solvable separately and manageably small
  • Microservices are software component architectual style as scale
    • Components via services
    • Organized around Business Capabilities
    • Smart endpoints and dumb pipes
    • Design for failure
    • Infrastructure automation
    • Decentralized Data Management
    • Decentralized Governance
    • Products not Projects

Quite liked the Nanoservice bit which demonstrated when the microservice is micro

He talked about the cost of owning the software vs building the software. More software more ownership and ownership isn't just one year. So build more software may not be the answer. Reducing cost of ownership is.

Really liked this was of capturing domains for ticketing using domain story telling.

I was introduced to the term ACID transactions which I googled to find here. I think it basically means

  • Atomic All or nothing
  • Consistent Follows integrity rules for the whole transactions
  • Isolation Lock around the data to stop other modifications
  • Durability It is persisted, i.e. no flushing