We want an order that a partner’s API call just created to show up in analytics within seconds, so that a fall in orders or a rise in failures is visible while it is happening. And we want that without a single analytics query touching the databases that take the orders. This post is about how we hold both, and what it cost us.
The problem
Orders, payments and redemptions live in each service’s own database, built for many small writes. Analytics wants the opposite: scans over months of rows, grouped by hour, joined across services. Run those scans where orders are taken and they compete with checkout. Move them to a read replica and checkout is safe, but the scans are still slow.
The data also comes in two shapes. Orders change: an order is created, moves on and settles. Events do not change: a screen view in an app, or a record a service writes about its own work. Each shape wants its own path.
The principles we chose
The order path is blind to analytics. Taking an order never waits on analytics and never fails because of it. If the analytics side is slow or down, orders carry on and the numbers catch up later.
State travels as changes, not as copy code. Each change to an order is picked up from the database’s own record of changes and streamed into a separate store built for analysis. Service teams own their data and nothing more. They write no code to feed analytics, and they do not need to know it exists.
Events travel separately. App and service events are accepted at once and written later in batches. One bad event is set aside instead of blocking the rest.
Money comes from orders, not events. Events are good for understanding behaviour. Any question about money is answered from the copied order records, which are the same facts the services themselves hold.
What fresh means
Fresh means the age of the newest data in the copy. Not a replication metric, and not the time a table was last synced.
We learned this the slow way. A replication lag metric can rise when no data is late at all, and a table’s last-synced time can look stale only because nothing in it changed. Both measure the machinery. Neither answers the question a person reading a dashboard has: is what I am seeing current?
Fresh matters because a problem is cheapest to fix while it is happening. A partner whose orders are failing wants to know in minutes, not in tomorrow’s report.
Monitoring that knows what normal looks like
A gift card business grows, and it has a strong rhythm through the day and the week. A fixed line, such as “alert when orders fall below a number”, is wrong most of the time. It fires on every quiet night, or it sleeps through a real drop at a busy hour.
So we hold our monitoring to two principles.
- Alert on what is unusual for this hour and this business. Normal is judged against comparable times for the same business, not against one number for everyone.
- An alert a person cannot act on is noise. Every alert should point at something a person can check and do something about. One that cannot is fixed or removed, because each false alarm teaches people to ignore the next one.
A third idea follows from the pipeline itself: a monitor should be able to tell “the business is down” apart from “the data is behind”. They are different problems with different owners, so we watch them separately. We leave out the detail of how our monitors work on purpose.
The trade-offs we accepted
| Choice | What we gained | What it cost |
|---|---|---|
| A separate analytics copy | Checkout is never slowed by a report | Another moving part, and a little lag |
| Changes streamed from the database | No copy code in any service | Every query must ask for an order’s current state, not its history |
| Events written in batches | Apps never wait on analytics | Events are good for behaviour, not for money |
The second row is the one to watch. We put that rule into shared query helpers rather than into anyone’s memory.
What we would tell another team
- Keep the order path blind to analytics from the first day. It is much harder to remove a dependency than to never add one.
- Measure freshness the way a reader feels it: the age of the newest data, in a table that changes all the time.
- Judge normal against the same hour and the same business, not a fixed line.
- Treat every alert nobody can act on as a bug.
- Make the correct way to query the copy the easy way, in shared code.
To build on our platform, start with the API docs. If you would like to work on problems like this, see careers at Hubble.