Microservices communicate with each other through a handful of established methods, each suited to different latency, coupling, and throughput requirements.
Key Points: • HTTP REST is the most common synchronous method — services send requests and get immediate responses over HTTP, using JSON payloads. • Message brokers like Kafka or RabbitMQ enable asynchronous communication, where services publish and consume messages without needing a direct, simultaneous connection. • gRPC uses HTTP/2 and binary Protocol Buffers for fast, efficient communication, making it well suited to high-performance, low-latency service-to-service calls. • GraphQL offers a flexible query-based alternative to REST, letting clients request exactly the fields they need in a single call. • The choice depends on the use case: REST for simplicity and broad compatibility, messaging for decoupling and resilience, gRPC for performance-critical internal calls.
Example: A system might use REST for a mobile app calling the User Service, Kafka for the Order Service to broadcast "OrderPlaced" events to multiple downstream consumers, and gRPC for high-frequency internal calls between a pricing engine and inventory service.
Interview Tip: A concise interview answer is:
"The main ways are synchronous REST over HTTP for simple request/response calls, asynchronous messaging through brokers like Kafka or RabbitMQ for decoupled communication, and gRPC when I need fast, efficient binary communication, typically for internal high-throughput calls. I pick based on whether the caller needs an immediate response and how much decoupling and performance matter for that specific interaction."