Managing Service Communication Patterns
1. Request/Response Pattern
| Property | Detail |
|---|---|
| Style | Caller blocks, awaits one response |
| Transport | HTTP, gRPC unary |
| Timeout | Mandatory; default to 1-3 seconds for internal |
| Retry | Only for idempotent ops |
| Trace Header | Propagate W3C traceparent |
2. Asynchronous Messaging Pattern
| Property | Detail |
|---|---|
| Transport | Queues (RabbitMQ, SQS) or logs (Kafka) |
| Durability | Broker persists until ack |
| Decoupling | Producer/consumer independent in time and identity |
| Use Cases | Workflows, fanout, long-running tasks |
3. Publish/Subscribe Pattern
| Element | Role |
|---|---|
| Topic | Logical event channel |
| Publisher | Emits to topic; unaware of subscribers |
| Subscriber | Each gets independent copy of every event |
| Delivery | At-least-once; consumers must be idempotent |
4. Point-to-Point Messaging Pattern
| Element | Role |
|---|---|
| Queue | Single logical destination |
| Consumers | Multiple workers compete; each message goes to one |
| Use Case | Work distribution, load balancing |
| Ordering | Per-queue FIFO (often relaxed under parallel consumers) |
5. Remote Procedure Invocation Pattern
| Variant | Description |
|---|---|
| REST over HTTP | Resource-oriented; widely supported |
| gRPC | Schema-first (Protobuf), HTTP/2, streaming |
| GraphQL | Single endpoint, client-shaped queries |
| Thrift | Cross-lang RPC framework |
6. Domain-Specific Protocol Pattern
| Aspect | Detail |
|---|---|
| Definition | Use a specialized protocol fitting domain (MQTT for IoT, FIX for finance, SMTP for mail) |
| Benefit | Native ecosystem support, optimized semantics |
| Cost | Specialized client libs; less generic tooling |
7. Transactional Outbox Pattern
| Step | Action |
|---|---|
| 1 | In same DB tx, write business state AND event row to outbox table |
| 2 | Background relay polls outbox / tails CDC |
| 3 | Relay publishes event to broker |
| 4 | Mark outbox row as published (or delete) |
Example: Outbox Table + Atomic Write
CREATE TABLE outbox (
id UUID PRIMARY KEY,
aggregate_type VARCHAR(64),
aggregate_id VARCHAR(64),
event_type VARCHAR(128),
payload JSONB,
created_at TIMESTAMPTZ DEFAULT now(),
published_at TIMESTAMPTZ
);
-- INSERT order + INSERT outbox row in one transaction
8. Polling Publisher Pattern
| Aspect | Detail |
|---|---|
| Mechanism | Publisher polls outbox table at interval |
| Pros | Simple, no special DB features |
| Cons | Latency = poll interval; load on DB |
| Tuning | Use SKIP LOCKED to parallelize publishers |
9. Transaction Log Tailing Pattern
| Aspect | Detail |
|---|---|
| Mechanism | Read DB redo/WAL log → publish events (Debezium, Maxwell) |
| Pros | Low latency, no application change to publish |
| Cons | Tight coupling to DB internals; ops overhead |
| Tools | Debezium, AWS DMS, GCP Datastream |
10. Competing Consumers Pattern
| Aspect | Detail |
|---|---|
| Mechanism | Multiple consumers read from same queue / partition group |
| Effect | Horizontal throughput; auto load balance |
| Ordering | Lost across messages unless partition key used (Kafka) |
| Idempotency | Required since duplicates possible on rebalance |