Database-to-Database Sync
The most fundamental hibase workflow pattern: transfer data from one database to another. Typically used to replicate production data to a data warehouse for analytics.
How It Works
A database sync workflow uses:
- Data source type: SQL Query — reads from the production database
- Step type: Transfer Data — writes to the target data warehouse
- Parameter query: Fetches the latest timestamp from the target to enable incremental loading
- Strategy: depends on your database engine and data characteristics (see Write Strategy below)
Basic Structure
Production DB (source)
└── SQL Query reads new rows
└── Write step inserts into DWH (target)
Example: Sync Users Table
Parameter Query (Step Parameters)
The parameter query runs against the target database to determine what's already been synced:
SELECT
MAX(created_at) AS last_created,
MAX(updated_at) AS last_updated
FROM source_app.users
This produces two parameters: $last_created and $last_updated.
Data Source Query
The main query runs against the source (production) database, using SQL-aware interpolation to handle NULL parameters gracefully:
SELECT *
FROM public.users
{{ WHERE created_at > $last_created }}
{{ OR updated_at > $last_updated }}
On the first run, both parameters are NULL (no data in the target yet). Thanks to the SQL-aware {{ WHERE ... }} syntax, the conditions are nullified:
-- First run (NULL params):
SELECT * FROM public.users WHERE true OR false
-- → fetches ALL rows
On subsequent runs, only new or updated rows are fetched:
-- Subsequent run:
SELECT * FROM public.users
WHERE created_at > '2024-01-15 10:30:00'
OR updated_at > '2024-01-15 14:22:00'
Write Strategy
Choose a write strategy based on your database engine and how the source data behaves:
| Strategy | Use when |
|---|---|
| Insert only | Rows are immutable (events, logs, transactions), or your database is append-only (e.g. BigQuery) |
| Upsert on unique identifier | Rows can be updated in place — requires a unique key and database support |
| Truncate table, then insert | Table should be fully rebuilt each run |
Not all strategies are available on all database engines. For example, BigQuery only supports Insert only, while PostgreSQL and MySQL support all four strategies. See Step Configuration for availability details.
Adding Error Notifications
Always configure an error notification on sync steps:
| Setting | Value |
|---|---|
| Trigger | On Error |
| Notify via | |
| Title | Error: Sync users |
| Body | {{ $log_html }} |
Multi-Table Sync with Dependencies
For related tables, use cross-workflow dependencies to ensure parent tables sync before child tables:
Workflow: "Sync orders" (schedule: every 30 min)
Workflow: "Sync order_items" (schedule: every 30 min, depends on: "Sync orders")
Workflow: "Sync payments" (schedule: every 30 min, depends on: "Sync orders")
hibase automatically manages execution order — all three workflows can be scheduled at the same interval, and dependencies ensure correct sequencing.
Tips
- Use
{{ WHERE ... }}and{{ OR ... }}syntax for NULL-safe incremental conditions (see Using Parameters) - Set the schedule based on data freshness requirements: every 5 minutes for transactional data, hourly or daily for less volatile data
- Add an
imported_attimestamp via step JSON parameters ({{ $now }}) for tracking and freshness assertions - For historized tables (tracking all versions), combine with deduplication to filter out unchanged rows
- Monitor sync health with scheduled reports showing daily row counts per table