A new species does not need a new cage welded by hand. It needs one line in the register - and writing that line turned up blank pages nobody had noticed.
👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: github.com/brilliant-almazov.
The dictionary section of the manifest and the closed-set package behind it are built into the shared library and its generator; five services use the package. The two findings below were found and fixed in the same pass.
This is part 7 of the series on what a shared platform does for every service, told as a zoo. Maybe you already do it better, maybe you'd do it another way - this is how it is going, and where it stops.
In real life
A new species arrives at the zoo: a lizard nobody has kept before. Nora reaches for the welding torch - "A new lizard! Weld a cage?" Pip stops her: "Put the torch down, Nora."
Because a new species in a well-run zoo is not a new cage. It is one line in the register: name, what it eats, how warm it likes it. The cage follows from the line.
Writing the line is where the story turns funny. Pickle opens the register to add the lizard and finds two columns that were never filled in for anybody - "since when?" asks Nora, and nobody knows. And Miso reports that the checker at the gate, the one who checks that the register matches the cages, had been saying no to everyone. Pip finishes the joke: "Even to the right answers."
A closed set of codes is a species
Our services have many small closed sets: statuses, kinds, types of things, each code with a title, sometimes with a parent code or a group. Every one of them needs the same handful of operations: parse a code, check it is valid, get its title, ask whether one code descends from another, ask whether a code belongs to a group.
Before, a new set meant a new piece of Go in the service - a cage welded by hand. Now the shared library has one package for closed sets, and the service manifest has a dictionary section. A new kind is a manifest entry; the printed package of the service holds only the table of codes; parsing, checks and walking the tree live in the library.
As a form - the names are illustrative:
dictionary:
- name: <kind>
values:
- { code: <a>, title: <A> }
- { code: <b>, title: <B>, parent: <a> }
The library's changelog puts it as plainly as the comic: a new kind of dictionary is a line of the manifest, without a line of Go.
Five gates on five lookups
A lookup that runs on every request is a place where small costs pile up. The closed-set package has allocation ceilings on its five lookups - parse, valid, title, descends, in group - the same kind of gate that the library uses elsewhere: a test fails if a lookup starts allocating more than its ceiling.
| Lookup | Question it answers | Gate |
|---|---|---|
| parse | is this string a code of the set? | allocation ceiling |
| valid | is this code allowed? | allocation ceiling |
| title | what do people call it? | allocation ceiling |
| descends | is this code under that one? | allocation ceiling |
| in group | does this code belong to the group? | allocation ceiling |
On the reading side, a handler uses the set through the same five questions. In the shape of the code, with names shortened:
// in a handler - a form
code, ok := kinds.Parse(raw) // is this a code of the set?
if !ok || !kinds.Valid(code) {
return refuse(reasonUnknownKind) // a refusal with a reason, not a panic
}
if kinds.Descends(code, parent) && kinds.InGroup(code, group) {
title := kinds.Title(code) // what people call it
// ...
}
None of those five functions is written in the service. The service wrote the table; the questions came with the library.
The blank pages
Writing the dictionary section through the generator was the first time anyone read the old manifest fields closely enough to print from them. Two findings came out of it, both in the library's changelog.
The manifest had fields for a migration's enum type and its values. They were declared - you could write them, and nothing complained - but the generator never printed them. A field that is accepted and ignored is worse than a missing field: it tells the author the job is done.
And the drift check in a service made from the template - the check that compares the manifest with what is printed - always refused. Every run, every service. A check that always says no gets ignored, and an ignored check is no check at all.
What went wrong
Both findings are the same failure in two costumes: something declared looked done. Fields accepted by the manifest looked like they worked, because nothing rejected them. A drift check existed, so drift looked guarded - except it rejected everything, so everyone learned to ignore it. Neither was found by looking for it. Both were found because a new, small feature had to walk through the same code honestly.
The lesson I keep from it: every declaration needs a reader that proves it is used. A field that is declared must be printed, or rejected. A check must be seen to pass on a correct input before its "no" means anything.
What I do not claim
- Not that every closed set in every service has moved to the manifest. Five services use the package.
- Not how long the two blank fields were blank. The changelog records the find, not the start.
- Not measured numbers for the gates here. They are ceilings that fail a test when crossed.
- Not the exact manifest format. The form above shows the shape.
What of this is method
- A new kind is data, not code. One line in the manifest; the library does the rest.
- Declared is not done. A field is printed or rejected; a check is seen to pass before its "no" counts.
- Small features walk old code honestly. That is where blank pages are found.
Zoo keeping, built in - Part 7. Next: No Night Watchman For Partitions.
If your closed sets live in code, how many cages did you weld last year? If your manifests accept fields, how do you know each one is read? If you have a check that always fails, who still looks at it? What blank page is waiting in your register?








Top comments (0)