Full Stack Engineer Guide: Web Push Notifications (VAPID), Service Worker Caching Strategies & Offline Background Sync
Progressive Web Apps (PWAs) deliver native-grade mobile engagement without app store friction when engineered with clean Service Worker lifecycles and standard RFC 8292 VAPID Web Push notifications. As a Senior Full Stack Engineer, I have implemented Web Push and offline Service Worker caching across real-time chat platforms, transit schedulers (MRT Jakarta Schedule), and enterprise SaaS dashboards.
1. End-to-End VAPID Web Push Subscription Flow
- Generate ECDSA P-256 VAPID Keypair: Store the private key securely in backend Secret Manager and expose the URL-safe Base64 public key (`applicationServerKey`) to the frontend.
- Register Service Worker & Subscribe via `PushManager`: Convert the VAPID public key to a `Uint8Array` and call `registration.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey })` only after an explicit user gesture.
- Persist Subscription Endpoint & `p256dh`/`auth` Keys: Associate the browser push endpoint with the authenticated user in PostgreSQL and prune `410 Gone` subscriptions automatically when dispatching via `pywebpush`.
// TypeScript helper for converting URL-safe Base64 VAPID key to Uint8Array
export function urlBase64ToUint8Array(base64String: string): Uint8Array {
const padding = "=".repeat((4 - (base64String.length % 4)) % 4);
const base64 = (base64String + padding).replace(/-/g, "+").replace(/_/g, "/");
const rawData = window.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
}
return outputArray;
}
2. Related Full Stack Engineering Guides
- Hire a Senior Full Stack Engineer: React, Next.js 15, TypeScript & Offline-First PWAs Pillar Guide
- Full Stack Engineer Guide: Real-Time WebSockets, Optimistic UI & Offline IndexedDB Sync
⚡ Hire Aldian Fazrihady — Senior Cloud, GCP, Backend, AI Application & Full Stack Engineer
Need production cloud architecture, GCP/AWS infrastructure, high-throughput backend systems, AI agents, or full stack web engineering? Book a 1-Day Programming Sprint for $100 USD (International Card / Apple Pay) or Rp 1,000,000 (Indonesian QRIS / Bank Virtual Account), or hire directly on Upwork:
Book $100 / Rp 1M 1-Day Sprint → Hire on Upwork (100% Job Success) →