GraphQL

Build Cost Effective Asynchronous GraphQL APIs Using Serverless

476views

At apidays New York, I had the opportunity to share insights from my work and research on a topic that’s close to my day-to-day engineering practice: building cost-effective asynchronous GraphQL APIs using serverless technologies. As a senior engineer with a deep focus on cloud computing, much of my work revolves around exploring the potential of serverless and event-driven architectures. Over time, I’ve seen how these paradigms can fundamentally reshape how we design APIs—particularly in environments where responsiveness, cost optimization, and workload decoupling are top priorities.

Whether you’re designing a car sales platform with multiple data sources or any other complex system requiring real-time data aggregation, this guide provides a comprehensive walkthrough of evolving from traditional monolithic architectures to modern serverless, event-driven GraphQL APIs. Along the way, you’ll gain practical understanding of the benefits, architectural patterns, and implementation nuances that make this approach a game-changer for developers and businesses alike.


Understanding the Challenge: Traditional Architectures and Their Limitations

Imagine a car sales website, similar to Carvana, that provides detailed information about cars, including vehicle specifics, pricing, user reviews, inspection reports, and Carfax history. This data often comes from multiple APIs — sometimes fifteen to twenty different sources — each providing pieces of the overall picture. Aggregating this information synchronously to present a single consolidated view to users can introduce significant latency.

In a traditional monolithic architecture or even in microservices without proper decoupling, the system has to wait for all these API calls to complete before responding to the user. This synchronous processing leads to:

  • High latency: User requests take longer to fulfill as the system waits for multiple external and internal services.
  • Performance bottlenecks: Complex searches across large inventories slow down operations.
  • Infrastructure cost spikes: To handle peak loads or traffic spikes, especially during sales or promotions, additional server capacity must be provisioned, increasing expenses.

For example, during a morning rush or a special deal event, sudden traffic spikes can overwhelm the backend. This overload not only impacts server costs but also degrades user experience as pages load slowly or time out.

 

The Evolution of API Architectures: From Monoliths to Shared Services

Over the past decade and a half, API architectures have evolved significantly to address these challenges:

  1. Monolithic architectures: Large codebases hosting all functionalities on-premise or on dedicated servers. These systems were hard to scale and maintain.
  2. Service-Oriented Architectures (SOA): APIs were split into services with universal components shared across products, improving modularity.
  3. Microservices: Further decomposition of services into smaller, independently deployable units focused on specific business logic.
  4. Shared Services on Microservices: Combining microservices with shared infrastructure components like logging, authentication, and event brokers to improve code reuse and standardization.

This progression reflects a growing need for flexibility, scalability, and maintainability. However, even with microservices, synchronous communication patterns can cause bottlenecks and tightly coupled dependencies.


Why Asynchronous Event-Driven Architectures Matter

In today’s world, asynchronous communication is becoming the norm rather than the exception. Instead of waiting idly for a process to complete, systems can continue executing other tasks and react to events as they happen. This approach mirrors real-world processes, such as:

  • Dropping off your iPhone for repair and receiving a notification when it’s ready, instead of waiting at the store.
  • Ordering food and engaging in other activities until you get an alert that your order is ready.
  • Sending clothes for dry cleaning and picking them up once notified.

Just as these everyday experiences do not require synchronous waiting, digital systems benefit from adopting event-driven, asynchronous architectures. This shift offers several advantages:

  • Decoupling: Components operate independently, reducing dependencies and improving fault tolerance.
  • Improved responsiveness: Users receive data faster because the system does not block on slow operations.
  • Cost efficiency: Resources are used optimally, avoiding over-provisioning during idle or low-traffic periods.
  • Scalability: Systems can handle traffic spikes gracefully by processing events asynchronously.

Moving from a synchronous thread-spawning model to an event-driven one drastically reduces CPU load and infrastructure expenses while enhancing user experience.


Leveraging Serverless and GraphQL in Asynchronous Architectures

Serverless computing platforms, such as AWS Lambda, paired with APIs like GraphQL, are ideal for building asynchronous, event-driven systems. Here’s how these technologies fit into the architecture:

  • AWS Lambda: Executes code in response to events without managing servers, scaling automatically with demand.
  • API Gateway: Serves as the entry point for client requests, routing them to Lambda functions.
  • GraphQL: Provides flexible data querying capabilities, allowing clients to request exactly the data they need, no more, no less.
  • Amazon SQS (Simple Queue Service): Acts as an event broker, decoupling producers and consumers by queuing events for asynchronous processing.
  • Amazon DynamoDB and OpenSearch: Store and index data for fast retrieval, supporting different query patterns.

In this setup, Lambda functions listen to SQS queues for new events and update the data stores accordingly. The GraphQL API then queries these data stores to serve client requests efficiently, avoiding costly real-time API calls whenever possible.


How GraphQL Enhances Data Fetching

GraphQL’s ability to specify precise data requirements reduces over-fetching and under-fetching issues common with REST APIs. For example, a client may request only the vehicle details and price, skipping reviews or inspection reports if they are not needed immediately.

