System Architecture

Deep dive into Pushy's architecture and design decisions.

Architecture Overview

Pushy is built on a modern architecture designed for high performance, scalability, and reliability. Click on components below to explore details.

REST APISQLCacheQueueTemplatesPollSendUpdate
React FrontendNext.js 15 with TypeScript
Redis CacheTemplate caching
Contentful CMSTemplate management
PostgreSQLPrimary database
Rust APIHigh-performance Axum server
AWS SQSMessage queue
Background WorkerAsync notification processor
Email ServiceSMTP/SES delivery
Data Flow
Component
Selected
💡Drag components to rearrange the diagram.

Backend Architecture (Rust)

API Server (Axum)

The core API server is built with Axum, a modern async web framework for Rust that provides:

  • •High-performance async request handling with Tokio runtime
  • •Type-safe routing and middleware system
  • •Built-in support for WebSockets and SSE
  • •Graceful shutdown and connection draining
API Server Structure
// src/main.rs
use axum::{Router, routing::{get, post}};
use tower_http::trace::TraceLayer;
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/health", get(health_check))
.route("/users", post(create_user))
.route("/notifications", post(send_notification))
.layer(TraceLayer::new_for_http())
.with_state(app_state);
axum::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(app.into_make_service())
.await
.unwrap();
}

Background Worker

The worker processes notifications asynchronously, ensuring reliable delivery:

Worker Architecture
// src/notification_worker.rs
pub struct NotificationWorker {
sqs_client: SqsClient,
email_channel: EmailChannel,
push_channel: PushChannel,
db_pool: PgPool,
}
impl NotificationWorker {
pub async fn run(&self) -> Result<()> {
loop {
// Long poll SQS for messages
let messages = self.poll_messages().await?;
// Process in parallel batches
let futures: Vec<_> = messages
.into_iter()
.map(|msg| self.process_notification(msg))
.collect();
futures::future::join_all(futures).await;
}
}
}

Frontend Architecture (Next.js)

Application Structure

The frontend uses Next.js 15 with the App Router for optimal performance:

Core Technologies

  • •Next.js 15 with App Router
  • •TypeScript for type safety
  • •Tailwind CSS for styling
  • •Three.js for 3D graphics

Key Features

  • •Server-side rendering (SSR)
  • •Real-time notifications
  • •AI-powered chat interface
  • •Progressive Web App (PWA)

Database Design

PostgreSQL Schema

The database schema is optimized for high-throughput notification processing:

Core Tables
-- Users table
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
email VARCHAR(255) UNIQUE NOT NULL,
name VARCHAR(255),
push_subscription JSONB,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
-- Notifications table
CREATE TABLE notifications (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID REFERENCES users(id),
title VARCHAR(255) NOT NULL,
body TEXT NOT NULL,
notification_type VARCHAR(50),
channel VARCHAR(20) NOT NULL,
status VARCHAR(20) DEFAULT 'pending',
sent_at TIMESTAMPTZ,
error_message TEXT,
metadata JSONB,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Indexes for performance
CREATE INDEX idx_notifications_user_id ON notifications(user_id);
CREATE INDEX idx_notifications_status ON notifications(status);
CREATE INDEX idx_notifications_created_at ON notifications(created_at DESC);

Message Queue Architecture

AWS SQS Integration

SQS provides reliable, scalable message delivery:

Queue Configuration

  • • FIFO queue for order guarantee
  • • Message deduplication
  • • Dead letter queue for failures
  • • 14-day message retention

Processing Strategy

  • • Long polling (20 seconds)
  • • Batch processing (10 messages)
  • • Exponential backoff retry
  • • Parallel worker scaling
Queue Message Format
{
"messageId": "550e8400-e29b-41d4-a716-446655440000",
"receiptHandle": "AQEBwJnKyrHigUMZj6rYigCgxlaS...",
"body": {
"notificationId": "123e4567-e89b-12d3-a456-426614174000",
"userId": "098f6bcd-4621-3373-8ade-4e832627b4f6",
"channel": "email",
"templateId": "purchase_confirmed",
"variables": {
"userName": "Crypto Trader",
"amount": "0.5",
"currency": "BTC"
}
},
"attributes": {
"ApproximateReceiveCount": "1",
"SentTimestamp": "1705320000000"
}
}

Security Architecture

Security Measures

Authentication

  • ✓JWT token authentication
  • ✓VAPID keys for web push
  • ✓API key management
  • ✓Role-based access control

Data Protection

  • ✓TLS encryption in transit
  • ✓Encrypted database storage
  • ✓PII data masking
  • ✓GDPR compliance

Performance Characteristics

<5ms
API Response Time
10K/sec
Message Throughput
99.99%
Uptime SLA
Horizontal
Scaling Model