Use when designing or reviewing a backend MVP with tight budget, evolving schema, and reliance on third-party backends where idempotency, replay, and responsibility attribution are high-risk.
Minimize irreversible decisions. Every write must be idempotent, every aggregate must be replayable, and every incident must be attributable with minimal evidence.
When NOT to use: throwaway prototypes where data loss and misattribution are acceptable.
vibescore_tracker_hourly)user_id + device_id + source + model + hour_startRequired fields: request_id, function, stage, status, latency_ms, error_code, upstream_status, upstream_latency_ms
Attribution rules:
upstream_status => UNKNOWN (do not change data semantics)upstream_status is 5xx/timeout and function status is 5xx => likely vendor/backbone issueupstream_status is 2xx and function status is 4xx/5xx => likely application validation/logic issuelatency_ms high and upstream_latency_ms low => likely application-side bottleneckStop rule: no data rewrite, schema change, or semantic patch without a replay plan and rollback.
| Guardrail | Why | Minimum Implementation |
|---|---|---|
| Idempotent writes | Prevent double-counting | Unique key + upsert |
| Replayable aggregates | Safe fixes | Source-of-truth table + backfill job |
| Cost caps | Fit low budget | Range limits + pre-aggregates |
| Evidence-first | Avoid misfix | M1 structured logs |
| Schema allowlist | Avoid data bloat | Reject unknown fields |
const start = Date.now();
const requestId = crypto.randomUUID();
const log = (entry) =>
console.log(
JSON.stringify({
request_id: requestId,
function: "example-function",
...entry,
}),
);
try {
const upstreamStart = Date.now();
const res = await fetch(upstreamUrl);
const upstreamLatency = Date.now() - upstreamStart;
log({
stage: "upstream",
status: res.status,
upstream_status: res.status,
upstream_latency_ms: upstreamLatency,
latency_ms: Date.now() - start,
error_code: res.ok ? null : "UPSTREAM_ERROR",
});
} catch (err) {
log({
stage: "exception",
status: 500,
upstream_status: null,
upstream_latency_ms: null,
latency_ms: Date.now() - start,
error_code: "UPSTREAM_TIMEOUT",
});
throw err;
}
upstream_status evidence| Excuse | Reality |
|---|---|
| "We are a tiny team, logs are overkill" | Small teams need stronger evidence, not weaker. |
| "Vendor is unstable, we cannot know" | You still need M1 logs to avoid misfixes. |
| "Budget is low so scans are fine" | Low budget means scans fail sooner. |
| "We can patch the numbers" | Patches without replay create permanent drift. |