Skip to main content

Designing a line protocol

advanced16 min readLesson 163 of 180

A KV exchange where every decision โ€” frames, single-line responses, QUIT, ERR โ€” is visible.

The checkpoint protocol โ€” a KV store over TCP:

client: PUT key value
     server: OK

client: GET key
           server: VALUE value
   (or)  MISSING

client: QUIT
              server: BYE
  (then both close)

Design decisions worth noticing: the frame is a line (text protocol, easy to debug with telnet); responses are SINGLE lines (the client never has to count bytes); QUIT ends the session explicitly instead of relying on EOF races; unknown commands answer ERR rather than hanging or crashing. A server loop: accept โ†’ per-connection handler โ†’ read-line/write-line until QUIT/EOF. The test client proves the whole loop over real loopback bytes.

Now practice

Socket drillsFraming, budgets, and deadlines โ€” the discipline before real sockets.2 challenges ยท ยท ~50 min