Edge Database Sync

HeliosDB Full plans offline-first edge synchronization for applications that must keep working when the network drops: local databases at edge sites accept reads and writes offline, then synchronize with the central server in both directions and resolve conflicts when connectivity returns. Edge computing and sync are on the roadmap and not in the current release, which runs as a single server.

Planned: offline-first edge sync is on the roadmap. Read the documentation.

Executive Summary

The design lets applications run in disconnected environments and stay consistent with the cloud, addressing the needs of retail, field service, IoT, and mobile applications.


Problem Being Solved

Core Problem: Applications fail or degrade when network connectivity is lost, causing business disruption and poor user experience in edge environments.

Root Cause: Traditional databases require constant connectivity:

  • Cloud Dependency: Every query goes to cloud, fails offline
  • Conflict Resolution: Manual handling of offline edits
  • Data Size: Cannot store full database at edge
  • Security: Edge data exposure concerns

The Problem

Edge Application Reality

ScenarioTraditional DBImpact
Retail POS offlineTransaction failsLost sale
Field technicianCannot access dataWasted trip
Mobile workerApp unusableProductivity loss
IoT deviceData buffered locallyAnalysis delayed
Remote locationIntermittent accessPoor UX

HeliosDB Solution: Embedded + Cloud Unified

Key Capabilities

1. Offline-First SQL

// Initialize edge database
const edge = await HeliosDB.initEdge({
  localPath: './local.db',
  cloudUrl: 'heliosdb://cloud.example.com',
  syncTables: ['inventory', 'transactions', 'customers'],
  syncFilter: {
    inventory: { store_id: currentStoreId },
    customers: { region: currentRegion }
  }
});

// Works offline - full SQL support
const result = await edge.query(`
  SELECT p.name, i.quantity
  FROM inventory i
  JOIN products p ON i.product_id = p.id
  WHERE i.store_id = ? AND i.quantity < i.reorder_level
`, [currentStoreId]);

// Write offline - queued for sync
await edge.execute(`
  UPDATE inventory
  SET quantity = quantity - 1
  WHERE product_id = ? AND store_id = ?
`, [productId, storeId]);
// Immediate local commit, syncs when online

2. Automatic Sync

// Sync happens automatically when online
edge.onSyncStatus((status) => {
  console.log(`Sync: ${status.pending} pending, ${status.synced} synced`);
});

// Force sync when needed
await edge.sync();

// Check sync status
const status = await edge.getSyncStatus();
// { lastSync: "2025-11-28T10:30:00Z", pending: 0, conflicts: 0 }

3. Conflict Resolution

// Automatic CRDT-based resolution (default)
edge.setConflictResolution({
  inventory: 'crdt_pncounter',  // Quantity changes merge
  transactions: 'cloud_wins',   // Cloud is authoritative
  customers: 'custom'           // Custom handler
});

// Custom conflict handler
edge.onConflict('customers', async (local, cloud, base) => {
  // Merge logic
  return {
    ...cloud,
    notes: `${cloud.notes}\n${local.notes}`
  };
});

4. Selective Sync

-- Define sync scope (cloud side)
CREATE SYNC POLICY retail_store AS
SELECT * FROM inventory WHERE store_id = :store_id;

CREATE SYNC POLICY retail_store AS
SELECT * FROM customers WHERE last_visit_store = :store_id;

CREATE SYNC POLICY retail_store AS
SELECT * FROM products; -- Full sync for products

-- Edge device syncs only relevant data

Concrete Examples

Example 1: Retail Point-of-Sale

Company Profile: Retail chain with 500 stores, frequent network issues

Challenge: POS must work during internet outages

// POS Application with HeliosDB Edge
const pos = await HeliosDB.initEdge({
  localPath: '/data/pos.db',
  cloudUrl: 'heliosdb://retail.cloud.com',
  syncTables: ['products', 'inventory', 'transactions', 'customers'],
  syncFilter: { store_id: CURRENT_STORE }
});

// Process sale - works offline
async function processSale(items, payment) {
  const txn = await pos.transaction();

  try {
    // Create transaction record
    const txnId = uuid();
    await txn.execute(`
      INSERT INTO transactions (id, store_id, items, total, payment, timestamp)
      VALUES (?, ?, ?, ?, ?, NOW())
    `, [txnId, CURRENT_STORE, JSON.stringify(items), calculateTotal(items), payment]);

    // Update inventory (CRDT counter for quantity)
    for (const item of items) {
      await txn.execute(`
        UPDATE inventory
        SET quantity = quantity - ?
        WHERE product_id = ? AND store_id = ?
      `, [item.qty, item.productId, CURRENT_STORE]);
    }

    await txn.commit();

    // Receipt prints immediately
    printReceipt(txnId, items, payment);

    // Sync happens in background when online
  } catch (e) {
    await txn.rollback();
    throw e;
  }
}

// Business Continuity:
// - 2,347 transactions processed offline
// - Zero revenue loss

