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
| Dimension | Monolith | Microservices |
|---|---|---|
| Deployment | Single unit | Independent per service |
| Scaling | Scale everything | Scale only what’s needed |
| Technology | Single stack | Polyglot (service chooses) |
| Failure isolation | Whole app at risk | Failures contained |
| Complexity | Simple to start | Distributed 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
- Kubernetes — primary runtime for microservice deployments
- System Design — microservices appear in system design interview questions
- Cloud & AWS Infrastructure — AWS services that enable microservice architectures
- Hexagonal Architecture — the ports-and-adapters answer to how services keep a boundary while talking to each other
References
- Software Architecture Diagram Collection (canvas in source/)