β Back to gRPC and Protocol Buffers
π§ gRPC and Protocol Buffers: cheat sheet
π¨ The analogyWalkie-talkies with a shared codebook of numbered phrases, so messages are tiny and both sides can talk at once.
π The regular explanationA contract-first RPC framework. Services and messages are defined in .proto files, encoded as compact Protocol Buffers binary, and called through generated stubs over HTTP/2, with unary and streaming calls, deadlines and status codes.
- Before the first shift, Mia and Sam write one codebook together. It lists every question Mia may ask and what each answer looks like.
- From the codebook, each of them gets a printed card. Mia's card turns her questions into codes; Sam's sheet turns codes back into questions.
- Mia just asks "how many apples?". Her card sends it as short codes over the radio, and Sam's sheet turns it back into the question.
- Sam answers "twelve", and the reply comes back the same way, as codes, until Mia hears "twelve".
- Mia sends "one, apples; two, twelve". Only the numbers and the values go over the radio, never the words "item" or "how many".
- Mia's new codebook adds "three, gift wrap". Leo has the old codebook, doesn't know "three", ignores it, and still gets the rest right.
- Later someone crosses out "two, how many" and reuses "two" for the price. Leo hears "two, nine" and thinks Mia wants nine apples.
- So crossed-out numbers stay crossed out for good. The price gets a brand-new number, four, and Leo just ignores it.
- Mia and Sam tune to one channel and keep it. First, the simplest way to talk, one question and one answer.
- Mia asks once, "read me today's orders", and Sam reads them out one by one until he's done.
- Now the other way round. Mia reads out every item she scanned, and Sam answers once at the end, "got all three".
- Finally, both talk at once. Mia and Sam chat freely on the same channel, and each speaks whenever they like.
- Mia asks Sam to put an order aside, with a time limit of two minutes and a word about who she is. Sam asks Kim and passes on the time that's left.
- Kim is slow today. The two minutes run out, so Mia stops waiting and gets the sign-off code "too late".
- Mia's "never mind" travels down the line, so Sam and Kim stop working on an order nobody is waiting for.
- Next time Kim's radio is switched off. Sam gets no answer and signs off to Mia with "nobody's there", so she tries again a little later.
- A channel switch by the stockroom door connects Mia's radio to Sam when she tunes in, and every question goes to Sam.
- Two more helpers start work, but Mia's radio stays tuned to Sam. He's swamped while Kim and Lee stand around.
- A dispatcher replaces the switch. It listens to each question and hands it to the next free helper, so the work is shared.
- When Kim goes on a break, the dispatcher simply stops giving her questions, and Sam and Lee carry on.
- Mia tunes in once and keeps the same channel all day, and Sam has his answer sheet ready.
- Mia sets a two-minute limit and asks for twelve apples. Sam writes down the order and answers with its number.
- Mia asks for pears, which the shop doesn't sell. Sam signs off with "we don't have that", and Mia's card tells her exactly that.
π§© Key questions
- Mia and Sam stop using "two, how many". What should happen to the number two?
- Cross it out for good, so an old codebook never misreads it. Old codebooks still think two means how many, so a new meaning for two would be misread.
- Mia adds "three, gift wrap" to her codebook. What happens when Leo, with the old codebook, hears it?
- He ignores three and understands the rest. New parts get new numbers, so old and new codebooks can still talk to each other.
- Mia gave Sam two minutes. Sam had to ask Kim, and the time ran out. What happens?
- Mia hears "too late", and her "never mind" reaches Sam and Kim so they stop. Nobody keeps working on something nobody's waiting for, but work already done isn't undone.
- The shop hires two more helpers, but every question still goes to Sam. Why?
- Mia's radio was tuned to Sam once, and every question goes down that one channel. A dispatcher who hands out each question, or a radio that takes turns, shares the work.