Usage sync from your database, without monthly exports
How a data link turns database rows into usage events on a schedule: what it stores, how incremental sync works, the safe setup, and how to cut over.
Lokesh Mahala, CEO & Co-founder
· Updated · 2 min read

On this page
Exporting a CSV every month works until it doesn't: the file arrives late, columns shift, or someone runs the wrong query. Database data links let Sonic query your database on a schedule and turn new rows into usage events, using the same template mappings as file uploads.
You get the same invoices as with uploads and no monthly export, but the sync needs the care you'd give any scheduled production job.
What a data link stores
| 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 billable data. Activate a link only after the template's Process step has succeeded on a representative sample.
How incremental sync works
Sonic runs your query, remembers how far it read, and on the next run asks only for rows newer than the marker.
Requirements:
- A marker column (a timestamp or an always-increasing id) that is indexed
- A query with a fixed, deterministic order
- A template idempotency key that matches what makes a row unique
Without an index, the query scans the whole table on every run until it times out.
The safe setup
- Point at a read replica, not the production primary, so billing queries never slow down your product's database.
- Give the database user read-only (SELECT) access to the intended tables only.
- Allowlist Sonic's sync workers on your network, per your security policy.
- Monitor New rows after the link goes live. Zero for days means the query is broken; a sudden spike means a 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. Events already ingested are not rewritten.
Same template rules as file uploads
Customer resolution, transforms, idempotency and the Process step work exactly as they do for file uploads:
- A bad mapping on an hourly schedule creates a lot of wrong events quickly.
- Idempotency keys must survive retries.
- Test on a small date window before switching to a
dailyschedule.
See the usage templates guide for the Process step and idempotency in detail, and idempotency as a product feature for why it matters.
Watch out for: a link that looks idle
- 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: queries slow down sharply as the table grows.
- Primary DB load: point the link at a read replica instead.
- Schema migrations: a renamed column breaks the mapping silently until the sync errors.
- Late rows still affect open invoice drafts; sent invoices follow immutability rules.

Written by
Lokesh Mahala
CEO & Co-founder, Sonic AI · LinkedIn
Lokesh is the Cofounder & CEO of Sonic AI. Before starting Sonic, Lokesh was an engineer at Stripe for 4 years building Stripe's Revenue and Finance Automation suite. He was a founding engineer at Recko (acquired by Stripe in 2021) where he built reconciliation solutions for B2C companies. He completed his bachelors from IIT Roorkee.