By limiting the data returned, GraphQL reduces latency and bandwidth usage, contributing to a more responsive user interface.


Asynchronous Data Updates with SQS

Real-time APIs can be slow or unreliable, so this architecture avoids making synchronous calls during user requests. Instead, background workers consume API update events from SQS queues, process the data, and update DynamoDB or OpenSearch indexes asynchronously.

This approach ensures that the data presented to users is as current as possible without forcing them to wait for slow API responses.


Detailed Architecture Overview 

Let’s step through the data flow in this asynchronous, serverless architecture:

 

1. User Request: A user requests car details via a web or mobile app.

2. API Gateway: The request hits the API Gateway, which routes it to the GraphQL Lambda endpoint.

3. GraphQL Resolver: The Lambda function authenticates the user, interprets the GraphQL query, and determines which data is needed.

4. Data Retrieval: The resolver queries DynamoDB or OpenSearch to fetch the requested data. These are optimized for quick lookups by primary key (VIN) or by search criteria like make and model.

5. Fallback Real-Time API Call: If data is missing or stale, the system can fall back to calling the slower real-time APIs directly, though this is rare (less than 0.01% of cases).

6. Response to User: The data is returned to the client promptly.

7. Asynchronous Updates: Meanwhile, background Lambda workers listen to SQS events from real-time APIs, process new data, and update DynamoDB and OpenSearch to keep the cache fresh.

 

Choosing Between DynamoDB and OpenSearch

Both DynamoDB and OpenSearch play complementary roles in this architecture:

  • DynamoDB: A cost-effective NoSQL database ideal for fast lookups using primary keys such as Vehicle Identification Numbers (VINs).
  • OpenSearch: A powerful search and analytics engine suited for complex queries filtering by attributes like make, model, or price, but comes with higher costs.

For example, if a user searches for all Toyota cars available, OpenSearch excels at filtering and aggregating results quickly. But if the query is for a specific VIN, DynamoDB provides rapid direct access.

Implementing the GraphQL Resolver and Event Listener

The GraphQL resolver is the critical component that translates client queries into database operations. It understands user intent and fetches relevant data from the backend stores efficiently.

On the backend, SQS event listeners continuously monitor for new data updates. When an event arrives, the listener Lambda function processes it and updates DynamoDB or OpenSearch. This ensures the data remains up-to-date without impacting user-facing query performance.

For example, when a payment status update for a car is received, the event listener updates the corresponding record in DynamoDB. Subsequent queries to the GraphQL API will then reflect the latest payment status without delay.

Benefits Realized: Cost Reduction and Performance Gains

Transitioning from a Scala-based monolithic architecture with high CPU-intensive EC2 instances to a serverless, event-driven architecture yielded significant benefits:

  • Cost Reduction: Infrastructure costs dropped by approximately 70%. Serverless Lambda functions run only when needed, avoiding wasteful always-on server expenses.
  • Improved Performance: Asynchronous processing and optimized data stores deliver faster responses, enhancing user experience.
  • Scalability: The system gracefully handles traffic spikes without requiring manual capacity planning.
  • Operational Simplicity: Reduced need for managing servers and complex threading models.

In the previous Scala microservices setup, synchronous thread spawning and heavy EC2 instances led to high operational overhead and cost. The new architecture’s event-driven serverless model eliminates these inefficiencies.

Conclusion: Why Asynchronous Serverless GraphQL APIs Are the Future

Building cost-effective asynchronous GraphQL APIs using serverless technologies and event-driven architectures represents a paradigm shift in how scalable digital platforms are designed. By decoupling heavy workloads, leveraging flexible data querying, and processing updates asynchronously, organizations can deliver superior user experiences while dramatically reducing infrastructure costs.

The example of a car sales platform highlights how this approach can be applied to real-world systems that depend on aggregating data from multiple, often slow, APIs. The result is a resilient, responsive, and economical backend that adapts to modern requirements.

As businesses continue to demand faster, more scalable, and cost-efficient APIs, adopting serverless event-driven architectures with GraphQL will be increasingly essential for developers and architects.

Thank you, and I hope this comprehensive overview inspires you to explore and implement asynchronous GraphQL APIs using serverless technologies in your own projects.

Balaji Thadagam Kandavel

Balaji Thadagam Kandavel

Senior Engineer & Researcher at Cox Automotive
I'm a Senior Cloud Solutions and Software Engineer with 17+ years of experience in AI and cloud transformation, particularly in retail. At Cox Automotive, I design scalable, serverless systems that power millions of users. I'm passionate about building cloud-native platforms that blend intelligence, efficiency, and real-world business impact.

APIdays | Events | News | Intelligence

Attend APIdays conferences

The Worlds leading API Conferences:

Singapore, Zurich, Helsinki, Amsterdam, San Francisco, Sydney, Barcelona, London, Paris.

Get the API Landscape

The essential 1,000+ companies

Get the API Landscape
Industry Reports

Download our free reports

The State Of Api Documentation: 2017 Edition
  • State of API Documentation
  • The State of Banking APIs
  • GraphQL: all your queries answered
  • APIE Serverless Architecture