Black Friday sale: an extra 40% off every course until Monday, November 30.New Year sale: an extra 30% off every course until Friday, January 1.Memorial Day sale: an extra 25% off every course until Monday, May 31.SysAdmin Day sale: an extra 25% off every course until Sunday, August 1.Back to School sale: an extra 25% off every course until Sunday, August 22.Labor Day sale: an extra 25% off every course until Monday, September 6.Black Friday sale: an extra 40% off every course until Monday, November 29.New Year sale: an extra 30% off every course until Saturday, January 1.Choose your certification →

Copyright (c) 2026 MindMesh Academy. All rights reserved. This content is proprietary and may not be reproduced or distributed without permission.

2.1.1.10. Real-Time APIs and Edge Compute (API Gateway WebSocket APIs, CloudFront Functions, Lambda at Edge)

2.1.1.10. Real-Time APIs and Edge Compute (API Gateway WebSocket APIs, CloudFront Functions, Lambda at Edge)

💡 First Principle: Real-time features need the server to push data the moment it changes, which requires a persistent connection rather than client polling; edge features should run in the cheapest runtime that can do the job, as close to the viewer as possible.

WebSocket APIs in "Amazon API Gateway":
  • A client opens one persistent, two-way connection. Routes decide which integration receives each message: $connect (authorize here with a Lambda authorizer or IAM, and record the connection), $disconnect, $default, and custom routes picked by a route selection expression such as $request.body.action.
  • Every connection has a connection ID. Backends push to a client by calling the @connections API (POST to https://{api-id}.execute-api.{region}.amazonaws.com/{stage}/@connections/{connection_id}), and can also read connection details or force a disconnect with DELETE.
  • Publish-subscribe fan-out: store connection IDs with their topics in "DynamoDB" on $connect; when an event arrives (from EventBridge, SNS or a DynamoDB stream), a Lambda function looks up the subscribers and posts to each one. A GoneException (HTTP 410) means the client is gone, so delete that ID. $disconnect is best-effort (the connection is already closed), so do not rely on it alone for cleanup.
  • Quotas that shape the design: a connection is closed after 10 minutes idle or 2 hours in total, and neither is adjustable, so clients send heartbeats and reconnect. Messages are up to 128 KB (sent in frames of up to 32 KB). New connections default to 500 per second per account and Region.
  • Alternatives: "AWS AppSync" GraphQL subscriptions and AppSync Events provide managed pub/sub over WebSockets without tracking connection IDs yourself; "AWS IoT Core" serves MQTT for device fleets. REST polling is the anti-pattern these replace.
CloudFront Functions vs. Lambda@Edge:
"CloudFront Functions""Lambda@Edge"
RuntimeJavaScriptNode.js and Python
EventsViewer request, viewer responseViewer request/response and origin request/response
Scale and durationMillions of requests per second, sub-millisecondUp to 10,000 requests per second per Region, seconds
Network, file system, request bodyNoYes
Data storeCloudFront KeyValueStoreAny service it can call
  • CloudFront Functions fit lightweight work on every request: cache-key normalization, header changes (security headers, True-Client-IP), URL redirects and rewrites, and validating a signed token such as a JWT. KeyValueStore holds lookup data such as redirect maps.
  • Lambda@Edge fits work that needs libraries, more memory, a network call to another service, the request body, or the origin events. An origin-request function runs only on cache misses, so expensive lookups there are paid far less often than on viewer events.
  • One distribution can use both on different event types, for example a CloudFront Function on viewer request for redirects and a Lambda@Edge function on origin request to call a personalization service.

⚠️ Exam Trap: Picking Lambda@Edge for simple header or URL manipulation at very high request rates (more latency and cost for no gain), or picking CloudFront Functions for logic that must call an external API or read the request body, which it cannot do.

See how it connects
Alvin Varughese
Written byAlvin Varughese
Founder•26 professional certifications earned