What is Session Storage?
When a user installs or accesses your Shopify app, the OAuth flow generates a session containing:- Access tokens for making API requests
- Shop information
- User details (for online sessions)
- Token expiration times
- OAuth state information
The SessionStorage Interface
All session storage implementations in the SDK implement theSessionStorage interface, which defines five core methods:
Key Methods
Creates or updates a session in storage. Returns
true on success.Retrieves a session by its ID. Returns
undefined if not found.Deletes a single session from storage.
Deletes multiple sessions in a single operation.
Finds all sessions associated with a specific shop.
Available Adapters
The SDK provides official adapters for various database systems:PostgreSQL
Production-ready relational database
MySQL
Popular relational database
Redis
High-performance in-memory store
MongoDB
Flexible document database
DynamoDB
AWS serverless database
SQLite
Lightweight file-based database
Drizzle
Type-safe ORM for SQL databases
Prisma
Modern database toolkit
Cloudflare KV
Edge-compatible key-value store
Memory
In-memory storage for development
Choosing an Adapter
Consider these factors when selecting a session storage adapter:Production Apps
For production environments, choose a persistent database:- PostgreSQL or MySQL - Best for traditional server deployments
- Redis - Excellent for high-traffic apps requiring fast access
- MongoDB - Good for flexible schema requirements
- DynamoDB - Ideal for AWS serverless architectures
- Prisma/Drizzle - When using these ORMs in your stack
Serverless/Edge Deployments
- Cloudflare KV - Perfect for Cloudflare Workers
- DynamoDB - Great for AWS Lambda
- Redis - Works well with serverless when using managed services
Development & Testing
- Memory - Quick setup, no configuration needed
- SQLite - Simple file-based storage for local development
Session Data Structure
Sessions store the following information:Database Schema Requirements
Most adapters automatically create the necessary tables/collections, but you should understand the schema:Relational Databases (PostgreSQL, MySQL, SQLite)
The default table structure includes:- Primary key on
id - Indexed
shopcolumn for efficient lookups - All session fields as columns
- Automatic migrations handled by the SDK
Document Databases (MongoDB)
Stores sessions as documents with the session ID as the primary key.Key-Value Stores (Redis, KV)
Uses the session ID as the key and serialized JSON as the value.Migration Support
Relational database adapters include built-in migration support:- Automatic schema creation on first run
- Migration tracking to prevent duplicate migrations
- Backwards-compatible schema updates
The SDK handles migrations automatically. You don’t need to run migration commands manually.
Security Considerations
Next Steps
SessionStorage Interface
Detailed interface documentation
Database Adapters
Setup guides for each adapter