A gift card code is money the moment a brand’s system issues it. That one fact shapes how we build orders at Hubble. We hold ourselves to two promises: a buyer never pays without getting a code or a refund, and a repeated request never produces a second card. This post is about why those promises are hard to keep and the principles we chose to keep them.
Why a gift card order is hard
The buyer pays before the code exists, and the code cannot be taken back once it does. Between the two sit three systems that share no transaction: the payment, our own records, and the brand’s system, which we reach over the network. Any of them can be slow. Any message between them can be lost, late or sent twice. Any of our processes can stop between two steps.
The hardest moment is a call to a brand that does not answer. We do not know whether the card was issued. If we call it a failure and refund, we may have given away a live card. If we call it a failure and try again, we may issue two. Both mistakes cost real money, and neither can be undone after the fact.
The guarantees we hold
We write the design down as properties, not steps, because properties are what we can test and what a partner can rely on.
- A buyer never pays without getting a code or a refund. If no card can be issued, the payment is refunded automatically.
- A repeated request cannot produce a second card, whether it comes from a partner, a network retry or our own recovery.
- A refund happens once. An order that has already been settled cannot be settled again.
- If a brand’s system is slow, the buyer’s order shows as in progress until the card arrives.
Everything below exists to keep those four true.
The principles behind them
“We do not know” is an answer of its own. A timeout is not a failure. We give the unknown its own name in our records, so it cannot turn into “failed” on its way through the code. Most of the design follows from this one decision.
Save what cannot be undone, first and alone. When money has moved, we record that before doing anything else. Nothing that goes wrong later may roll that record back, because the money has already moved in the real world.
Name the order before you send it. Every request to a brand carries a reference built from our own order, and every later question uses the same reference. Asking again is then the same question, not a new order, and the brand can see a repeat for what it is.
Every step checks before it acts. Any step in the flow can run twice, so each one looks at the order before it changes anything. A second event for an order that is already settled is refused, not merged. That strictness is what makes “a refund happens once” true.
Recovery uses the same path as normal work. Some orders end up between steps, after a crash or a lost message. We settle them by asking the system that owns each fact for its answer, then passing that answer through the same code a live event would use. There is one way to move an order forward, not a normal path and a repair path that slowly drift apart.
We leave out the detail of how and when unfinished orders are settled on purpose.
The trade-offs we accepted
The buyer pays before the code exists. We did not try to make payment and issue a single step, because the brand’s system sits outside any transaction we control. We spent the design on making every path without a code end in a refund instead.
Some orders wait. A buyer can see an order in progress for longer than a quick failure would take. We chose a short, honest wait over a fast answer that might be wrong.
Strict steps refuse things. Because every step checks first, an event that arrives for a settled order is turned away rather than merged in. That makes the flow less forgiving, but it never pays out twice.
A repeated reference is refused, not replayed. A business on our API that sends the same order reference twice gets an error, not the first order’s result. It can look the order up by its reference instead. This keeps a retry from ever becoming a second order.
What we would tell another team
- Give “we do not know” its own place in your records, and never let a timeout become “failed”.
- Put your own reference on every call that can move money or create value, and ask about the result by that reference.
- Record what you cannot undo before you take the next step.
- Make recovery call the same code as your live events. A separate repair path will drift.
- Decide what happens when waiting runs out before you need to.
If you integrate with us, the order flow for partners is in the API docs. The same ideas shape the ledger behind a gift card. If you would like to work on problems like this, see careers at Hubble.