Skip to content

Postgres usage sync — incremental data links without monthly exports

Read replicas, marker columns, draft vs active links, and the same template discipline as file uploads.

Akaash Gupta

Software engineer

7 Sept 20262 min read

IntegrationsStripe, Razorpay, Postgres, Slack, and migration paths.

Exporting a CSV every month works until it does not — file arrives late, columns shift, someone runs the wrong query. Postgres data links let Sonic query your database on a schedule and turn rows into usage events with the same template mappings as uploads.

Same billing outcomes; less ritual; more need for ops discipline.

Field Meaning
Name Operator label
Table Schema.table being read
Status Draft until activated
Schedule Daily, monthly, billing period end, etc.
Last sync Freshness indicator
New rows Billable rows from last sync

Draft links never pull production billable data. Activate only after template Process succeeded on a representative sample.

Incremental sync model

Sonic runs your query, remembers how far it read, and next run asks only for rows newer than the marker.

Requirements:

  • Marker column (timestamp or monotonic id) indexed
  • Query deterministic ordering
  • Template idempotency key aligned with row identity

Without an index, the query scans the whole table monthly until it times out.

  • Point at a read replica, not production primary — billing queries should not slow product DB.
  • Restrict DB user to SELECT on intended tables.
  • Network allowlist Sonic sync workers per your security model.
  • Monitor New rows column after deploy — zero forever means broken query; spike means mapping bug.

Activation and backfill

Turning a link on does not automatically backfill all history unless you configure a start position deliberately. The safer cutover most teams run in practice: keep the existing file upload process alive for one more period, run the new sync alongside it, and compare event counts between the two before trusting the sync alone. Only cut over once a period's numbers agree.

Changing template mappings changes future reads only — past ingested events do not rewrite.

Shared template rules

Customer resolution, transforms, idempotency, and Process gate discipline match file-based templates:

  • Bad mapping × hourly schedule = large wrong event volume quickly.
  • Idempotency keys must survive retries.
  • Test on small date window before daily schedule.

See usage-template-ingestion-guide for Process and idempotency detail.

Watch out for

  • A draft link looks identical to an idle one at a glance. Check status explicitly before assuming a sync is running.
  • No index on marker — performance cliff.
  • Primary DB load — use replica.
  • Schema migrations — column renames break mappings silently until sync errors.
  • Late rows still affect open invoice drafts; sent invoices follow immutability rules.

See it on the platform

Everything above describes how Sonic actually runs it — the product pages show the screens.

Written by

Akaash Gupta · Software engineer

Builds the billing engine. Writes about the mechanics — ingestion, proration, immutability — and the edge cases that decide whether an invoice is right.

Related questions

Still have questions?

How do usage and seats get in?

Templates map vendor files or a Postgres connection. Usage is events. Seats are daily snapshots compared to the balance on record. Large files are a first-class path, not an afterthought.

Do you process payments or file tax returns?

Sonic does not take the place of a payment processor, a tax engine of record, a general ledger of record, or a CPQ. Stripe and Razorpay can collect on an invoice. Your accountant still owns the books Sonic feeds.

Are seats events or snapshots?

Snapshots. Each row is how many they had that day. Sonic compares it to the balance on record and writes an event only when the count changes. Vendor increase/delta columns are not imported — they break at customer boundaries.

See the full FAQ →

Next

See it on your contracts

A walkthrough on the agreements and files you actually bill from — not a slide deck.