ARCHIVED from builddistributedsystem.com on 2026-04-28 — URL: https://builddistributedsystem.com/tracks/proxies/tasks/task-12-2-dedup
TASK

Implementation

Deduplicate identical concurrent requests to reduce backend load:

  1. Compute a request key (e.g., hash of method + URL + body)
  2. If a request with the same key is already in-flight, wait for it
  3. When the original completes, return the same response to all waiters
  4. After response, remove from in-flight set

This is especially valuable for hot endpoints with many identical requests.

Sample Test Cases

Deduplicate concurrentTimeout: 5000ms
Input
{
  "src": "c0",
  "dest": "n1",
  "body": {
    "type": "init",
    "msg_id": 1,
    "node_id": "n1",
    "node_ids": [
      "n1"
    ]
  }
}
Expected Output
{"src":"n1","dest":"c0","body":{"type":"init_ok","in_reply_to":1,"msg_id":0}}

Hints

Hint 1
Track in-flight requests by key
Hint 2
Have duplicates wait for original
Hint 3
Return same response to all waiters
OVERVIEW

Theoretical Hub

Request Deduplication

When many clients request the same resource simultaneously, sending all requests to the backend wastes resources. Deduplication sends one request and shares the response, reducing backend load dramatically.

Request Fingerprinting

The dedup key must uniquely identify functionally equivalent requests. For GET requests, URL is often sufficient. For POST, you may need to hash the body. Be careful with headers that affect response.

Key Concepts

deduplicationidempotencyrequest coalescing
main.py
python
Add Request Deduplication - Proxies | Build Distributed Systems