Microservices

Definition

Microservices is an architectural approach where a single application is built as a suite of small services, each running in its own process and communicating via APIs (typically HTTP/REST or message queues). Each service is independently deployable, scalable, and owned by a small team.


Core Ideas

Microservices vs Monolith

DimensionMonolithMicroservices
DeploymentSingle unitIndependent per service
ScalingScale everythingScale only what’s needed
TechnologySingle stackPolyglot (service chooses)
Failure isolationWhole app at riskFailures contained
ComplexitySimple to startDistributed system overhead

Key Principles

  • Single Responsibility — each service does one thing well
  • Owns its data — no shared databases between services; each has its own store
  • API-first — services communicate exclusively via published APIs
  • Failure tolerance — designed for partial failure (circuit breakers, retries, timeouts)
  • Independently deployable — CI/CD pipeline per service

Communication Patterns

Synchronous

  • REST over HTTP/HTTPS
  • gRPC (Protocol Buffers, streaming)
  • GraphQL

Asynchronous

  • Message queues: SQS, RabbitMQ, Kafka
  • Event-driven: services publish events; consumers react
  • Saga pattern for distributed transactions

Design Patterns

  • API Gateway — single entry point routing to services (AWS API Gateway)
  • BFF (Backend for Frontend) — API tailored per client type (mobile, web, third-party)
  • Sidecar — co-deployed helper container (logging, proxy, mTLS)
  • Service Mesh — infrastructure layer handling service-to-service communication (Istio)
  • CQRS — separate read and write models for performance and clarity
  • Event Sourcing — state as ordered event log; enable audit and replay

Challenges

  • Distributed tracing — tracking a request across many services (Jaeger, AWS X-Ray)
  • Data consistency — no ACID across services; use eventual consistency
  • Service discovery — how services find each other (Kubernetes DNS, Consul)
  • Operational overhead — many services = many pipelines, logs, dashboards

Relationships


References

  • Software Architecture Diagram Collection (canvas in source/)