What is a Microservice? A Simple Explanation for Developers
A microservice is a small, independent piece of your application that does one thing and runs on its own.
Instead of one big application (a monolith) that handles everything β users, payments, emails, search β you split it into separate services that communicate over APIs.
Monolith vs Microservices
Monolith:
βββββββββββββββββββββββββββ
β Users + Orders + Email β
β + Search + Payments β
β (one codebase, one DB) β
βββββββββββββββββββββββββββ
Microservices:
ββββββββββββ ββββββββββββ ββββββββββββ
β Users β β Orders β β Email β
β Service ββββ Service ββββ Service β
ββββββββββββ ββββββββββββ ββββββββββββ
β β
ββββββββββββ ββββββββββββ
β Search β β Payments β
β Service β β Service β
ββββββββββββ ββββββββββββ
Each service:
- Has its own codebase
- Has its own database
- Can be deployed independently
- Can be written in a different language
- Communicates via HTTP/REST, GraphQL, or message queues
When to use microservices
- β Large team (10+ developers) β teams can own individual services
- β Different parts need different scaling (search gets 100x more traffic than payments)
- β You need to deploy parts independently (update payments without touching users)
- β Different parts need different tech stacks
- β Small team or solo developer β the overhead will slow you down
- β Early-stage startup β you donβt know your domain well enough yet
- β Simple application β a monolith is simpler and faster to build
The honest advice: Start with a monolith. Split into microservices when you feel the pain of the monolith. Most apps never need microservices.
How services communicate
Synchronous (request/response)
- REST API β HTTP calls between services. Simple, widely used.
- gRPC β binary protocol, faster than REST. Popular in Go and Java.
Asynchronous (events)
- Message queues β RabbitMQ, AWS SQS. Service A publishes an event, Service B processes it later.
- Event streaming β Kafka, Redis Pub/Sub. Real-time event processing.
The hard parts
Microservices solve some problems but create new ones:
- Network failures β services go down, networks are unreliable
- Data consistency β no more single database transactions
- Debugging β a request touches 5 services, where did it fail?
- Deployment complexity β you need Docker, Kubernetes, CI/CD
- Monitoring β you need distributed tracing, centralized logging
Essential infrastructure for microservices
Running microservices in production requires tooling that monoliths donβt need:
- Service discovery β services need to find each other. Tools like Consul, Kubernetes DNS, or AWS Cloud Map handle this.
- API Gateway β a single entry point that routes external requests to the right service. Handles auth, rate limiting, and request routing. Nginx or Kong are common choices.
- Distributed tracing β follow a request across multiple services. Jaeger, Zipkin, or Datadog trace requests end-to-end so you can find where latency or errors occur.
- Centralized logging β aggregate logs from all services into one place (ELK stack, Grafana Loki). Without this, debugging is impossible.
- Health checks and circuit breakers β detect when a service is unhealthy and stop sending it traffic. Prevents cascading failures where one broken service takes down everything.
Real-world example
An e-commerce platform might split into:
ββββββββββββββ ββββββββββββββ ββββββββββββββ
β Product β β Cart β β Payment β
β Catalog β β Service β β Service β
β (Node.js) β β (Go) β β (Java) β
ββββββββββββββ ββββββββββββββ ββββββββββββββ
β β β
ββββββββββββββ ββββββββββββββ ββββββββββββββ
β Search β β Shipping β β Email β
β (Elastic) β β (Python) β β (Node.js) β
ββββββββββββββ ββββββββββββββ ββββββββββββββ
Each team owns their service end-to-end: code, database, deployment, and on-call. The product catalog team can deploy 10 times a day without coordinating with the payment team.
FAQ
How small should a microservice be?
A microservice should be small enough that a single team (2-8 people) can own it completely, and it should represent one bounded business domain. If a service requires constant coordination with another service to make changes, theyβre probably too tightly coupled and should be merged or the boundary redrawn.
Can microservices share a database?
They shouldnβt. Sharing a database creates tight coupling β changes to one serviceβs schema can break another service. Each microservice should own its data and expose it only through its API. If services need each otherβs data, they request it via API calls or subscribe to events.
How do I migrate from a monolith to microservices?
Start by identifying the most independent, well-bounded piece of your monolith and extract it first. Use the βstrangler figβ pattern: route traffic for that domain to the new service while the rest stays in the monolith. Repeat gradually β donβt try to split everything at once, as that almost always fails.
Related: You Dont Need Microservices