Redis
How Tyk Uses Redis
Redis is central to Tyk’s operation. Its role differs depending on whether it is serving a Control Plane or a Data Plane. Control Plane Redis is shared between Tyk Dashboard and the Management Gateway. It stores:- Tyk Dashboard user sessions.
- API client Session data (the source of truth for the deployment).
- OAuth tokens issued by Tyk’s OAuth 2.0 authorization server.
- Tyk Certificate Store.
- Distributed locks, for example to ensure OAuth token purging runs on only one node at a time.
- The pub/sub channel used to push hot-reload notifications from Tyk Dashboard to connected Data Plane Gateways.
- Rate limiting counters.
- API response caching.
- Webhook deduplication, preventing duplicate events from firing within the configured timeout.
- Traffic logs buffered before Tyk Pump processes them.
- A local copy of API client Sessions and certificates, synced from the Control Plane.
- API definition and policy backups, providing resilience when the Control Plane is unavailable.
Protecting Redis Data
Tyk’s Redis usage differs between the Control Plane and Data Plane, and the consequences of losing each are different. Control Plane Redis stores API keys, session data, OAuth tokens, and certificates. This is the source of truth for your deployment and cannot be recovered from any other Tyk component. Deploy it with persistence enabled and a high-availability topology such as Redis Sentinel or Redis Cluster. If you are using Amazon ElastiCache, also configure read replicas and regular snapshots. Data Plane Redis stores rate limiting counters, cached responses, and analytics buffers, plus a local copy of keys, sessions, and API definitions synced from the Control Plane. If Data Plane Redis is lost, the impact is temporary: keys and sessions re-sync from the Control Plane on reconnection, and API definition backups rebuild on the next hot reload. High availability is still recommended to avoid disruption during a node failure, but Data Plane Redis is recoverable in a way that Control Plane Redis is not. For configuration details, see Configure Redis.Redis Sizing Guidelines
Redis memory requirements depend on what the instance is serving. Control Plane Redis memory is driven primarily by the number and size of API keys, API definitions, and security policies stored. Key size is typically small (around 1KB), but large key counts or large API definition payloads can add up quickly. Data Plane Redis memory is driven by traffic volume and feature usage. The main contributors are:- Traffic log buffering: traffic logs accumulate in Redis between purge intervals. Basic analytics records are typically around 2KB; detailed logging can reach 52KB per request. Logs are processed by Tyk Pump or, in distributed deployments, by Tyk MDCB.
- Response caching: cached API responses are held in Redis for the duration of their TTL. Memory usage depends on cache hit rate, TTL, and average payload size.
- API definitions and policies: a local copy is stored in Data Plane Redis for resilience.
Redis RAM Calculator
Use this calculator to estimate the RAM requirements for your Redis instance when using Tyk. This tool helps you plan your infrastructure by calculating memory needs based on your expected API traffic, caching requirements, and analytics storage. The calculator considers factors like requests per second, cache hit rates, number of API keys, and analytics settings. Results show the total RAM per host accounting for your specified utilization threshold.Managing Redis Memory
Capping Analytics
Tyk Gateways can generate a large volume of analytics data. Be sure to read about capping your Dashboard analytics.Compressing API Definitions and Policies
In distributed deployments, Data Plane Gateways store API definition and policy backups in Redis to ensure resilience when the Control Plane is unavailable. For deployments with many or large API definitions, this can consume significant Redis memory. You can reduce the size of these backups using optional Zstandard compression, which typically achieves around 75% reduction, though results vary depending on the size and complexity of your API definitions and policies. Set the following fields in your Data Plane Gateway configuration:storage.compress_api_definitionsis available from Tyk 5.12.0.storage.compress_policiesis available from Tyk 5.13.0.
storage.max_decompressed_size.
Separate Analytics Storage
By default, Tyk Gateway writes traffic logs to the same Redis instance used for rate limiting, session data, and other gateway operations. Under high traffic, this can place significant pressure on your primary Redis. You can offload traffic log buffering to a dedicated Redis instance by enabling a separate analytics store:analytics_storage block accepts the same fields as the main storage block. See Configure Redis for the full field reference.
Separate Cache Storage
API response caching can consume significant Redis memory, particularly for large payloads or high cache hit rates. You can isolate cache storage in a dedicated Redis instance, keeping it separate from session and rate limiting data:cache_storage block accepts the same fields as the main storage block. See Configure Redis for the full field reference.
MongoDB
Supported Versions
MongoDB is our default storage option. We support the following versions:- MongoDB 5.0.x, 6.0.x, 7.0.x (with
mongo-godriver).
mongo-go driver has been available since Tyk 5.0.2 and is the default from Tyk 5.3.0.
MongoDB 3.x to 4.4.xPrior to Tyk 5.0.2, Tyk used the
We can not guarantee full compatibility with these versions of MongoDB for Tyk and recommend upgrading to a supported MongoDB version. In particular, when using Tyk OAS APIs with Tyk 5.3.0 onwards, the minimum supported version of MongoDB is 5.0.
mgo driver which supported MongoDB 3.x to 4.4.x, but we no longer test MongoDB versions prior to 5.0 since they are EOL.We can not guarantee full compatibility with these versions of MongoDB for Tyk and recommend upgrading to a supported MongoDB version. In particular, when using Tyk OAS APIs with Tyk 5.3.0 onwards, the minimum supported version of MongoDB is 5.0.
- Amazon DocumentDB 3.6 and 4 engine
- Azure Cosmos DB for MongoDB 3.6 and 4 engine
Choose a MongoDB driver
From Tyk 5.0.2, we added an option to use the official MongoDB Go driver to connect to MongoDB. We recommend using the mongo-go driver if you are using MongoDB 4.4.x+. For MongoDB versions prior to 4.4, please use the mgo driver. With the mongo-go driver, we support the latest versions of MongoDB (5.0.x, v6.0.x, and v7.0.x) and also features such as the “+srv” connection string and SCRAM-SHA-256. For more details, visit the MongoDB doc: You can configure which driver to use with the MongoDB driver option: For recommended deployment topology, see Planning for Production. Special notes for DocumentDBIf you are using DocumentDB, capped collections are not supported. See here for more details.
MongoDB Sizing Guidelines
The aggregate record size depends on the number of APIs and Keys you have. Each counter size is ~50b, and every aggregated value has its own counter. So an hourly aggregate record is computed like this: 50 * active_apis + 50 * api_versions + 50 * active_api_keys + 50 * oauth_keys, etc. The average aggregate record size (created hourly) on our cloud is about ~ 40KB (a single record includes all the aggregate stats mentioned above). So for 1 million requests per day, it will generate 1KB * 1M request stats (1GB) + 24 * 40KB aggregate stats (~1MB). Per month: 30GB request logs + 30MB aggregate logs MongoDB Working Data Working data in terms of MongoDB is the data you query most often. The graphs displayed on the Tyk Dashboard, except for the Log browser, use aggregated data. So if you rely only on this kind of analytic data, you will not experience issues with working data and memory issues. It is literally hundreds of MBs. Even if you use the Log browser, its usage access is usually quite random, and it is unlikely that you check requests for every request. So it can’t be called working data. And it is ok to store it on disk and allow MongoDB to do the disk lookups to fetch the data. Note, that in order to do fast queries, even from the disk, MongoDB uses indexes. MongoDB recommends that indexes should fit into memory, and be considered working data, but only the part of the index which is commonly used. For example the last month of data. For an aggregate collection, the average index size is 6% of the overall collection. For requests stats, it is around 30%. MongoDB Sizing Example If you serve 1 million requests per day, and require fast access to the last seven days of request logs (usually way less, and the performance of the log viewer is not a concern), with 3 months of aggregated logs, the memory requirements for MongoDB can be as follows: Request_logs_index ( 30% * (1GB * 7) ) + aggregated(3month * 30MB) ~= 2.1GB + 90MB = ~ 2.2GB In addition to storing working data in memory, MongoDB also requires space for some internal data structures. In general, multiplying the resulting number by 2x should be enough. In the above example, your MongoDB server should have around 4.4GB of available memory. Audit Log storage From Tyk Dashboard v5.7+,the audit log can be configured to be stored in the database. If you choose to store the audit logs in the database, you need to account for additional storage for audit logs in the database setup. The size of this table will depend on the number of operations recorded, with each record averaging 1350 to 1450 bytes. Audit Log Considerations- Data Generation: The total size of the audit log table will depend on the number of API operations, administrative actions, and system events that are being logged.
- Daily Estimate: For example, logging 100,000 operations per day results in 135MB to 145MB of additional data daily.
- Storage Growth: Over time, this can significantly impact your storage requirements, especially in high-traffic environments or systems with comprehensive logging enabled.
- Implement Data Retention Policies: Define a clear retention period based on business and regulatory requirements, such as 30, 90, or 180 days. Remove older logs that exceed the retention policy to prevent excessive storage growth.
- Archive Older Logs: For long-term storage or compliance purposes, move older logs to external systems such as a data lake, object storage (e.g., S3), or a data warehouse.
- Monitor Growth Trends: Use monitoring tools to track the size and growth rate of the audit log table. Adjust retention policies or resources proactively based on observed trends.
- Plan for Resource Scaling: Audit log storage can significantly impact overall database size, especially in high-traffic environments. Plan for storage and resource scaling based on daily log growth estimates.
- Daily Logs: 100,000 operations/day
- Average Record Size: 1400 bytes
- Storage Growth: 100,000 × 1400 bytes/day = 140MB/day
Database Storage Calculator
Use this calculator to estimate the storage requirements for your database when using Tyk. This tool helps you plan your database infrastructure by calculating storage needs based on your API traffic, analytics retention, and configuration data. The calculator considers factors like requests per second, analytics time-to-live, and the number of APIs and policies you manage. Results show the total storage requirement accounting for your specified utilization threshold.PostgreSQL
How you configure your PostgreSQL installation depends on whether you are installing Tyk from fresh using PostgreSQL, or are migrating from an existing MongoDB instance. Supported Versions From Tyk 4.0, you can use PostgreSQL as your datastore. We support the following versions:- PostgreSQL version 13.x, 14.x, 15.x, 16.x, 17.x
- Amazon RDS
- Amazon Aurora PostgreSQL
-
Azure CosmosDB for PostgreSQL
In a production environment, we only support the PostgreSQL versions listed above.
- SQLite 3.x
Migrating from an existing MongoDB instance
For v4.0 we have provided a migration command that will help you migrate all data from the main storage layer (APIs, Policies, Users, UserGroups, Webhooks, Certificates, Portal Settings, Portal Catalogs, Portal Pages, Portal CSS, etc.).The migration tool will not migrate any Logs, Analytics, or Uptime analytics data.
- Make sure your new SQL platform and the existing MongoDB instance are both running
- Configure the
mainpart of thestoragesection of yourtyk-analytics.conf:
- Run the following command:
Migrating 'tyk_apis' collection. Records found: 7.
- You can now remove your
mongo_url(orTYK_DB_MONGOURLenvironment variable) from yourtyk-analytics.conf - Restart your Tyk Dashboard