Skip to main content

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.

Communication Decision Tree

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

  1. Start (7 min): API Styles - Know your options
  2. Foundation (10 min): Sync vs Async - Make the core choice
  3. Asynchronous (8 min): Messaging - Event-driven architecture
  4. Client Entry (6 min): API Gateway - Handling external traffic
  5. Service Lookup (7 min): Service Discovery - Finding services
  6. Infrastructure (7 min): Service Mesh - Transparent communication layer
  7. Server-Initiated (6 min): Webhooks & Callbacks - Events to clients

Key Decisions

QuestionSynchronousAsynchronous
"Does A wait for B?"Yes, A blocksNo, A continues
LatencyRequest-response latencyLow initial latency, eventual delivery
CouplingTight (A depends on B running)Loose (B can be down temporarily)
OrderingEasy (request order = response order)Hard (messages arrive out of order)
ScalabilityLimited (A exhausts waiting)High (services decouple)
ConsistencyCan enforce immediatelyMust accept eventual consistency

Communication Topology

Common Communication Patterns

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.

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.