Design every step so it is safe to kill and resume.
if retries < 5 { backoff(attempt) }
Security, metrics and testing reels
Security, metrics and testing1 / 3
1 / 4
Tokens in the background
Background jobs must authenticate without the user. Keep short-lived access tokens and a refresh token in Keystore or Keychain, readable after first unlock. If refresh fails, pause sync and ask the user to sign in when they next open the app.
2 / 4
Data at rest
Encrypt the local database for regulated data, wipe it on logout and keep files inside the app sandbox. Presigned URLs should expire within minutes and allow exactly one object and one method.
3 / 4
Trust nothing from clients
The server re-checks authorisation on every pull, validates every payload, verifies file hashes on completion and scans uploads. Deletion requests reach every device through tombstones.
Interview answer
Say it in the interview
Background auth uses short-lived tokens with a refresh token in Keystore or Keychain, readable after first unlock. Encrypt regulated data at rest, and wipe it on logout. Presigned URLs expire in minutes, and the server re-checks authorisation and verifies hashes on every request.
1 / 4
Tokens in the background
Background jobs must authenticate without the user. Keep short-lived access tokens and a refresh token in Keystore or Keychain, readable after first unlock. If refresh fails, pause sync and ask the user to sign in when they next open the app.
2 / 4
Data at rest
Encrypt the local database for regulated data, wipe it on logout and keep files inside the app sandbox. Presigned URLs should expire within minutes and allow exactly one object and one method.
3 / 4
Trust nothing from clients
The server re-checks authorisation on every pull, validates every payload, verifies file hashes on completion and scans uploads. Deletion requests reach every device through tombstones.
Interview answer
Say it in the interview
Background auth uses short-lived tokens with a refresh token in Keystore or Keychain, readable after first unlock. Encrypt regulated data at rest, and wipe it on logout. Presigned URLs expire in minutes, and the server re-checks authorisation and verifies hashes on every request.
Security for offline data
#security
❚❚
Security, metrics and testing2 / 3
1 / 4
It fails quietly
A broken sync system rarely crashes. Data simply stops arriving, and users notice days later. You need numbers that move before users complain.
2 / 4
Metrics
Track freshness, the time since each device last synced, at p50 and p95. Track outbox depth, upload completion rate, conflict rate and background-task expirations, split by app version, platform and manufacturer.
3 / 4
Acting on them
Alert when a release moves those numbers, gate staged rollouts on sync success, trace requests from device to database with OpenTelemetry, and keep a remote kill switch for every sync path.
Interview answer
Say it in the interview
Our sync SLOs are p95 freshness and zero acknowledged writes lost. Dashboards show outbox depth, upload completion, conflict rate and background-task expirations by app version and manufacturer, and staged rollouts are gated on sync success.
1 / 4
It fails quietly
A broken sync system rarely crashes. Data simply stops arriving, and users notice days later. You need numbers that move before users complain.
2 / 4
Metrics
Track freshness, the time since each device last synced, at p50 and p95. Track outbox depth, upload completion rate, conflict rate and background-task expirations, split by app version, platform and manufacturer.
3 / 4
Acting on them
Alert when a release moves those numbers, gate staged rollouts on sync success, trace requests from device to database with OpenTelemetry, and keep a remote kill switch for every sync path.
Interview answer
Say it in the interview
Our sync SLOs are p95 freshness and zero acknowledged writes lost. Dashboards show outbox depth, upload completion, conflict rate and background-task expirations by app version and manufacturer, and staged rollouts are gated on sync success.
Knowing your sync is healthy
#observability
❚❚
Security, metrics and testing3 / 3
1 / 4
Make the engine pure
Write the sync engine as a function of database state and server responses. Every conflict, error and retry branch can then be tested deterministically, without a device.
2 / 4
Break it on purpose
On real phones, kill the app mid-upload, toggle airplane mode, switch between Wi-Fi and mobile data, reboot, fill the disk, change the clock and revoke the token. Every case should end with no lost data and no duplicates.
3 / 4
Test the OS and the scale
Force Doze and standby buckets with adb, simulate background launches in Xcode, test on aggressive OEM phones, and seed a million rows on a low-end device to measure first sync and scrolling.
Interview answer
Say it in the interview
The sync engine is a pure function of database state and server responses, so every branch has deterministic tests. On devices we run kill, airplane-mode, reboot, low-disk and clock-skew drills, force Doze, and seed a million rows on a low-end phone.
1 / 4
Make the engine pure
Write the sync engine as a function of database state and server responses. Every conflict, error and retry branch can then be tested deterministically, without a device.
2 / 4
Break it on purpose
On real phones, kill the app mid-upload, toggle airplane mode, switch between Wi-Fi and mobile data, reboot, fill the disk, change the clock and revoke the token. Every case should end with no lost data and no duplicates.
3 / 4
Test the OS and the scale
Force Doze and standby buckets with adb, simulate background launches in Xcode, test on aggressive OEM phones, and seed a million rows on a low-end device to measure first sync and scrolling.
Interview answer
Say it in the interview
The sync engine is a pure function of database state and server responses, so every branch has deterministic tests. On devices we run kill, airplane-mode, reboot, low-disk and clock-skew drills, force Doze, and seed a million rows on a low-end phone.