CSE Roadmap

Core tier · about 6 hours · 14 parts

Part 9 of 14 · 1 min read

How to build it so it holds up

Rules for a transport implementation, each with the reason it matters.

  • Keep stdout for the protocol alone, because any stray line (even one that succeeded) reads as a protocol violation to a client that is not told otherwise, and logs belong on stderr.
  • Shut down in order: close stdin, wait, terminate, kill, because a server that exits on end of input costs about 0.01 s to stop, while a server that must be killed costs 0.6 s and a signal most servers should never need.
  • Probe for the modern era, and never key the fallback to one error code, because legacy servers answer an unrecognised pre-handshake request however they like, including with silence.
  • Make the server check mirrored headers against the body, not just the gateway, because a gateway's decision is only as good as the value it decided from, and the server is the last place that can catch a lie.
  • Attach an idempotency key to every side-effecting call, because a dropped connection after the work is done leaves no other honest way to tell a retry from a duplicate.
  • Validate Origin, bind to loopback locally, and authenticate anyway, because the origin check alone never stops a plain program, only a browser carrying a hostile page's request.
  • Re-read cached resources after every reconnect, because a stateless server replays nothing it missed sending you.