Skip to content
Sonic AI

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

Lokesh Mahala, CEO & Co-founder

· Updated · 2 min read

A database sending rows along a line into a scheduled sync.
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.

FieldMeaning
NameOperator label
TableSchema.table being read
StatusDraft until activated
ScheduleDaily, monthly, billing period end, etc.
Last syncFreshness indicator
New rowsBillable 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 daily schedule.

See the usage templates guide for the Process step and idempotency in detail, and idempotency as a product feature for why it matters.

  • 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.
Lokesh Mahala

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.

FAQ

Can Sonic read usage straight from our database?

Yes. A data link runs a query against your database on a schedule, reads only rows newer than the last marker, and turns them into usage events with the same template mapping as a file upload. Point it at a read replica and give it a read-only database user.

Does turning on a data link backfill old usage?

No, not unless you set a start position on purpose. The safer cutover is to keep the file upload running for one more billing period, run the sync alongside it, and compare event counts. Switch over once a full period's numbers agree.

What happens when our database schema changes?

A renamed or removed column breaks the template mapping, and the sync errors until the mapping is updated. Changing a mapping only affects future reads, so events already ingested are not rewritten. Watch the New rows column after every migration.

How do we avoid counting the same row twice?

Set the template's idempotency key to the columns that make a row unique, such as an event id. If a sync retries or reads an overlapping window, the repeated rows are recognised and skipped instead of creating a second usage event.

See Sonic run on one of your contracts.

A 30-minute call with the team, using your own contract.

Book a demo