Skip to content
SEE Exam Prep

Question 11 of 15 · CIE-1 QB · 7 marks

Open in ChatGPT

Explain the concepts of at-least-once, at-most-once, and exactly-once execution semantics in reliable client-server communication.


Introduction

When a client sends a request to a server and the network can lose messages, the client cannot tell which failure happened: the request was lost, the reply was lost, or the server crashed. The execution semantics of an operation say how many times it may run under that uncertainty.

The three semantics

  1. At-most-once. The server executes the operation at most one time. The client sends once and gives up; requests are never retried. Safe for operations that must not repeat, such as debit ₹100, but a lost reply means the client never learns what happened.
  2. At-least-once. The client retries until it gets a reply, so the operation executes once or more. Safe for idempotent operations, such as set balance = 500, but a repeated non-idempotent operation corrupts state.
  3. Exactly-once. The operation executes exactly one time, which requires the server to detect duplicate requests and suppress them while still replying.

Achieving exactly-once

The server keeps a reply cache keyed by a client id and a request sequence number:

  1. The client attaches (client-id, seq) to every request.
  2. On arrival the server checks the cache. If a reply is present, it returns the cached reply without re-executing.
  3. If absent, it executes, stores the reply against the key, then sends it.
  4. A retransmitted request therefore gets the old reply, and the operation runs once.

The entries are discarded after a bounded time, which makes the guarantee exactly-once within the retransmission window.

Comparison

Semantics Retries Repeats possible Needs Safe for
At-most-once None No Nothing Non-idempotent writes
At-least-once Until reply Yes Nothing Idempotent operations
Exactly-once Until reply No Sequence numbers, reply cache Money, orders, transfers

Worked example

  • The client calls transfer(100) and the reply is lost.
  • At-most-once: the client never retries, so the transfer happened but the client believes it failed.
  • At-least-once: the client retries, the server executes again, and 200 is transferred.
  • Exactly-once: the retry carries the same sequence number, the server returns the cached reply, and 100 is transferred once.

Conclusion

Exactly-once is not free: it trades server memory for a duplicate-free guarantee, and its window is bounded. Choose at-most-once for non-idempotent writes when a duplicate is worse than an unknown outcome, at-least-once for idempotent operations, and exactly-once where both matter.