Communication Patterns
Design inter-service communication that is efficient, scalable, and resilient
Why Communication Matters
Services must communicate to coordinate work. How they communicate—synchronously or asynchronously, tightly or loosely coupled—shapes the entire system's behavior under load, during failures, and as it scales.
Seven Core Patterns
1. API Styles
Different protocols for different needs. REST is simple and ubiquitous. gRPC is fast and efficient. GraphQL is flexible for complex queries.
Topics:
- REST for simplicity and compatibility
- gRPC for performance and streaming
- GraphQL for client-driven queries
- WebSockets for real-time bidirectional communication
- Server-Sent Events (SSE) for server-to-client streaming
2. Synchronous vs Asynchronous
The fundamental choice: does A wait for B's response, or does A fire and forget?
Topics:
- Request-response coupling and latency trade-offs
- When synchronous makes sense
- When asynchronous is necessary
- Hybrid approaches
3. Messaging Patterns
Asynchronous communication through message brokers. Queues for ordered processing, topics for broadcast.
Topics:
- Message queues (point-to-point)
- Topics and subscriptions (publish-subscribe)
- Event streams (distributed logging)
- Ordering guarantees and idempotency
4. API Gateway
The entry point for external traffic. Handles routing, rate limiting, authentication, and aggregation.
Topics:
- Routing and path-based dispatch
- Request/response transformation
- Rate limiting and quota management
- Authentication and authorization
- Aggregating multiple backend services
5. Service Discovery
How does Service A find Service B when services scale horizontally and instances appear/disappear?
Topics:
- Client-side discovery (lookup, then call)
- Server-side discovery (route through load balancer)
- Service registry patterns
- Health checking and stale instance removal
6. Service Mesh
An infrastructure layer that handles communication concerns transparently. Services don't worry about retries, timeouts, tracing—the mesh handles it.
Topics:
- Transparent interception of service calls
- Mutual TLS between services
- Distributed tracing
- Circuit breaking at the infrastructure level
- Load balancing and traffic shaping
7. Webhooks and Callbacks
Server-initiated communication to clients. B calls back to A when something happens.
Topics:
- Event-driven integrations
- Guaranteed delivery with retries
- Handling duplicate webhook deliveries
- Webhook security and verification
Learning Path
Total Time: 50 minutes
- Start (7 min): API Styles - Know your options
- Foundation (10 min): Sync vs Async - Make the core choice
- Asynchronous (8 min): Messaging - Event-driven architecture
- Client Entry (6 min): API Gateway - Handling external traffic
- Service Lookup (7 min): Service Discovery - Finding services
- Infrastructure (7 min): Service Mesh - Transparent communication layer
- Server-Initiated (6 min): Webhooks & Callbacks - Events to clients
Key Decisions
| Question | Synchronous | Asynchronous |
|---|---|---|
| "Does A wait for B?" | Yes, A blocks | No, A continues |
| Latency | Request-response latency | Low initial latency, eventual delivery |
| Coupling | Tight (A depends on B running) | Loose (B can be down temporarily) |
| Ordering | Easy (request order = response order) | Hard (messages arrive out of order) |
| Scalability | Limited (A exhausts waiting) | High (services decouple) |
| Consistency | Can enforce immediately | Must accept eventual consistency |
Communication Topology
Before You Move On
You should understand:
- Trade-offs between different API styles (REST, gRPC, GraphQL)
- When synchronous communication makes sense (and when it doesn't)
- How to decouple services with asynchronous messaging
- The role of gateways, discovery, and mesh in managing communication
- How webhooks enable event-driven integrations
Next Section
Once you've mastered communication patterns, layer in Resilience Patterns to handle the failures that inevitably occur when services communicate across networks.
📄️ API Styles
Master REST, gRPC, GraphQL, WebSockets, and SSE. Choose the right API style for your service communication needs.
📄️ Synchronous vs Asynchronous Communication
Choose between synchronous request-response and asynchronous messaging. Understand coupling, latency, and availability trade-offs.
📄️ Messaging Patterns
Master message queues, publish-subscribe, and event streams. Choose the right pattern for your asynchronous communication.
📄️ Service Discovery
Master client-side and server-side service discovery. Enable services to find each other in dynamic, horizontally-scaling environments.
📄️ Service Mesh
Manage service-to-service communication using a service mesh.
📄️ Webhooks and Callbacks
Master event-driven integrations: webhooks for server-initiated callbacks, signing for security, and handling idempotency and retries.
📄️ API Gateway
Centralize request routing, authentication, and rate limiting using an API gateway.
References
- Fowler, M., & Lewis, J. (2014). "Microservices". martinfowler.com.
- Newman, S. (2015). "Building Microservices". O'Reilly Media.
- Richardson, C. (n.d.). "Microservice Architecture Pattern Language". microservices.io.
- Indrasiri, K., & Kulatunga, D. (2021). "Microservices Development Cookbook". Packt.