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

Implementation

Build a basic relay proxy that forwards requests to a backend server:

  1. Listen for incoming client requests
  2. Parse the request to determine backend destination
  3. Forward the request to the backend
  4. Wait for the backend response
  5. Return the response to the client

Handle connection errors and timeouts gracefully.

Sample Test Cases

Forward requestTimeout: 5000ms
Input
{"src":"c0","dest":"proxy","body":{"type":"init","msg_id":1,"node_id":"proxy","node_ids":["proxy","backend"]}}
{"src":"client","dest":"proxy","body":{"type":"relay_request","msg_id":2,"path":"/api/data","method":"GET"}}
Expected Output
{"src":"proxy","dest":"c0","body":{"type":"init_ok","in_reply_to":1,"msg_id":0}}
{"src":"proxy","dest":"client","body":{"type":"relay_response","in_reply_to":2,"msg_id":1,"status":200,"path":"/api/data"}}

Hints

Hint 1
Accept incoming requests
Hint 2
Forward to backend server
Hint 3
Return response to client
OVERVIEW

Theoretical Hub

What is a Proxy?

A proxy sits between clients and servers, intercepting and forwarding requests. Proxies can add functionality like caching, load balancing, security, and logging without modifying client or server code.

Forward vs Reverse Proxy

A forward proxy acts on behalf of clients (e.g., corporate firewall). A reverse proxy acts on behalf of servers (e.g., NGINX in front of application servers). We will build a reverse proxy.

Key Concepts

proxyforwardingrequest handling
main.py
python
Implement Basic Relay Proxy - Proxies | Build Distributed Systems