Example 2: Field Service Technician

Company Profile: HVAC company with 200 field technicians

Challenge: Technicians need customer data at job sites with poor connectivity

// Field Service App with HeliosDB Edge
const fieldApp = await HeliosDB.initEdge({
  localPath: './field.db',
  cloudUrl: 'heliosdb://hvac.cloud.com',
  syncTables: ['work_orders', 'customers', 'equipment', 'parts_inventory'],
  syncFilter: {
    work_orders: { technician_id: CURRENT_TECH, status: 'assigned' },
    customers: { /* synced via work_orders relationship */ },
    equipment: { /* synced via customers relationship */ }
  }
});

// View customer history - works in basement with no signal
const history = await fieldApp.query(`
  SELECT e.model, e.serial, s.date, s.notes
  FROM equipment e
  JOIN service_history s ON e.id = s.equipment_id
  WHERE e.customer_id = ?
  ORDER BY s.date DESC
`, [customerId]);

// Complete work order - queued offline
await fieldApp.execute(`
  UPDATE work_orders
  SET status = 'completed',
      completion_notes = ?,
      parts_used = ?,
      labor_hours = ?
  WHERE id = ?
`, [notes, JSON.stringify(parts), hours, workOrderId]);

// Technician returns to truck - auto-syncs via cellular

Example 3: Remote Healthcare Clinic

Company Profile: Healthcare network with clinics in rural areas

Challenge: Patient records needed where internet is unreliable

// Clinic EHR with HeliosDB Edge
const ehr = await HeliosDB.initEdge({
  localPath: '/secure/ehr.db',
  cloudUrl: 'heliosdb://health.cloud.com',
  syncTables: ['patients', 'encounters', 'prescriptions', 'lab_results'],
  syncFilter: {
    patients: { primary_clinic: CURRENT_CLINIC }
  },
  encryption: {
    enabled: true,
    key: await loadEncryptionKey()  // HIPAA requirement
  }
});

// View patient record - instant, offline
const patient = await ehr.queryOne(`
  SELECT p.*, json_agg(e.*) as encounters
  FROM patients p
  LEFT JOIN encounters e ON p.id = e.patient_id
  WHERE p.id = ?
  GROUP BY p.id
`, [patientId]);

// Create encounter - works offline
await ehr.execute(`
  INSERT INTO encounters
  (id, patient_id, provider_id, chief_complaint, vitals, notes, timestamp)
  VALUES (?, ?, ?, ?, ?, ?, NOW())
`, [encounterId, patientId, providerId, complaint, vitals, notes]);

// Prescription created offline, syncs to pharmacy system
await ehr.execute(`
  INSERT INTO prescriptions
  (id, patient_id, medication, dosage, quantity, pharmacy_id)
  VALUES (?, ?, ?, ?, ?, ?)
`, [rxId, patientId, medication, dosage, qty, pharmacyId]);
// Pharmacy receives when clinic regains connectivity

HIPAA Compliance:
- Data encrypted at rest (AES-256)
- Audit trail maintained locally
- Syncs securely over TLS
- Access control enforced locally

Example 4: Industrial IoT

Company Profile: Manufacturing plant with 10,000 sensors

Challenge: Sensor data collection with intermittent connectivity

// IoT Gateway with HeliosDB Edge
const gateway = await HeliosDB.initEdge({
  localPath: '/data/sensors.db',
  cloudUrl: 'heliosdb://factory.cloud.com',
  syncTables: ['sensor_readings', 'alerts', 'equipment_status'],
  syncMode: 'continuous',  // Stream as connected
  bufferSize: '10GB'       // Store up to 10GB offline
});

// Collect sensor data every second
setInterval(async () => {
  const readings = await collectSensorReadings();

  // Bulk insert - buffered locally
  await gateway.execute(`
    INSERT INTO sensor_readings (sensor_id, value, timestamp)
    VALUES ${readings.map(() => '(?, ?, ?)').join(',')}
  `, readings.flatMap(r => [r.sensorId, r.value, r.timestamp]));
}, 1000);

// Local analytics - no cloud needed
const anomalies = await gateway.query(`
  SELECT sensor_id, AVG(value) as avg_val, STDDEV(value) as std_val
  FROM sensor_readings
  WHERE timestamp > NOW() - INTERVAL '1 hour'
  GROUP BY sensor_id
  HAVING STDDEV(value) > 2 * AVG(STDDEV(value) OVER ())
`);
// Alert locally, sync to cloud for historical analysis

Conclusion

HeliosDB Edge is planned. It is designed so that organizations can:

  • Ensure Business Continuity: Operations continue during outages
  • Improve User Experience: Instant response, no loading
  • Reduce Complexity: Built-in sync replaces custom code
  • Scale Globally: Millions of edge devices supported

Performance depends on workload and hardware. Published figures are measured on representative fixtures; see the benchmarks page and reproduce them on your own workload.