Service-to-service communication (sync vs async)

Synchronous communication: caller sends a request and waits for the response (e.g. HTTP/gRPC). Asynchronous: caller sends a message and doesn’t wait (e.g. queue, event bus); the other service processes later and may reply via another channel.

Sync: request–response

sequenceDiagram participant A as Service A participant B as Service B A->>+B: HTTP/gRPC request B->>B: Process B-->>-A: Response Note over A: Blocked until response

Async: fire and forget or event

sequenceDiagram participant A as Service A participant Q as Queue / Bus participant B as Service B A->>Q: Publish message Q-->>A: Ack (A continues) Q->>B: Deliver message B->>B: Process (later)
AspectSyncAsync
CouplingCaller knows callee, needs to be upDecoupled; queue absorbs load
LatencyWait for responseNo wait; processing later
FailureTimeout, retry, cascadeRetry via queue; backpressure
Use caseNeed immediate result (e.g. get user)Fire-and-forget, events, eventual consistency

Use sync when the caller needs the result to continue (e.g. auth check, fetch user). Use async for notifications, background work, or when you want to decouple and avoid cascading failures.