skip to content

For a reporting system with users in several time zones, which zone should store event times, which should define a day's bucket, and what does each choice cost?

level: principalimportance: should knowfreq 37%

answer

  1. storage and reporting are separate decisions
  2. whose midnight is the business day
  3. totals that reconcile versus days people expect
  4. half-hour offsets and rollup grain
  5. future events are a different case

basics

~20 s

Store past events as instants, usually in UTC, and pick bucket zones by who uses the number. One business zone keeps totals reconcilable; viewer zones match local expectations but stop totals agreeing; serving both needs finer rollups.

solid answer

~50 s

I'd split it into two decisions. Past events are instants, so I'd store them in a form that pins the instant, normally UTC, and never as an unlabelled local time, because a clock change makes an hour of local readings ambiguous. Where a day begins is a business decision. One reporting zone, often finance's, gives totals that reconcile and a stable meaning for yesterday, but distant users see days that start mid-afternoon. Viewer-zone buckets match what people expect, yet one sale falls on different days for different viewers, and daily totals stop agreeing between them. To serve both, I'd roll up at a grain that can rebuild any zone's day, 15 minutes rather than an hour because some zones sit on half-hour and 45-minute offsets, and accept the extra storage. Then I'd write down the default, and label every report with its zone.

go deeper

for a junior

Recall that an instant and a local clock reading are different things, and that a day's boundary depends on a zone. Saying that a report should name its zone is already a useful instinct.

for a middle

Explain why instants are the safe form for past events, and show how one instant lands on different local dates. Name what plain local storage loses during a clock change.

for a senior

Tie zone choices to concrete failures: reports that disagree, rollups that cannot serve a new region, and ambiguous hours. Propose rollup grains that match the zones actually needed, and keep raw events available for rebuilding.

for a principal

Separate the storage decision from the bucketing decision, and assign each an owner. Weigh reconcilable totals against what each audience expects, set a default by report class, and write down exceptions and restatement rules.

## Two decisions, usually conflated "What time zone do we use?" sounds like one question. It is really two, with different owners and different costs: - **Storage** asks how to record what happened so that the fact can never be lost. It is an engineering decision, and it is hard to reverse once data exists. - **Bucketing** asks where one reporting day ends and the next begins. It is a business decision about what a number means, and it can differ per report as long as the stored data allows it. Teams get into trouble when they treat "store in UTC" as settling both. A database can hold perfect instants and still publish daily numbers that nobody can defend. ## Storing past events | Storage choice | What it keeps | What it costs | |---|---|---| | Instants, in UTC | the exact moment, always | every local view needs a conversion | | Instant plus the event's zone name | the moment and its local context | one more column to populate and validate | | Plain local time, no zone | the reading only | one hour a year is ambiguous; moving regions is painful | For events that have already happened, the instant is what you cannot rebuild, so it is the part to protect. Add the zone name when a report needs the event's own local day, such as a store's trading day, because the zone in force at that moment is not derivable from the instant alone. **Future events are the exception.** A meeting at 09:00 local next year means "09:00 on the clocks there", even if the government changes the rules first. Storing today's computed UTC value would silently move it, so keep the wall-clock reading with the named zone, and compute the instant when you need it. ## Choosing the bucket's zone | Bucket zone | Works well for | What it costs | |---|---|---| | One business zone | finance, company-wide totals | distant users see days starting at odd hours | | UTC | internal engineering metrics | a business day that matches nobody's clock | | The entity's zone (each store's own) | operational reports per location | days across locations cover different instants | | The viewer's zone | personal dashboards | the same sale falls on different days per viewer | No row in that table is right in general. A sensible default for many companies is one business zone for anything that gets reconciled, with viewer zones for personal views, labelled as such. A customer-facing product may need the opposite default, and a lead has to make that call openly. ## What it costs to serve several zones Precomputed daily rollups fix one zone into the data, which is where this decision becomes expensive. The options, in rising order of cost: 1. **Daily rollups in one zone.** Cheap and fast, but another zone's report goes back to raw events. 2. **Hourly rollups by UTC hour.** These rebuild the day for whole-hour zones, including those with clock changes, since each UTC hour maps to a known local hour. They cannot rebuild zones at half-hour offsets such as India's UTC+05:30. 3. **Rollups every 15 minutes.** These also cover UTC+05:45 in Nepal, at up to 96 rows per day per dimension combination instead of 24. 4. **Query raw events by zone.** This is exact for anything, and it costs the most at query time. Choose by how many zones truly need fast answers. Keeping the raw events matters whichever you pick, because rollups can then be rebuilt when the definition changes. ## What a lead writes down - **The default reporting zone**, by report class, and who may approve an exception. - **A label on every report and export** that names its zone, so a mismatch can be explained in a sentence. - **One shared definition in code**, such as a view or a helper for "business day", so authors do not hand-write conversions. - **The restatement policy**: what happens to closed periods if a tenant changes its reporting zone. - **Who updates the zone database.** Governments change clock rules at short notice, so stale zone data gives wrong local times for future dates and recent events. ## Signals the decision needs revisiting - Finance and a dashboard disagree by a small, repeating amount around month ends. - Support hears that yesterday's numbers changed, or that a sale appeared on the wrong day. - A new market opens at a half-hour offset, and the hourly rollups can no longer serve it. - A team has started adding its own offset to a report, which shows that the shared definition is failing them.

  • When would you not store an event as a UTC instant?
    When it has not happened yet and people care about the local clock, such as an appointment at 09:00 next year. If the place changes its clock rules, a stored UTC value now means the wrong local time. Keep the wall-clock reading and named zone, and compute the instant near the time.
  • A tenant changes its reporting zone. Would you restate its history?
    It depends on what the numbers have been used for. I would usually keep closed periods as published, because invoices and reports already rest on them, and apply the new zone from an effective date recorded per tenant. If raw events survive, a restatement on request remains possible and should be labelled as such.

  • Storing everything in UTC settles the reporting question, because the business day follows automatically.
  • Bucketing in UTC is neutral, so no user ever sees a misleading day.
  • Hourly rollups by UTC hour can rebuild the local day of every time zone.
  • Per-viewer daily buckets will reconcile with a single company-wide daily total.
  • Storing a future local appointment as a UTC instant is always the safest choice.