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