Offline support is not just nice, it's necessary.

frankylee kellyfrankylee kelly
5 min read

What does offline-first mean?

An offline-first app is an app that is able to perform all, or a critical subset of its core functionality without access to the internet. That is, it can perform some or all of its business logic offline.

Android Developer docs

We've all used apps that did not support offline-first. I can distinctly recall moments of traveling back home to Montana where cell-reception was unavailable, whether driving or flying. In those moments, you can't stream music that hasn't been downloaded, you might be able to check certain Social Media platforms to see an outdated feed, but you can't make any persisted actions, and you certainly can't check your bank account balance or transaction history in most banking platforms. As someone who regularly tracks their bank account history, you can imagine this might cause frustration when in the middle of nowhere without reception.

Offline-first can go by a few names, including local-first and offline-support. It is the architectural decision to prioritize and ensure that the application remains as functional as possible when access to the internet is limited or nonexistent.

A few examples of apps with offline support include streaming services like Disney or Netflix, where users can download movies and shows to their device to watch later, Spotify or Apple Music, where users can download songs and podcasts, and Figma, which syncs design changes once connection is restored. While these are not complete examples of offline-first architecture, it illustrates the importance of supporting local-first usage and how introducing offline support to limited features can yield positive impact to consumers.

I, for one, cannot tell you how grateful I am for being able to download movies on my child's tablet before a long roadtrip—it has saved lives (/s).

Why is offline-first critical?

So, you want to build an app that has its data co-located with its UI? That works offline? That synchronizes between clients? And that lets its users own their data? Welcome to the world of local-first web development.

Local-First Software

Offline support serves a variety of benefits for the consumers of your application. This means that when a user is offline, or has poor internet connection, they can still access and use the app to its full (or mostly-full) extent. This is beneficial for folks who live in remote areas, where a stable connection may be intermittent or mostly non-existent, for city-dwellers when passing through a tunnel or riding an elevator, or when browsing on devices that require WiFi, such as iPads and tablets, when out and about.

There are many situations where an internet connection may not be feasible or may become unstable, and we are all tired of apps showing the unending progress indicator or shimmer boxes for data that will never be retrieved.

And it's not just folks with poor internet connection we're targeting. Offline support enables faster load times for users even when their internet connection is stable because there is no need to wait for network requests to resolve before rendering the data. We're talking about reducing wait time from seconds to rendering near-instantaneously.

How do we support local-first architecture?

Local-first applications work with a local database and sync data in the background with the Source of Truth, the remote database. By interacting with the local database, data is retrieved faster than relying on the network request, and it's always responsive. This makes state management easier, because everything is already on the device.

PowerSync enters the room...

So what's the hubbub? PowerSync—a drop-in sync layer for your existing Postgres and backend, enabling an offline-first architecture for real-time reactive apps with dynamic replication at scale. The goal is to solve the hard problems of keeping data in sync, then get out of the developer's way. While Postgres is the only supported backend database at the time of writing, support for MySQL and Microsoft SQL Server are on the roadmap.

PowerSync allows you to fully customize what data is synced to the client. Syncing the entire database is extremely simple, but it is just as easy to use sync rules to transform and filter data for each client using dynamic partial replication. Data is transformed and partitioned according to these sync rules.

You can develop custom rules for how you manage conflicts, but generally, PowerSync takes the approach of "last write wins". Changes are replicated from Postgres using Write-Ahead Logging (WAL), and are incrementally streamed from the source to each client.

At the time of writing, PowerSync supports on-device storage using SQLite because it's fast—it can perform tens of thousands of updates per second, even faster reads, with seamless support for concurrent reads.

Is PowerSync secure?

Data is always encrypted in transit using TLS—both between the client and PowerSync, and between PowerSync and the source database. The client-side database can be encrypted at rest using SQLCipher (available in the Flutter SDK).

End-to-end encryption: encrypted data can be synced, then encrypted and decrypted directly in memory by the client, or a separate local-only table can persist the decrypted data. The Enterprise plan can house data in managed, isolated tenants, and SOC 2 Type 2 audit results are available.

Supported SDKS and Integrations

Currently supported SDKs include Flutter, React Native, JS Web, and Kotlin Multiplatform, with Kotlin and Swift underway. Bonus integrations for Supabase, FlutterFlow, and Railway.

tldr;

People want their app to work seamlessly, and they want it now. Use PowerSync or steamroll your own solution with an on-device storage system that works with your tech stack—no one cares how you do it (probably), they just care that you do it.


Disclaimer

In case you were suspicious, I am not a PowerSync employee, nor am I paid by PowerSync to endorse them. I just enjoy their product, and I love offline-first architecture. If you want to learn more, please checkout their website and docs.

If you want to more about local-first but not specifically about PowerSync, I recommend Local-First Software.

0
Subscribe to my newsletter

Read articles from frankylee kelly directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

frankylee kelly
frankylee kelly