Building Real-Time GraphQL APIs with AWS AppSync - Subscriptions and Resolver Design

This article introduces design patterns that deliver real-time notifications with WebSocket-based subscriptions and integrate multiple data sources with DynamoDB / Lambda pipeline resolvers.

Choosing Between AppSync and REST APIs

AppSync is the AWS managed GraphQL service, which processes up to thousands of requests per second and supports up to 100,000 concurrent connections over WebSocket. With REST APIs, you need to call multiple endpoints and assemble the data you need, but with GraphQL, you can retrieve only the fields you need with a single query. It is well suited to environments with limited bandwidth, such as mobile apps, and to dashboards that retrieve data across multiple data sources. On the other hand, for simple CRUD or public APIs for third parties, a REST configuration with API Gateway + Lambda is simpler. AppSync is well suited to applications that need real-time updates, complex data retrieval patterns, and situations where frontend teams want flexibility in the API.

Real-Time Subscriptions

AppSync subscriptions run over WebSocket and push data to clients, triggered by the execution of a Mutation. You set up real-time notifications by defining a Subscription type in the schema and specifying the target Mutation with the @aws_subscribe directive. In a chat application, when a new message Mutation is executed, the message is delivered to all clients subscribed to the same chat room. With subscription filtering, clients can receive only the data changes that are relevant to them. AppSync manages connections automatically, so you do not need to operate WebSocket servers.

Resolver Design and Data Source Integration

A resolver is a component that connects a GraphQL field to a data source. DynamoDB resolvers use mapping templates written in VTL (Velocity Template Language) or JavaScript to run DynamoDB operations such as GetItem, PutItem, Query, and Scan. Pipeline resolvers run multiple functions in sequence and can pass the result of the previous function to the next function. For example, a configuration is possible in which the first function retrieves user information from DynamoDB and the next function retrieves that user's order history from a separate table. One way to divide the roles is to use Lambda resolvers for processing that involves complex business logic or calls to external APIs, and DynamoDB resolvers for simple CRUD.

AppSync Pricing

AppSync pricing consists of the number of query / mutation executions and real-time updates. Queries and mutations cost approximately $4.00 per million requests, and real-time updates (subscriptions) cost approximately $2.00 per million updates, with charges for connection time and data transfer added on top (as of August 2026). Enabling caching adds hourly charges for the cache instance (approximately $0.028/hour for t2.small), but because it can reduce the number of calls to DynamoDB and Lambda, the total cost may go down for read-heavy workloads. When you compare costs with a REST configuration using API Gateway + Lambda, look at the number of backend calls reduced by solving the N+1 problem in addition to the per-request price.

Schema Design Basics

Designing a GraphQL API starts with defining the schema. The schema declares the types of data you handle and the operations that clients can run, and it becomes the API specification itself. You define queries that retrieve data, mutations that make changes, and subscriptions that receive changes in real time. By designing the schema carefully first, client and server developers can work in parallel based on a shared specification. Being able to retrieve exactly the data you use, no more and no less, is a characteristic of GraphQL, and schema design is the prerequisite for it.

Resolver Types and Design

A resolver links an operation defined in the schema to processing against an actual data source. For simple processing against a single data source, you use a unit resolver. When you call multiple data sources in order or combine processing, you use a pipeline resolver that chains multiple steps. This allows you to integrate multiple related pieces of data and return them in a single request. Some data sources also have mechanisms that integrate directly from resolvers, which lets you omit extra code. You choose the resolver configuration according to the complexity of the operation.

Authentication / Authorization Modes

AppSync supports multiple authentication methods, and you can choose one according to the purpose of the API. They include methods that integrate with the user authentication platform, methods that use the AWS permissions system, methods based on a simple key, and methods that plug in your own authentication logic. In addition, you can control authorization at the field level, which enables fine-grained control such as exposing specific data only to specific user groups. You can also combine multiple authentication methods and use each for a different purpose. You decide who can access which data at the API design stage.

Offline Support and Conflict Resolution

For applications used in environments with unstable networks, such as mobile apps, you include offline behavior in the design. AppSync provides a mechanism that lets you work with data locally while offline and synchronizes it with the server when the connection is restored. At that point, if multiple users have changed the same data, the changes may conflict. By designing in advance how to resolve conflicts, such as which change takes priority, you can maintain data consistency. You build in offline support and conflict resolution to make the application usable when network conditions are unstable.

Summary

AppSync is a GraphQL service well suited to applications that need real-time updates and flexible data retrieval. It delivers real-time notifications with WebSocket-based subscriptions and integrates multiple data sources such as DynamoDB, Lambda, and RDS with pipeline resolvers. It also provides fine-grained access control through multiple authentication modes as a managed feature.

References (Official AWS Resources)

The primary sources for this page are the official AWS website and documentation. Check the official pages below for the latest specifications and pricing.

If this page and the official documentation disagree, treat the official documentation as authoritative.

Share