Skip to main content

Charged Twice: Safe Retries With Idempotency Keys in Fiber

· 32 min read
René Werner
Fiber maintainer

A customer taps "Pay" on a train. The app sends POST /v1/orders, the server charges the card, writes the order and answers 201. The answer never arrives, because the train went into a tunnel. The app times out and, like every good HTTP client, sends the request again. The server has no idea it has seen this request before. It charges the card a second time.

Most retries are not in your code. Mobile SDKs retry on timeouts, service meshes on connection resets, job queues redeliver when a worker dies, and people press the button again when nothing happens. The fix is an idempotency key, a random value the client sends with every attempt of one operation, and Fiber's idempotency middleware answers every repeat with the first response. On a payment endpoint that is not enough: you also have to decide in every branch of the handler whether something irreversible has happened, require the key, scope and fingerprint it, and share the lock across instances.

Why Your Symlinked Assets Suddenly Return 404

· 19 min read
René Werner
Fiber maintainer

A shop moves to Fiber v3.7.0, the upgrade goes through without a complaint, and after the next deploy every avatar is a broken image. CSS and the home page still load, the logs show nothing but 404s for /uploads/..., and a few minutes later someone notices that the Apple touch icon and the web fonts are gone too.

The shop runs on a single VM. Every deploy unpacks the build into a new directory under /srv/shop/releases, flips the current link to it, and reloads the service. Product photos and avatars live outside any release in /srv/shop/shared/uploads, and the deploy script links that directory into each one as public/uploads. The Fiber app has served /srv/shop/current/public with the static middleware for a year.

None of those files moved; the links to them stopped resolving, without a log line. One rule decides which links break, a startup check can list them before users find them, and each kind of link has a fix that leaves the new protection on.

Filters Nobody Planned For: Binding attr[color]=red Into Go Maps

· 24 min read
René Werner
Fiber maintainer

Say a shop sells jackets. The product list has filters for color and size, and the handler binds them into a struct with a Color field and a Size field. Then the merchandising team adds "material" to the product data, and a week later "hood" and "waterproof rating". Every new attribute is a new struct field, a new WHERE clause, a code review and a deploy, for something that is really just another row in the attributes table. The frontend team would rather send whatever the data has: ?attr[color]=red&attr[material]=down.

Fiber's binder used to skip a struct field of type map[string]string without a word, although a request for exactly this had been open since 2023. Now map fields of a struct bind from query strings and form bodies.

Binding the map is the easy part. The map also hands you keys chosen by whoever sends the request, and a key that becomes a column name in your SQL has to come from a lookup table in your code, never from the request.