Web push service

Introduction#

Web Push via VAPID: subscribe, unsubscribe, send, and clean up dead endpoints. How payloads differ from Telegram and where subscriptions live in MongoDB.

Project structure#

The Web Push Service is organized within the application’s modular architecture, following service-oriented design principles :

Core components#

The Web Push Service consists of several interconnected components that work together to provide reliable browser notification delivery:

WebPushService class#

The primary service class that implements the INotificationChannel protocol, handling all aspects of web push notification delivery including VAPID authentication, subscription management, and payload formatting.

VAPID authentication system#

Implements Voluntary Application Server Identification for secure push notification delivery, requiring cryptographic keys and contact email for authentication with push providers.

Subscription management#

Manages user subscriptions through the database service, storing subscription endpoints and cryptographic keys associated with each user’s browser installations.

Notification delivery pipeline#

Processes notification requests through a structured pipeline that formats payloads, applies VAPID signatures, and handles delivery failures with automatic cleanup of invalid subscriptions.

Architecture overview#

The Web Push Service operates within a detailed notification architecture that supports multiple delivery channels:

The architecture ensures smooth integration between web browsers and the notification system, with automatic handling of subscription lifecycle management and delivery failures.

Detailed component analysis#

VAPID encryption implementation#

The Web Push Service implements VAPID (Voluntary Application Server Identification) encryption for secure notification delivery:

The VAPID implementation includes:

  • Private Key Management: Cryptographic key for signing push requests
  • Public Key Distribution: Shared with web clients for subscription verification
  • Claims Generation: Creation of authentication claims with contact email
  • Signature Validation: Verification of push provider authentication

Browser subscription management#

The service manages browser subscriptions through a structured lifecycle:

Subscription management includes:

  • Registration: Storing subscription endpoints and cryptographic keys
  • Validation: Periodic verification of subscription validity
  • Cleanup: Automatic removal of expired or invalid subscriptions
  • Persistence: Database storage of subscription data linked to user profiles

Push notification delivery mechanisms#

The notification delivery pipeline follows a standardized process:

Integration with multi-channel notification ecosystem#

The Web Push Service integrates with the broader notification ecosystem:

Dependency analysis#

The Web Push Service relies on several key dependencies for secure and reliable operation:

Dependency graph for the production path:

  • pywebpush: Web Push protocol
  • py-vapid: VAPID signatures
  • cryptography: crypto primitives
  • http-ece: payload encryption
  • FastAPI/uvicorn: HTTP API

Performance considerations#

Performance notes:

Asynchronous processing#

  • Non-blocking: webhook server uses FastAPI async handlers
  • Connection pooling via PyMongo
  • Batch sends where parallel is safe

Resource management#

  • Lazy-load optional deps so missing VAPID libs do not crash import
  • Truncate payloads; stream when it helps
  • Reuse DB connections for the process lifetime

Scalability features#

  • Keep running without VAPID keys (push just no-ops)
  • One bad subscription does not fail the batch
  • Drop 404/410 subscriptions so the list stays short

Troubleshooting guide#

Common VAPID configuration issues#

Problem: Web push notifications not working despite proper setup Solution: Verify VAPID key configuration and provider compatibility

Problem: Subscription registration failing with HTTP 501 Solution: Check VAPID key availability and service initialization

Problem: Delivery failures with 404/410 responses Solution: Automatic cleanup removes invalid subscriptions; verify subscription validity

Subscription management issues#

Problem: Subscriptions not persisting in database Solution: Verify database connectivity and user ID mapping

Problem: Duplicate subscriptions accumulating Solution: Implement subscription deduplication logic in database service

Performance issues#

Problem: Slow notification delivery Solution: Monitor database query performance and optimize subscription retrieval

Problem: Memory leaks during high-volume delivery Solution: Implement proper resource cleanup and connection pooling

Conclusion#

Web Push Service: VAPID, subscribe/unsubscribe, send, prune dead endpoints. Same SOA shape as the Telegram path, different transport.