Why this matters
Client-server communication can occur via two distinct patterns: synchronous request-response or asynchronous message-based systems.
Synchronous communication requires the client to wait for a response.
Asynchronous communication allows the client to send a message and proceed without waiting.
The choice between them affects system design, scalability, and fault tolerance.
Synchronous Request-Response
The client sends a request directly to the server.
The client waits for a response before proceeding.
This pattern is fast to implement.
It works best when real-time results are needed.
For example, a client must know the result to proceed with another action.
Asynchronous Request-Response
The client sends a message to a messaging system.
The client receives an acknowledgment that the message was accepted.
The message is delivered to the server later.
The server may send a response at a later time.
The client does not wait for the response.
The client only cares about successful message submission.
This pattern is ideal when the client doesn’t care who, when, or how the message is processed.
Use Cases
Use synchronous when:
- The client needs real-time results.
- The result is required to proceed with another action.
Use asynchronous when:
- The client wants to make multiple requests in parallel.
- The client does not want to be blocked.
Synchronous calls must be performed sequentially, increasing latency.
Asynchronous messaging enables parallel processing.
Stream Processing
Stream processing is a classic use case for asynchronous communication.
The client submits messages and moves on.
The system processes messages at its own pace.
More servers can be added to handle increased load.
Disadvantages
Asynchronous systems increase overall system complexity.
They require high availability, scalability, and security.
They need monitoring and maintenance.
Questions
- What should the client do when the server is not available?
- How does asynchronous communication reduce latency?
- When is a messaging system ideal for client-server interaction?
- What happens to messages during server performance degradation?
- Can a server process messages at a different rate than client requests?
- How does the client know if a message was successfully submitted?
- What is a classic example of stream processing?
Key takeaways
- Synchronous communication requires waiting for a response.
- Asynchronous communication allows clients to proceed without waiting.
- The client only needs confirmation of message submission in asynchronous systems.
- Real-time results require synchronous communication.
- Parallel requests are better handled asynchronously.
- Message processing can scale independently of client request rates.
- Asynchronous systems increase complexity and require operational overhead.