Microservices Architecture
Microservices architecture is an approach to building software as a collection of small, independently deployable services, each owning a specific business capability and communicating over well-defined APIs.
What It Really Means
Instead of building one large application that handles everything — user authentication, order processing, payments, notifications — you decompose it into separate services. Each service runs its own process, manages its own data store, and can be developed, deployed, and scaled independently.
The defining characteristic is not size. It is independence. A microservice can be deployed without coordinating with other teams. It can be rewritten in a different language without affecting the rest of the system. It can scale horizontally based on its own traffic patterns. This independence enables organizational scaling — teams can own services end-to-end without stepping on each other.
Microservices emerged from real engineering constraints at companies like Netflix, Amazon, and Spotify. Amazon's famous "two-pizza teams" mandate in the early 2000s drove them to decompose their monolith into services that could be owned by small, autonomous teams. Netflix followed when their monolithic DVD rental application could not support the scale and velocity required for streaming. The pattern was formalized by James Lewis and Martin Fowler in 2014.
How It Works in Practice
Real System Example: E-Commerce Platform
Consider an e-commerce platform decomposed into microservices:
- User Service — authentication, profiles, preferences (PostgreSQL)
- Product Catalog Service — product listings, search, categories (Elasticsearch + PostgreSQL)
- Cart Service — shopping cart management (Redis)
- Order Service — order lifecycle, status tracking (PostgreSQL)
- Payment Service — payment processing, refunds (PostgreSQL + payment gateway)
- Notification Service — email, SMS, push notifications (message queue + third-party APIs)
- Inventory Service — stock levels, warehouse allocation (PostgreSQL)
Each service has its own database (database-per-service pattern), its own CI/CD pipeline, and its own team. The Cart Service uses Redis because it needs fast reads and writes for ephemeral session data. The Product Catalog Service uses Elasticsearch because it needs full-text search. Each service chooses the technology that fits its specific requirements.
Communication Patterns
Synchronous (REST/gRPC): The Order Service calls the Payment Service to charge a credit card and waits for the response. Use for operations that require an immediate result.
Asynchronous (Message Queues): When an order is placed, the Order Service publishes an OrderPlaced event to a message broker. The Notification Service, Inventory Service, and Analytics Service each consume this event independently. Use for operations that can happen eventually and should not block the user. See event-driven architecture for deeper coverage.
Service Discovery and Routing
Services need to find each other. In Kubernetes, DNS-based service discovery is built in — payment-service.default.svc.cluster.local resolves to the current instances. Outside Kubernetes, you use a service registry like Consul or Eureka. An API gateway handles external client routing, authentication, and rate limiting.
Implementation