Interprocess Communication in Microservices

Interaction styles

Synchronous Asynchronous
Request / Response Public / (subscribe | async response)
Used mostly to communicate with other application -
Remote procedure invocation-based Message-based
REST, gRPC AMQP, STOMP
Each request is processed by exactly one service Can process by multiple services
Clients expect a timely response from the service Response isn't sent immediately
Maybe blocking I/O None-blocking I/O
services being tightly coupled Less coupled
Less availability More availability

Message formats

Text-based message formats Binary Message formats
JSON / XML Protocol Buffers / Avro / Thrift
- Force to use API-first approach
Human readabel/ self describing -
Messages are verbose -
overhead of parsing text Focus on efficiency and performance

REST : Pros and Cons

Pros Cons
Simple Request/Response style only
Easy to test via browser Sender and Receiver must be running during the exchange. Hence, reduced availability
Firewall friendly Clients must know the target URLs or Service discovery is needed
Doesn't require broker -

gRPC : Pros and Cons

Pros Cons
efficient, compact, binary format Older firewall might not support HTTP/2
APIs evolve - easy on backward-compatibilities More work for Javascript to consume gRPC-based API than REST/JSON
Interoperable between clients and services written in a wide rage of languages -

Using Remote procedure invocation style should consider

  • Network timeouts
  • Rate limited
  • Circuit breaker pattern

Broker-based : Pros and Cons

Pros Cons
Loose coupling Potential performance bottleneck. (but modern brokers are designed to be highly scalable)
Message buffering Potential single point of failure (but modern broders are designed to be highly available
Support both Sync and Async Request/Response Additional operational complexity

Potential design issue

  • Messages ordering eg. sending 1,2,3 but may arrive to the target as 2,3,1 that might cause problem
  • Duplicate messages. Guaranteeing exactly-once is too costly, so, message brokers usually guarantee at least once

Ref