What is the Edge API Pattern?
The Edge API Pattern is an architectural approach designed to create simple, cost-effective APIs by running logic at the edge of AWS’s global network (Cloudfront).
It’s ideal for APIs that:
- 🧩 Don’t require complex business logic.
- 🌍 Need to be highly available.
- 💰 Should remain cost-effective, even at scale.
How It Works
- 🔹 CloudFront as the API Gateway: Acts as the entry point for API requests. Its global edge locations ensure high availability for users anywhere in the world.
- 🔹 Origin-request Lambdas: Handle the bulk of your API’s logic, executing when CloudFront forwards requests to the origin. No actual origin server is needed—the Lambda function generates responses directly.
- 🔹 Viewer-request Lambdas: Execute before CloudFront processes the request. Use them to:
- 🔑 Authenticate requests (e.g., validate a JWT token).
- 🛡️ Enforce authorisation rules (e.g., ensure the user has access to specific endpoints).
- ✅ Apply high-level validation (e.g., header validation).
Example Use Cases
- 💡 Static Data APIs: An origin-request Lambda can query an S3 bucket or DynamoDB table, format the data, and return it as JSON—without involving a full application backend.
- 💡 Personalised Responses: A viewer-request Lambda authenticates a user via a JWT, while an origin-request Lambda fetches and returns personalised data, such as a user’s recent transactions.
- 💡 A/B Testing APIs: Viewer-request Lambdas can assign users to test groups based on cookies or request headers, and origin-request Lambdas serve different content globally with minimal latency.
Why Use the Edge API Pattern?
- 💰 Cost-Effective: Pay only for the compute time and data transfer you use—no servers or containers to maintain.
- ⚡ Simplified Architecture: No need for API Gateway or traditional backend services unless required.
- 🌍 High Availability: Built on AWS’s global CloudFront network, ensuring resilience even during traffic spikes or regional failures.
At Blackstack, we specialise in designing scalable, efficient architectures that align with your business goals. If you’re looking to streamline your APIs with the Edge API Pattern, contact us below👇