Datasources
Primary source
events_by_ingested_at is the single ingestion point. All events are written here from Python via ingest_events() in server/polar/integrations/tinybird/service.py.
Materialized views
All datasources (materialized views and regular tables) live intinybird/datasources. The materialization pipes in tinybird/pipes define how the views are built.
Lineage
Adding a column
- Add the column to
datasources/events_by_ingested_at.datasource - Map the field in
TinybirdEventinserver/polar/integrations/tinybird/service.py(the_event_to_tinybirdfunction) — fields are extracted fromuser_metadatavia.pop()so they’re denormalized into columns - Add it to any materialized view datasources that need it (e.g.
events_by_timestamp.datasource,system_events_by_org.datasource) - Update the corresponding materialization pipes to SELECT the new column
Local development
tb fmt --diff, tb build, and tb test run on any changes to server/tinybird/**.
Deploying changes
tb --cloud workspace ls and tb --cloud workspace use <name>.
Tinybird performs a migration of historical data on deploy. If a column change requires backfilling, add a Forward Query.
Deploys with backfills can take >45 minutes depending on data volume.
Ingestion errors and reconciliation
If events have failed to ingest, use the reconcile script to find and re-ingest missing events:events_by_ingested_at datasource in the given time range, then re-ingests any missing events.
Tinybird has a slight latency from PostgreSQL, so if your end timestamp is close to the current time, it will always report a mismatch. Running it with those events will generate duplicates.
Other scripts
- Full backfill:
uv run python -m scripts.backfill_tinybird_events --batch-size 5000 --start-date <iso8601> --cutoff-date <iso8601> - Cleanup/reingest specific events:
uv run python -m scripts.tinybird_events_cleanup events.json --delete --reingest

