RPC Services at Scale
The service in front of the network: JSON-RPC 2.0 done exactly, Serde at the edge, Tower layers for timeout and rate limiting, and the architecture questions an interview will actually ask.
// lessons
- 01
The JSON-RPC 2.0 Envelope and Its Five Error Codes
Classify any inbound request into the right JSON-RPC error code, and know the two cases where the response id must be null rather than echoed.
- 02
Notifications, Batches and the Requests You Must Not Answer
Implement the two rules that break naive JSON-RPC servers: a notification gets no response at all, and an empty batch is itself an invalid request.
- 03
A Method Dispatch Table of Boxed Handlers
Build a router from a HashMap of boxed closures, and separate the three failures a call can have: no such method, bad arguments, handler blew up.
- 04
Service and Layer: Building Tower From Two Traits
Write the two traits the whole Tower ecosystem is made of, then wrap a backend in a timeout and prove the timed-out requests never reach it.
- 05
Concurrency Limits and Load Shedding
Simulate the same overload under two admission policies and read off what queueing actually costs: the same successes, plus 320ms of backend time spent on responses nobody can use.
- 06
A Token-Bucket Rate Limiter on a Simulated Clock
Implement per-client token buckets with lazy refill, return a retry_after the client can act on, and see why the limit you configure is not the limit your fleet enforces.
- 07
Pagination Contracts: Cursors, Offsets and Request IDs
Prove that OFFSET paging silently drops rows when the collection changes mid-walk, and write the cursor contract that does not.
Every exercise compiles and runs in the Forge sandbox — standard library only, no external crates.
