Building Service Communication Patterns
1. Implementing Synchronous Communication
| Property | Detail |
|---|---|
| Model | Caller blocks until response |
| Coupling | Temporal — both must be available |
| Latency | Sum of hops |
| Examples | HTTP, gRPC unary, JDBC |
| Risk | Cascading failures; backpressure must propagate |
2. Implementing Asynchronous Communication
| Property | Detail |
|---|---|
| Model | Send-and-forget; reply later or never |
| Coupling | Decoupled in time |
| Examples | Kafka, SQS, RabbitMQ, async webhooks |
| Pros | Buffer load spikes; resilient to consumer failure |
| Cons | Harder to reason; eventual consistency |
3. Implementing Remote Procedure Calls (RPC, gRPC)
Example: gRPC service definition
service OrderService {
rpc CreateOrder(CreateOrderRequest) returns (Order);
rpc StreamOrders(StreamRequest) returns (stream Order);
rpc UploadEvents(stream Event) returns (UploadAck);
rpc Chat(stream Msg) returns (stream Msg);
}
| Mode | Use |
|---|---|
| Unary | Standard request/response |
| Server stream | Server pushes many; client one |
| Client stream | Client uploads; server one |
| Bidirectional | Full duplex (chat, telemetry) |
| Transport | HTTP/2 + protobuf |
4. Implementing RESTful APIs
| Constraint | Detail |
|---|---|
| Stateless | Each request self-contained |
| Resource-oriented | Nouns in URL, verbs as methods |
| Uniform interface | Standard HTTP semantics |
| Cacheable | ETag, Cache-Control |
| Layered | Proxies, gateways transparent |
5. Implementing GraphQL APIs
| Feature | Detail |
|---|---|
| Single endpoint | POST /graphql |
| Client-defined query | Fetch only needed fields |
| Schema-first | SDL defines types/queries/mutations |
| Subscriptions | Real-time over WS |
| Pitfalls | N+1 (use DataLoader); query complexity DoS |
6. Implementing WebSocket Communication
| Property | Detail |
|---|---|
| Protocol | RFC 6455; upgrade from HTTP |
| Full duplex | Bidirectional persistent |
| Frames | Text or binary |
| Use cases | Chat, live dashboards, gaming |
| Scaling | Sticky sessions or distributed pub/sub |
7. Implementing API Gateways
| Function | Detail |
|---|---|
| Routing | URL/header → backend service |
| Auth | JWT/OAuth validation |
| Rate limiting | Per-API-key throttling |
| Aggregation | Compose multiple backends (BFF) |
| Tools | Kong, Envoy, AWS API Gateway, Apigee |
8. Implementing Service Mesh
| Feature | Detail |
|---|---|
| Sidecar proxy | Envoy intercepts pod traffic |
| mTLS | Automatic certificate rotation |
| Traffic management | Canary, retries, timeouts |
| Observability | Built-in metrics, tracing |
| Tools | Istio, Linkerd, Consul Connect, Cilium Service Mesh |
9. Understanding Communication Protocols
| Protocol | Layer | Use Case |
|---|---|---|
| TCP | 4 | Reliable byte stream |
| UDP | 4 | Low-latency, no reliability (DNS, gaming) |
| QUIC | 4 (over UDP) | HTTP/3 transport |
| HTTP/1.1 | 7 | Universal; head-of-line blocking |
| HTTP/2 | 7 | Multiplexing, header compression |
| HTTP/3 | 7 | Multiplexing without HOL block |
| gRPC | 7 | RPC over HTTP/2 + protobuf |
| AMQP | 7 | RabbitMQ messaging |
| MQTT | 7 | IoT pub/sub |
10. Implementing Request-Reply Pattern
| Approach | Detail |
|---|---|
| Sync (HTTP/gRPC) | Caller blocks for reply |
| Async via reply queue | Correlate via correlation-id; reply-to queue |
| Callback URL | Webhook to caller's endpoint |
| Polling | Caller polls a status endpoint |