Communication Patterns
Service-to-service communication is one of the load-bearing decisions in a SaaS architecture. The shape of communication determines how the system behaves under load, how it tolerates failure, and how easily it can evolve. The choices ripple through four properties at once:
The Spectrum
Real systems mix both. The skill is choosing per interaction.
Synchronous: REST APIs
HTTP REST APIs remain the foundation. Simple, debuggable, supported everywhere.
Synchronous: GraphQL
Synchronous: RPC and gRPC
RPC abstracts network communication so calling a remote function looks like calling a local one. Modern implementations (gRPC) layer in strong typing, code generation, binary serialization on top of HTTP/2.
Asynchronous: Message Queues
Message queues decouple services by letting them exchange data without waiting for an immediate response.
This pattern significantly improves system resilience. The cost is operational: you now have a queue to monitor, dead-letter queues to drain, consumer-lag dashboards to watch.
Asynchronous: Event Streaming
Streaming platforms like Apache Kafka provide real-time data streams where services publish events as they occur, and other services subscribe to relevant streams.
The key shift is publish to a log, not call a service. Producers donโt know whoโs listening; consumers can rewind, replay, and arrive late. Kafka gets a deep dive in Section 5.
Asynchronous: Pub/Sub
Pub/Sub messaging lets services broadcast events to multiple interested parties without knowing whoโs listening.
Order Service
โ
[purchase.completed]
โ โ โ
Inventory Email Analytics
Service Service Service
HTTP Protocol Evolution
For internal service-to-service on stable networks, HTTP/2 is the modern default. For client-facing on the public internet โ especially mobile โ HTTP/3 has the edge.
Bidirectional: WebSockets
WebSockets provide bidirectional persistent connections between clients and servers.
The trade-off is operational: load-balancing persistent connections is harder, connection management gets non-trivial at scale, reconnection logic needs deliberate design.
Message Delivery Guarantees
Order and Durability
Global ordering is expensive and usually unnecessary. Most โwe need orderingโ requirements are actually โwe need ordering per entityโ โ which partition keys give you.
Durability, live updates, and outside calls
Durability is whether a message still exists after a failure. An in-memory queue is fast and can lose data. A persistent queue survives failures, which only holds once you have chosen the storage and replication strategy.
Real-time interaction uses two channels. WebSockets or Server-Sent Events push updates to clients. HTTP APIs carry the user actions that modify state. When several people act at the same time, operational transforms or conflict-free replicated data types (CRDTs) resolve the conflicts and keep the interaction responsive.
Image processing, report generation, and data analysis should stay off the request path. A queue takes the work, the caller gets an immediate response, and status comes back through a WebSocket or by polling.
Payment processors, email services, analytics platforms, and other third-party APIs need retry logic so an external failure stays outside the core request path. A webhook lets the partner notify you and removes the polling loop. Webhooks need careful security handling, and the handler must be idempotent, because the same delivery can arrive more than once.
HTTP/2 adds server push. The protocol fits APIs that make many small requests or return large amounts of data, and most modern load balancers and API gateways already support HTTP/2. Messaging platforms such as Apache Kafka, Amazon SQS, and Google Pub/Sub hide the wire protocol and add message filtering and automatic scaling. AMQP suits reliable enterprise messaging; MQTT suits lightweight IoT. Delivery, ordering, and durability matter more than which of those protocols is on the wire.
Choosing the Right Pattern
The most successful applications donโt rely on a single pattern. They use the right one for each specific need:
Recap
- Communication patterns are architectural decisions shaping reliability, performance, scalability, maintainability.
- Synchronous (REST, GraphQL, gRPC) gives immediate feedback but creates tight coupling and risks cascading failures.
- Asynchronous (queues, streaming, pub/sub) decouples services and improves fault tolerance, at the cost of operational complexity.
- Most production systems mix patterns: sync where users wait, async everywhere else.
- Message delivery guarantees and ordering ripple through the system.