AWS Builder Center

Building a Serverless Real-Time Notification System with AWS

A practical walkthrough of building a real-time notification system using API Gateway WebSockets, Lambda, and DynamoDB — no servers to manage, and it scales automatically with your users.

Sandip Ghorai | Cloud & AI Developer

The Problem

Most apps eventually need real-time updates — a chat message, an order status change, a live dashboard metric. The traditional approach (polling an API every few seconds) wastes bandwidth, adds latency, and doesn't scale well once you have thousands of concurrent users.

The Solution: WebSockets + Lambda + DynamoDB

Here's a serverless architecture that handles real-time notifications without managing a single server:

1. API Gateway WebSocket API

Instead of REST, use API Gateway's WebSocket support. It handles persistent connections for you and exposes three routes automatically:  $connect ,  $disconnect , and  $default .

2. Lambda for Connection Management

On  $connect , a Lambda function stores the connection ID in a DynamoDB table, keyed by user ID. On  $disconnect , it removes that record. This keeps track of who's currently online without any custom infrastructure.

3. DynamoDB as the Connection Store

A simple table with  userId  as the partition key and  connectionId  as an attribute is enough. Because DynamoDB scales automatically, this works whether you have 10 users or 10 million.

4. Broadcasting a Notification

When an event happens (say, a new order is placed), a Lambda function looks up the relevant  connectionId  from DynamoDB and calls the API Gateway Management API to push the message directly to that open WebSocket connection — no polling required.

Why This Approach Works

  • No servers to patch or scale manually — everything here is fully managed.
  • Pay-per-use pricing — you're billed for actual connections and messages, not idle compute.
  • Millisecond-level delivery — updates reach the client the moment they happen, not on the next poll cycle.

When to Use This Pattern

This works well for chat apps, live dashboards, order tracking, and collaborative tools. For very high-throughput streaming use cases (like live sports scores to millions of viewers), you'd want to layer in a fan-out service like SNS or EventBridge in front of this pattern.

Try It Yourself

Start with the AWS documentation for API Gateway WebSocket APIs, and pair it with a minimal DynamoDB table. You can have a working prototype running in under an hour.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article