Managing Service Communication Patterns

1. Request/Response Pattern

PropertyDetail
StyleCaller blocks, awaits one response
TransportHTTP, gRPC unary
TimeoutMandatory; default to 1-3 seconds for internal
RetryOnly for idempotent ops
Trace HeaderPropagate W3C traceparent

2. Asynchronous Messaging Pattern

PropertyDetail
TransportQueues (RabbitMQ, SQS) or logs (Kafka)
DurabilityBroker persists until ack
DecouplingProducer/consumer independent in time and identity
Use CasesWorkflows, fanout, long-running tasks

3. Publish/Subscribe Pattern

ElementRole
TopicLogical event channel
PublisherEmits to topic; unaware of subscribers
SubscriberEach gets independent copy of every event
DeliveryAt-least-once; consumers must be idempotent

4. Point-to-Point Messaging Pattern

ElementRole
QueueSingle logical destination
ConsumersMultiple workers compete; each message goes to one
Use CaseWork distribution, load balancing
OrderingPer-queue FIFO (often relaxed under parallel consumers)

5. Remote Procedure Invocation Pattern

VariantDescription
REST over HTTPResource-oriented; widely supported
gRPCSchema-first (Protobuf), HTTP/2, streaming
GraphQLSingle endpoint, client-shaped queries
ThriftCross-lang RPC framework

6. Domain-Specific Protocol Pattern

AspectDetail
DefinitionUse a specialized protocol fitting domain (MQTT for IoT, FIX for finance, SMTP for mail)
BenefitNative ecosystem support, optimized semantics
CostSpecialized client libs; less generic tooling

7. Transactional Outbox Pattern

StepAction
1In same DB tx, write business state AND event row to outbox table
2Background relay polls outbox / tails CDC
3Relay publishes event to broker
4Mark 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

AspectDetail
MechanismPublisher polls outbox table at interval
ProsSimple, no special DB features
ConsLatency = poll interval; load on DB
TuningUse SKIP LOCKED to parallelize publishers

9. Transaction Log Tailing Pattern

AspectDetail
MechanismRead DB redo/WAL log → publish events (Debezium, Maxwell)
ProsLow latency, no application change to publish
ConsTight coupling to DB internals; ops overhead
ToolsDebezium, AWS DMS, GCP Datastream

10. Competing Consumers Pattern

AspectDetail
MechanismMultiple consumers read from same queue / partition group
EffectHorizontal throughput; auto load balance
OrderingLost across messages unless partition key used (Kafka)
IdempotencyRequired since duplicates possible on rebalance

Competing Consumers

[Producer] → [Queue] → ┬── [Consumer A]
                       ├── [Consumer B]
                       └── [Consumer C]   (each msg → exactly one consumer)