The ledger was right

A team sale splits one commission between two people. The split was recorded correctly everywhere a person could look, and the code that sent the money would have paid the wrong one.

3 min readGlitz · Team stage

On the marketplace, creators can work in teams. A member makes a sale and the commission splits: part to the member, part to the leader who brought them in. That split is the leader's whole reason to run a team, so the platform guards it. A member who shares their own solo link to dodge the leader's cut has the sale routed through the team anyway, earliest membership winning, with the split read from the team's records rather than anything the app sends.

Two functions, one row

A sale writes a ledger row. It records who sold, which team, the split rate, the member's amount and the leader's amount, each computed once and stored. Thirty days later a scheduled job releases the row and sends two transfers. The function that writes the row and the function that sends the money are different code, and they were written at different times. The split arrived on 18 February 2026. The sender arrived on 29 March, and it was correct that day. The rerouting of solo links arrived on 21 April, and it created a kind of row the sender had never been asked to read.

What the sender read

The sender found the leader's payee from the row's seller field. On a team link the leader created, the seller is the leader, so the money went to the right place. On a solo link the team check had rerouted, the seller is the member, because it was the member's own link. The row also carried a leader field, filled in correctly at sale time. The sender never read it. Both transfers would have gone to the member: their own share, and the leader's.

Everything a person could look at was right. The ledger showed the split. The member's running total showed their share and only their share. The leader got a notification for money that was never going to arrive. The only place the mistake lived was the transfer itself, the one record nobody reads until someone asks where their money went.

Found by reading

Nobody reported it. I found it on 2 October 2026, reading the source to write about the team check, and the essay stopped there. The honest version would have described a live bug, and the flattering version would have claimed a defence that did not reach the money. Production held no team sales at all, so nothing had been paid wrongly and nothing needed correcting. The fix merged on 21 October. The leader's share is paid to the leader field. The release notification goes to the same person. The same rerouting now runs for orders that come in through connected stores. A missing split falls back to the team's own default before the platform's. The scheduled jobs that send the money were redeployed on 31 October.

Fixed is not impossible

The fix is a corrected line, not a structure that rules the mistake out. The writer and the sender are still two code paths reading one row, and the notification repeats the payee expression rather than sharing it. If a rerouted row were ever written with an empty leader field, the fallback would pay the member again. What guards it today is a battle test that seeds team sales, releases them, and checks which account received how much. Its six team cases all passed on the last recorded run, in late October, and three of them had failed before the fix. It runs by hand against throwaway records, not on every change.

The version that makes it impossible is small. One function decides who is owed what from a row, and both the transfer and the notification call it. Before any transfer leaves, an assertion checks that the two amounts add up to the commission and that the leader's transfer is going to the leader. That is a morning's work. It is the difference between a bug that was fixed and a kind of bug that cannot come back.

Why it belongs on this page

The writer, the sender and the rerouting were written by the same person, weeks apart. That is the only reason the disagreement could be found from a chair. Whoever was reading the team check also knew, without asking anyone, which field the sender read. When those functions belong to two people, the ledger is right, the dashboard is right, and the first sign is a leader asking where their money went.

More notes
  • The webhook that credits twiceA payment processor delivers every result at least once. The interesting engineering is in what happens when your side fails halfway through.
  • A ledger you can edit from a route handler is not a ledgerWhy every movement of value on the payments platform goes through a Postgres function, and what it costs to keep it that way.
  • Four rows that were not theirsHardening multi-tenant row-level security in four reversible phases, verified by impersonating a member and counting what they could see.
  • The bug inside the fixA payout race, the fix for it, the bug inside that fix, and why it is the best argument I have for one person owning the whole path.
  • The sale that arrives with no referrerA creator shares a link on Instagram, the buyer taps it, installs the app and purchases. Nothing in that chain carries the creator's name across. Here is what does.
  • The minimum that belongs to someone elseHeld commissions are released to creators once a brand's payout minimum is met. Group the money by creator, the obvious way, and one brand's minimum ends up holding another brand's money.
  • The commission that must not mint twiceA buyer pays and the platform owes a creator a commission. Between those two facts sit a colluding pair, a call that arrives twice, and a cart with three items on one payment.
  • The rule that has to be written twiceFirestore security rules do not cascade to subcollections. Forget that in one place and a single query returns every private message on the platform.
  • Thirty days in the ledgerSplitting a payment at charge time is simpler and wrong: a refund after the creator is paid is a clawback nobody enjoys. Holding the money creates a different set of problems, and each piece of machinery around the hold answers one of them.
  • Arbitrary but consistentA gym's assessment answers become rules that swap an exercise for a member before a session. Two rules can disagree about the same movement. The code says who wins, and the comment admits how.
  • The number that ducked every thresholdA deposit arrives from a browser carrying two numbers. The platform scored one of them and charged the other, and every limit it had was measuring the wrong figure.
  • The second one tells you the shapeHigh-risk merchants get dropped by processors, so the platform cannot be welded to one. The interface that makes a processor swappable could not be designed before the second one existed.
  • A key you did not makeA device fingerprint is a hash the browser computes and the server has to take on faith. The useful question is not whether to trust it, but what a server does once it accepts that it cannot.
  • The template never learns your nameA trainer builds a workout once and runs it for a room of people who are not the same. The data model that survived is three tables with a one-way street between them, and the model it replaced was the obvious one.
  • The copy that heals itselfA marketplace that sells a brand's products keeps a copy of the brand's store. The same codebase keeps that copy two different ways, and the slower one is the one that is right by morning.
  • Zero was not a ceilingA creator can write their own commission rate, so the server caps it at what the brand agreed to. For most of the catalogue the cap never ran, because those products carried no commission of their own.
  • Smaller than it wasOn 27 September the gym's movement library lost 4,724 lines and gained one field. What came out was a theory of how movements relate. What replaced it was a trainer writing the relation down.
  • The toast that could not fireA trainer taps Mark All and the whole room's round is recorded. From October 2025, if every one of those saves failed, the app said nothing, because a failed save and a deliberate skip had become the same value.
  • The ceiling is a thousand rowsA comment beside the member totals names their ceiling: tens of thousands of sets, and then it gets slow. The query under it has no range, and the API it calls stops at a thousand rows without saying so.
  • Spent, but not on anythingEvery deposit required a texted code, and each code could be spent once. Nothing recorded which deposit spent it, so the dispute packet that cited those codes was counting texts, not approvals. Now each spent code carries the checkout it approved.
  • No exceptions notedThe platform could generate a certificate of its own controls for underwriters, and every result in it was the same fixed string. Re-reading it for this page found that. It now counts what the guard actually decided.