Users expect mobile apps to work instantly on the subway, in rural job sites, and during airplane flights. Traditional web architecture requires waiting for an API call before updating the screen. Local-first architecture stores data in an embedded on-device SQLite database, rendering reads in 0ms and streaming mutations to PostgreSQL in the background via replication streams.
1. The Local-First Software Manifesto: Speed & Data Ownership
Why waiting for network spinwheels is a broken user experience
Local-first software treats the device database as the primary source of truth, treating the cloud as a synchronization and backup relay. Apps open instantly without loading spinners.
2. Setting Up PowerSync with React Native & PostgreSQL
Sync rules and real-time reactive SQL queries in React
PowerSync syncs PostgreSQL tables directly into client SQLite databases using declarative sync rules defined in YAML.
src/db/queries.ts (typescript)
import { useQuery } from '@powersync/react';
export function ProjectTasksList({ projectId }: { projectId: string }) {
// Executes synchronously against on-device SQLite
// Automatically re-renders when background sync delivers remote changes
const { data: tasks, isLoading } = useQuery(
'SELECT * FROM tasks WHERE project_id = ? ORDER BY priority DESC',
[projectId]
);
return (
<div>
{tasks.map((task) => (
<TaskCard key={task.id} task={task} />
))}
</div>
);
}
3. Resolving Concurrent Offline Sync Conflicts
Deterministic merging with Hybrid Logical Clocks (HLC)
Hybrid Logical Clocks assign monotonically increasing timestamps that combine physical wall-clock time with logical sequence counters, ensuring fair conflict resolution.
4. Mobile Storage Quotas & Partial Sync Buckets
Syncing only relevant user data to preserve mobile disk space
Sync rules ensure mobile devices sync only active projects belonging to the logged-in user rather than the entire corporate database.