Skip to main content

Communication Patterns

Communication StyleDefinitionFeaturesUse Cases
AsynchronousAsynchronous communication is used to communicate between services without waiting for the response
  • Non-blocking
  • Supports retries
  • Flexible scaling
  • Load leveling
  • Batch processing
  • Event-Driven Architectures
  • Background processing
  • Decoupled systems
DatabaseUses a shared database to communicate between services. Commonly uses CQRS and Event Sourcing techniques
  • Eventual Consistency
  • ACID properties
  • Consistent state management
  • Data backup and recovery
  • Data synchronization
  • When you need a snapshot of data
File TransferServices communicate by reading and writing files to a shared location
  • Batch processing
  • Eventual Consistency
  • Batch processing
  • Data import/export
  • Integration with legacy systems
GraphQLQuery language for APIs, allowing clients to request exactly what they need
  • Flexible data retrieval
  • Schema-first development
  • Type safety
  • Reduces over/under-fetching of data
  • APIs with complex and dynamic data requirements
gRPCgRPC (Google Remote Procedure Call) is a high-performance, language-agnostic remote procedure call (RPC) framework that enables efficient communication between distributed systems by utilizing Protocol Buffers for serialization and HTTP/2 for transport, ensuring low latency, bandwidth efficiency, and support for bi-directional streaming
  • High performance
  • Bi-directional streaming
  • Protobuf
  • HTTP/2
  • Binary data transfer
  • Microservices
  • Point-to-point real-time communication
  • Command and action oriented APIs
  • High performance communication in massive microservice systems
P2PP2P (Peer-to-Peer) is a decentralized form of communication where each party has the same capabilities and either party can initiate a communication session. It enables direct communication and sharing of resources among multiple nodes in a network without the need for a central coordinating server
  • Decentralized
  • Resource sharing
  • Direct communication
  • Dynamic network topology
  • Resilient and scalable
  • File sharing applications (Torrent)
  • Blockchain and cryptocurrencies
  • Distributed databases
  • Decentralized social networks
  • Collaborative software applications
  • Multiplayer online gaming
SOAPSOAP (Simple Object Access Protocol) is an XML-based communication protocol
  • XML-based
  • Enterprise applications
  • Payment gateways
  • identity management
  • CRM solutions
  • financial and telecommunication services
  • legacy system support
StreamData transmission method where information is continuously and sequentially delivered in a steady flow, often in real-time, without distinct boundaries or breaks, facilitating persistent and ongoing data exchange between communicating entities
  • Push-based
  • Pull-based
  • Reactive
  • Real-time data processing and insights
  • Real-time analytics
  • Live dashboard updates
  • Streaming applications
  • MMO games
  • Chat applications
SynchronousData transmission between sender and receiver occurs in real-time, requiring both parties to be actively engaged simultaneously for message exchange, ensuring temporal alignment of communication events
  • Blocking
  • Resource-based
  • HTTP methods
  • Supports request-response patterns
  • Operations where immediate response is required
  • Request/response APIs
  • Transactional systems

Best Practices​

Semantic Versioning​

Semantic Versioning (SemVer): (1.0.0)

  • MAJOR: version for incompatible contract changes
  • MINOR: version for adding functionality in a backward-compatible manner
  • PATCH: version for backward-compatible bug fixes

Strategies​

StrategyDefinitionConsumers ActionProsCons
Schema VersioningExplicitly include a version number in the message itselfConsumers can handle messages based on their version
  • Granular control
  • Easy identification of changes
  • More complex implementation
  • Potential for breaking changes
Backward Compatible Schema EvolutionIntroduce new optional fields to messages without breaking existing consumersConsumers can ignore new fields they don't understand
  • Minimizes disruption
  • Promotes smooth upgrades
  • Can lead to cluttered messages over time
Forward Compatible Schema EvolutionMark existing fields as deprecated in older versionsIntroduce new fields in newer versions for future consumers
  • Prepares for future changes
  • Avoids cluttering older messages
  • Requires handling deprecated fields
  • Potential confusion for consumers unaware of versions
Content NegotiationProducer and consumer negotiate the message format during connection establishmentAllows for dynamic adaptation and interoperability between different versions
  • Highly flexible
  • Avoids version conflicts
  • More complex implementation
  • Requires additional negotiation overhead

Considerations​

  • Trade-offs: Complexity vs Flexibility, Backward vs Forward Compatibility
  • Start simple: Opt for schema versioning or backward-compatible evolution for most cases
  • Use content negotiation: For highly dynamic environments with diverse clients
  • Versioning granularity: Decide if versioning applies to entire messages or individual fields
  • Version deprecation policy: Define a timeline for removing support for older versions
  • Versioning tooling: Leverage tools for schema documentation, validation, and migration
  • Clear communication: Document versioning policies and notify stakeholders of upcoming changes
  • Forsee Future Changes: Plan for message versioning to accommodate future changes in the payload structure, and ensure backward and forward compatibility to facilitate system evolution