skip to content

A daily quota per customer: how does anchoring the period to a shared clock rather than the customer's first call change the store?

level: middleimportance: should knowfreq 55%

answer

  1. where does the period start live
  2. key name, or the entry's deadline
  3. deadline becomes part of the contract
  4. pushed-forward deadline never resets
  5. shared boundary synchronises every subject

basics

~20 s

A shared clock puts the period in the key, so no extra state is stored and every subject resets at the same instant. First-call anchoring puts the period start in the counter's own lifetime, making the deadline load-bearing.

solid answer

~50 s

With a shared-clock period, the period identity is derivable from the clock alone and is written into the key - a subject identifier plus a period stamp. Any instance can compute the current key, and the entry's lifetime only has to outlive its own period. With first-call anchoring there is no agreed stamp, so the period start is carried by the counter itself: it is created on the subject's first call with a **fixed lifetime (counted from the write)**, and when that deadline passes the subject's allowance is fresh again. That makes the lifetime part of the contract rather than housekeeping, and it rules out an **access-extended lifetime (pushed forward by each use)** - a subject that keeps calling would never reach its reset and would stay refused. The visible difference is the reset moment: one is the same instant for everybody, the other is per subject and cannot be stated on a calendar.

go deeper

for a junior

Learn the two options and where each keeps the period start: in the key name when it comes from a shared clock, in the entry's own deadline when it starts at the subject's first call.

for a middle

Explain why the same missing deadline is a leak in one design and a permanently refused customer in the other, and why a deadline that every call pushes forward stops a period counter ever resetting.

for a senior

Show that you would check, on the store you actually run, whether rewriting an entry preserves its deadline - because the usual fix for undated counters quietly turns a fixed lifetime into an extended one on stores where it does not.

for a principal

Treat the reset moment as a product commitment before a storage decision: it is on the pricing page, support explains it, and the anchoring choice also decides whether your tier absorbs a synchronised reset or a smooth one.

## Two ways to say when the period starts *One thousand calls per day per customer* does not say what a day is. There are two answers, and they put the period's start in two different places. **Anchored to a shared clock.** A day means a named calendar day. The period identity is derived from the clock, so it can be written into the key itself: subject identifier plus period stamp. Every application instance computes the same key without consulting anything, and the counter is pure count. **Anchored to first use.** A day means twenty-four hours from this customer's first call. There is no agreed stamp to put in the key, so the period start has to be remembered - and the cheapest place to remember it is the counter's own **entry lifetime**. The counter is created on the first call with a fixed lifetime of one period, and the moment the store reclaims it is the moment the subject's allowance returns. ## What each one asks of the store | | anchored to a shared clock | anchored to first use | |---|---|---| | where the period start lives | in the key name, derived from the clock | in the entry's own deadline | | key shape | subject plus period stamp | subject only | | what the lifetime is for | housekeeping: stop the key leaking | the contract: it *is* the reset | | effect of losing the deadline | one leaked key, enforcement unaffected | the subject never gets a fresh allowance | | when subjects reset | all at the same instant | staggered, one per subject | | can support state the reset time? | yes, from the calendar | only by reading the entry's remaining life | The fourth row is the one that catches teams out. Under shared-clock anchoring, a missing deadline is the leak described elsewhere in this subject - unpleasant but not a correctness bug, because the *next* period uses a different key anyway. Under first-use anchoring, the deadline is the only thing that ends the period, so an undated counter means a customer that hits its quota is refused permanently. The same missing line of code has two entirely different severities. ## The lifetime kind matters here, and only here A lifetime can be **fixed, counted from the write**, or **access-extended, pushed forward by each use**. On a period counter the second is always wrong, and the failure is worth being able to state out loud: every request extends the deadline, so an active subject's counter never reaches it, the period never ends, and once the count crosses the quota that subject is refused for as long as it keeps trying. The subject is punished for exactly the behaviour the quota was meant to shape. The trap is that you can arrive at an access-extended lifetime without choosing it. On stores where writing an entry replaces it outright and discards whatever deadline it carried, a code path that re-dates the counter on every increment - added, usually, to fix the undated-counter bug - silently converts a fixed lifetime into an extended one. Stores differ in whether an ordinary write preserves an existing deadline, so this is a property to check on the store you actually run rather than to assume. ## The operational shape of a shared boundary Shared-clock anchoring has a second-order consequence in the store. Every subject's counter is created in the same small stretch of time after the boundary, and every one of them carries a deadline that falls in the same small stretch a period later. The tier therefore sees a synchronised creation burst and a synchronised reclaim, once per period. For a daily period on a modest subject population this is invisible. For a per-minute period across a large population it is a recurring shape in the tier's write rate and resident size, and it is worth knowing it is the enforcement design causing it rather than the traffic. First-use anchoring spreads both events across the period by construction, because each subject's clock started whenever it happened to arrive. ## Which to choose Choose the one the product promised, because the reset moment is user-visible and support will be asked about it. A quota described on a pricing page as *per day* implies a calendar reset that a customer can plan around; a quota described as *per rolling twenty-four hours* implies first use. One honest warning about each. Shared-clock anchoring concentrates the reset, so the most eager subjects re-arrive together at the boundary - the allowance returns for everybody at once. First-use anchoring makes every subject's reset unexplainable without inspecting the store, which is a support burden and an audit problem, and it means two subjects with identical usage can be treated differently depending on when they happened to start. What neither anchoring changes is the counter's dependence on the tier. Both hold a number that exists nowhere else, and both return to zero if that entry disappears before its period ends. ## What the period key has to carry Three things, and leaving any one out is a different failure: - **the subject** the allowance belongs to, at the granularity the allowance is written in — per account is not per user, and per user is not per device; - **the period**, encoded so that two adjacent periods cannot collide and so that reading the key tells you which period it is — a truncated timestamp does both; - **the allowance's identity**, where one subject has several — a read allowance and a write allowance that share a key silently spend each other's budget.

  • Around the moment a shared-clock period ends, how many counter keys exist for one active subject?
    Two, briefly. The new period's key is created by the subject's first call after the boundary, while the ended period's key survives until the store reclaims it - memory does not come back the instant a deadline passes, and when it does differs by store. So the tier's peak footprint for this design is about two counters per active subject, not one. It also means a subject's calls in that stretch are charged against two different period keys.
  • Under first-use anchoring, how does a caller find out when its allowance returns?
    By asking the store how much life the counter has left, since nothing else records the period start. That works, but it makes a housekeeping property of the entry into an answer the product gives customers - and it stops working the moment the entry disappears early, at which point the reported reset time and the actual one disagree.
  • Can you get first-use behaviour without leaning on the deadline?
    Yes, by storing the period start explicitly alongside the count and comparing it on each request, which needs either a value the server understands well enough to update in part or a read-modify-write. It costs a round trip or a richer value shape, and buys a period start you can read, log and explain without inferring it from an entry's remaining life.

saying these in an interview costs you the question

  • Cannot say where the period start is recorded in either design.
  • Uses a deadline pushed forward by every call on a period counter.
  • Assumes a rewrite of the counter preserves its existing deadline.
  • Thinks a missing deadline is equally harmless under both anchorings.
  • Promises a calendar reset while anchoring the period at first use.