Keeping a property management service available during production API key rotation requires a period of credential overlap, but overlapping access must not become overlapping billing records. Short answer: schedule usage fetches into your own store, preserve a stable billing identity across credential changes, publish complete snapshots atomically, and show the last successful collection time separately from the period the usage covers. Rotate the credential used by the collector as a separate deployment step; a fresh credential must not reset the chart or change which property owns a charge.
The constraint is attribution accuracy. A chart that stays available while silently assigning usage to the wrong building is a poor outcome, even if every fetch succeeds. For this design, availability means continuing to serve the last complete snapshot during a rotation, with its age visible; continuous access to the upstream service additionally depends on whether its credential lifecycle supports an overlap window. Verify that capability before promising a rotation without downtime.
What identity survives a credential change?
Treat a key as a means of access, not as the owner of a bill. In the proposed property ledger, each usage record belongs to a stable account and property, with a meter dimension and a defined usage interval. Keep a nonsecret credential generation identifier as collection evidence, separate from those billing dimensions. OWASP's Secrets Management Cheat Sheet discusses secret lifecycle management, rotation, access controls, and auditing; those controls provide the security baseline, while the attribution schema remains an application design decision.
Consider a hypothetical account called portfolio-west with properties courtyard and riverside. Credential generations 17 and 18 both authorize collection for that account. If a fetch made with generation 18 returns usage already collected with generation 17, a cache indexed by credential generation can create two apparent charges for the same interval. Another tempting implementation replaces every property's data with an account total because the new credential can see only account-level aggregates. That loses the allocation evidence. Neither result becomes trustworthy merely because the response arrived recently.
Identity comes first.
Before accepting a snapshot, validate its account scope and the dimensions required by the billing workflow. If the source provides no reliable property allocation, store the account total as an account total and label property attribution unavailable. Do not manufacture a split. If it provides stable record identifiers, preserve them; otherwise, define and document a composite identity only after checking the source's aggregation and revision semantics. An interval, by itself, is not necessarily unique.
How should a scheduled fetch store API usage in a dashboard cache?
The scheduled collector should own upstream access. Dashboard requests should read the published snapshot from your store, so a page refresh does not initiate another collection or expose a production credential. This is a proposed separation of responsibilities, not a claim about a particular API. The same design can sit behind an existing JavaScript application; the example below uses Python to make the storage contract explicit.
Store the requested usage interval, source scope, collection completion time, credential generation, schema version, and snapshot identifier alongside the data. When the upstream response supplies a reporting watermark or an update timestamp, preserve it under its own name. A successful fetch at 10:05 does not establish that usage is complete through 10:05. If the source offers no completeness signal, display that limitation rather than treating collection time as evidence of accounting finality.
There are three different clocks here.
The usage interval answers which activity is represented. The last successful collection time answers when the collector last retrieved and validated a snapshot. The last attempted collection time answers whether the scheduler is still trying. Advancing the second clock after a failed attempt makes old data look new; advancing it because the browser read the cache is worse, because a popular dashboard would appear perpetually fresh without collecting anything.
For a hypothetical 5-minute schedule, the following display policy uses a 15-minute freshness budget. Those are example policy choices, not service guarantees. The function deliberately makes no claim that recently collected usage is settled for billing. It also treats a future collection timestamp as a clock problem rather than quietly reporting zero age.
from datetime import datetime, timedelta, timezone
def snapshot_status(snapshot, now):
if now.tzinfo is None or now.utcoffset() is None:
raise ValueError("now must include a timezone")
collected_at = datetime.fromisoformat(
snapshot["last_successful_collection_at"]
)
if collected_at.tzinfo is None or collected_at.utcoffset() is None:
raise ValueError("collection timestamp must include a timezone")
age = now - collected_at
if age < timedelta(0):
return "clock discrepancy"
if age > timedelta(minutes=15):
return "stale collection"
return "recent collection; completeness checked separately"
snapshot = {
"account_id": "portfolio-west",
"property_id": "courtyard",
"credential_generation": 18,
"last_successful_collection_at": "2026-11-22T10:00:00+00:00",
}
now = datetime(2026, 11, 22, 10, 16, tzinfo=timezone.utc)
assert snapshot_status(snapshot, now) == "stale collection"
This is display logic only. Persistence, source validation, and scheduling need their own contracts. In particular, don't infer billing completeness from the status string.
Publish a snapshot without tearing the ledger
Collect into a candidate snapshot before changing what readers see. Fetch every required page, validate scope and units, then make the completed candidate visible through a single publication boundary supported by the chosen store. A transactional store can commit the snapshot and its active reference together. With immutable objects, use a publication mechanism whose documented consistency and conditional-update behavior meet the reader contract; do not assume that writing several objects makes them visible as one unit.
A failed collection should leave the previous published snapshot intact.
The important failure mode is a partial replacement: a collector writes courtyard's new rows, fails before riverside's rows arrive, and the dashboard now displays an account total assembled from different collection runs. A related race occurs when an older scheduled job finishes after a newer one and overwrites its publication reference. Use an explicit publication ordering rule and enforce it at the write boundary; timestamps in an application log do not prevent that race.
Keep collection attempts as operational evidence, with outcome and nonsecret generation identifiers, while keeping raw credentials out of records, logs, and browser responses. Apply the same care to backups and retained snapshots: retaining collection evidence does not justify retaining the secret that authorized it. Verify durability and recovery behavior against the actual store's documented guarantees before treating the cache as billing evidence.
Repeated collection also needs an explicit replacement rule. If the source returns interval totals that can be revised, appending every response and summing them double-counts observations. Preserve snapshot history for investigation, but make the active view select the applicable revision. If the source instead returns events, determine its event identity and delivery semantics before choosing a deduplication rule. There is no universal key that can be inferred from a chart.
Compare publication choices after defining attribution
These are design alternatives, not product rankings. The deciding question is how much consistency and recovery work the team can operate while preserving evidence for each property's allocation.
| Design | Benefit for the dashboard | Attribution boundary and operational cost |
|---|---|---|
| Replace one complete snapshot | Readers see one coherent collection | Simple review path; retain prior versions separately if investigations require them |
| Immutable snapshots with an active reference | Historical collections remain inspectable | Requires a verified publication protocol, retention policy, and protection against older writers |
| Append observations and build a current view | Preserves revisions and collection evidence | Requires source-aware deduplication and selection rules; summing observations is unsafe |
Choose the smallest design that can explain a displayed total after a credential change and after a restore. More retained observations increase storage and review work; less retained evidence makes reconciliation harder. Neither trade-off is resolved by a lower unit price. For a small team, a complete snapshot plus bounded history may be easier to operate than an event ledger, provided its recovery and retention rules satisfy the billing workflow.
Roll out rotation against the published snapshot
First establish the baseline: a complete collection with known scope, visible collection time, and a recorded nonsecret generation identifier. Then prepare the replacement credential with the required access and run a candidate collection before moving the scheduled collector to it. Where overlapping credentials are supported, keep the old credential valid until the replacement has passed the relevant checks. The permitted overlap and revocation process depend on the upstream service's documented lifecycle.
Test the boundaries that can corrupt attribution: repeated intervals across generations, missing property dimensions, incomplete pagination, a late older job, revised usage, and a collection that fails before publication. Compare identical scopes and intervals when reconciling candidate results; differing totals require investigation, because they could reflect source revisions rather than a rotation error. Use controlled test fixtures for those cases, and keep deployment checks separate from assumptions about upstream reporting delay.
Once the replacement passes, switch the scheduled collector, observe a successful scheduled publication, and revoke the retired credential according to the established lifecycle. If the candidate fails before cutover, keep serving the last complete snapshot and investigate before retiring access. After revocation, recovery must use a valid credential; a rollback plan cannot depend on reviving a revoked secret.
The dashboard should expose collection age, reporting coverage when available, and allocation gaps. Alert separately on missed collections and rejected attribution checks, since a functioning scheduler can repeatedly retrieve unusable data. Close the rollout only when the active snapshot preserves property ownership and its displayed timestamps describe the evidence accurately.
Sources
References
- OWASP Secrets Management Cheat Sheet — secret lifecycle, rotation, access controls, and auditing: https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html
Top comments (0)