How Atlassian bills millions of usage events without double-charging
· Do Minh Tuan · Tech Made Simple 💡
Atlassian published a write-up of how Forge, its platform for building apps, handles usage-based billing at scale. The system processes millions of usage events across a distributed network, and the post is mostly about accuracy. I read it because billing is the one system where a small bug becomes a customer conversation, a refund and a support ticket, all at once.
Usage-based pricing means you pay for what you consume, emails sent, gigabytes stored, requests served. It sounds fair, and it is, until the meter misses an event or counts one twice. Then the fairness argument disappears and you are explaining a line item to someone who has the logs.
Why the pipeline is streamed, not batched
The first design choice is that events flow through a streaming pipeline rather than a nightly batch job. Batch means collecting everything for a day and processing it later, which is simpler to build and much easier to reason about. Streaming means processing each event as it arrives. Atlassian's reason is near-instant billing visibility: a customer can see usage close to when it happens instead of finding out a day later.
That choice costs you something, and I think the cost is underrated. A batch job that fails can be rerun from the start of the day. A stream that drops an event has already moved on, and you have to have designed for duplicates and gaps before you needed to. Which brings us to the two mechanisms the post spends most of its time on.
Duplicates are the normal case, not the edge case
When services talk over a network, connections drop. An app reports that a user sent an email, the request times out, the app retries, and now two events exist for one email. If nobody handles that, the customer pays twice and you find out from a support ticket.
What I find useful is that Atlassian describes two layers of protection. Deduplication spots events that describe the same action and throws the extra one away. Idempotency is the stronger guarantee: the same request, sent any number of times, produces the same single result. The name comes from mathematics and the meaning is simple. Pressing an elevator button five times still calls the elevator once.
In practice, idempotency usually means a client-generated key attached to the request. The server records the key alongside the result. When a duplicate arrives, the server returns the stored result and skips the work. The pipeline also uses layered storage for this, keeping temporary event logs in fast short-term stores before committing to long-term records. That is how you get both speed and an auditable trail.
The detail I would underline is that the key has to come from the client. If the server generates it, a retry arrives as a brand new request and the protection is gone. It goes wrong in exactly that way in systems where everything else looks correct.
I keep coming back to the failure mode, because it is rarely the happy path. It is the retry after a timeout, the webhook delivered twice, the user who clicks submit three times because the button did not respond. Each of those is a normal event, and each one is a chance to bill someone twice.
A second failure mode is the cleanup. Idempotency keys need a retention window. Too short and a slow retry slips through. Too long and the store grows without bound. A day is the retention window I would start with, and it is worth writing down why you picked it.
A third is reconciliation. Even with both mechanisms, you want a way to compare events received against events billed, by customer, on a schedule. If the numbers drift, you want to know before the invoice goes out, not after.
The business argument
The post also makes a case for usage-based pricing itself, and I think it is mostly right for infrastructure-style products. A low entry price lowers the barrier for a budget-conscious buyer, and revenue grows as the customer's usage grows. The risk is the opposite of what people expect. Customers on usage pricing watch the meter, and a surprise spike is a churn event even when the charge is technically correct. That is another argument for near-real-time visibility and for spend alerts, which the write-up does not cover but any team building this will need.
It also points at ready-made billing providers such as Stripe as a way to launch usage billing in days rather than building an architecture like this from scratch. I agree with that for most companies. The parts you should not outsource are the event definition and the idempotency story. A billing vendor can meter what you send it. It cannot decide what a billable event is, and it cannot stop your services from sending the same event twice.
What I would do first
Before writing any pipeline code, write down the events you will charge for, in plain language, and who owns each one. Then write down what happens when the same event arrives twice, arrives late, or never arrives. Those three sentences will save more money than any infrastructure choice.
Then build the smallest version: one event type, one idempotency key, one reconciliation report. Run it against real traffic for a month and compare the totals by hand. If the numbers match, add the second event type.
The dispute path is the part I would test first. My bet is that this is where teams underbuild, because the fast logs have aged out by then and nobody wants to reconstruct the story. An answer that survives an audit is the product.
Written with AI assistance, reviewed and edited by Do Minh Tuan.