What happened, and when
Apps log events: sign-ups, orders, errors. Build an event log and a daily summary using this unit's PostgreSQL features.
Design the event table
Event logs grow quickly, so plan for size from the start: index by kind and time, keep payloads small, and archive or delete events older than you need for reports.
An event log is mostly written and rarely changed. Each event has a kind from a fixed list, a precise moment, and a payload whose shape depends on the kind: a sign-up has a user id, an order has a total, an error has a message. That mix — fixed columns plus a flexible document — is exactly where enums and JSONB shine together.
- kind event_kind NOT NULL — enum: signup, order, error.
- at timestamptz NOT NULL DEFAULT now() — when it happened.
- data jsonb NOT NULL DEFAULT '{}' — the details for that kind.
- tags text[] — optional labels such as 'mobile' or 'beta'.
Index what dashboards filter on: (kind, at) for "orders this week", and GIN on data if you search inside payloads.