Repository navigation
Description
In short: Appwrite keeps the cache and all job queues in one Redis with a 512 MB limit that throws out the least recently used keys when full. A backlog in the usage-statistics queue fills Redis and pushes the cache out, and in the worst case could throw out queued jobs.
Impact:
- After our write tests, the usage queue used 391 of 512 MB, the cache hit rate dropped to 67 % and 7.2 M keys had been evicted.
- Fewer cache hits mean more database load exactly when the system is busiest.
- Evicted queue entries would mean silently lost jobs.
👟 Reproduction steps
-
Run Appwrite 2.3.0 with the official
docker-compose.yml. Redis is started with--maxmemory 512mb --maxmemory-policy allkeys-lru(docker-compose.yml#L1913-L1919) and serves both the document cache and all queues. -
Keep usage stats enabled (
_APP_USAGE_STATS=enabled, default) and generate write load with single-row creates, e.g. 1,000–1,300 rows/s for a few minutes. Each request enqueues one job inv1-stats-usage. -
Watch Redis:
docker exec appwrite-redis redis-cli info memory | grep used_memory_human docker exec appwrite-redis redis-cli llen utopia-queue.queue.v1-stats-usage docker exec appwrite-redis redis-cli info stats | grep -E 'evicted_keys|keyspace_(hits|misses)'
👍 Expected behavior
- Queue jobs are never evicted.
- A backlog in one queue does not push the document cache out of memory.
👎 Actual Behavior
After our write tests:
| Metric | Value |
|---|---|
used_memory |
396 MB of 512 MB |
utopia-queue.queue.v1-stats-usage |
391 MB, 150,396 jobs, ≈ 2.1 KB each |
evicted_keys since start |
7,191,753 |
Cache hit rate (keyspace_hits / (hits+misses)) |
67 % |
The usage worker drained about 1,000 jobs/s. Single-row writes enqueue faster than that, so the backlog grows for as long as the load lasts. About 240,000 pending jobs fill Redis completely. At that point:
allkeys-lruevicts cached documents (projects, tables, rows), so more requests go to the database exactly when it is busiest;- with
allkeys-lru, any key is eligible, including queue lists, reservations and claims. An evicted queue list loses every job in it.
Each job carries the full request context (path, method, user agent, IP, hostname, country, project, resource), which is why it is 2 KB.
Suggestions:
- Allow queues and cache on separate Redis instances, and document it for production. In 2.3.0, cache, queue publisher, pub/sub, locks and abuse all use one DSN built from
_APP_REDIS_HOST/_APP_REDIS_PORT(registers.php#L52, #L102-L135). There is no setting to split them. The queue instance should usemaxmemory-policy noeviction, so a full Redis rejects new jobs instead of silently dropping old ones. - Use
volatile-lrufor the cache instance together with TTLs on cache keys, so non-expiring keys are never evicted. - Reduce the payload of usage jobs: aggregate per worker before enqueueing, or drop fields that are not used for the metric.
- Make the
v1-stats-usagebacklog visible, e.g. in the health endpoints, as is done for other queues.
Since when / regression?
--maxmemory 512mb --maxmemory-policy allkeys-lrufor the shared Redis has been in the official compose file since 1.0.0.- The risk grew with the usage pipeline (
v1-stats-usage, one job of about 2 KB per request). It is not a code regression.
Risks / things to consider for the fix
noevictionon the shared instance would make cache writes fail once it is full, so requests would start failing. It only makes sense for a separate queue instance.volatile-lruonly evicts keys with a TTL. In our instance only 22 of 2,378 keys had one, so the document cache does not set TTLs. Without TTLs on cache keys,volatile-lruwould behave likenoeviction.- Splitting cache and queue into separate Redis instances needs new configuration variables and an upgrade path for existing installs.
Related issues from the same analysis (Appwrite 2.3.0 with Postgres, same test setup):
- 🐛 Bug Report: Two uncached team queries on every API request #14077 – every request runs two uncached queries for the project team
- 🐛 Bug Report: Postgres insert reads back
_idwith an extra query #14078 –_idread back after every insert instead ofINSERT … RETURNING - 🐛 Bug Report: Postgres adapter sets and resets
statement_timeoutaround every query #14079 –SET/RESET statement_timeoutaround every query - 🐛 Bug Report: Postgres adapter sends
ROLLBACKbefore everyBEGIN#14080 –ROLLBACKbefore everyBEGIN, Postgres log flood - 🐛 Bug Report: Postgres: fulltext search never uses an index #14081 – fulltext indexes on Postgres are plain B-trees,
searchcannot use them - 🐛 Bug Report:
total=falseon list endpoints is ignored #14082 –total=falseon list endpoints is ignored - 🐛 Bug Report: Pool adapter checks out a connection for every capability getter #14083 – pool adapter checks out a connection for constant capability getters
- 🐛 Bug Report: PostgreSQL adapter never uses the
_uidindex – every create, get and update by row ID scans the whole table #14075 – Postgres adapter never uses the_uidindex (collation)
🎲 Appwrite version
Version 2.3.0 (self-hosted)
💻 Operating system
Linux (Debian 12, Docker 29.8)
🧱 Your Environment
Self-hosted Appwrite 2.3.0, Redis 7.4.7 from the official compose file, usage worker with _APP_WORKERS_NUM=1 and the default coroutine settings. Related test setup: #14075.
👀 Have you spent some time to check if this issue has been raised before?
- I checked and didn't find similar issue
🏢 Have you read the Code of Conduct?
- I have read the Code of Conduct
Activity
[-]🐛 Bug Report: Usage queue backlog fills the shared Redis (`maxmemory 512mb`, `allkeys-lru`) and evicts the document cache – queues can be evicted too[/-][+]🐛 Bug Report: Usage queue backlog evicts the cache from Redis[/+]JoshiJoshiJoshi commentedon Oct 14, 2026
A restart case we hit while testing, in case it helps with the topic of this issue: Redis can silently evict most of its data while it loads its own dump.
What happened (Appwrite 2.4.0, compose Redis 7.4.7 with
--maxmemory 512mb --maxmemory-policy allkeys-lru, the 2.5.0docker-compose.ymlhas the same settings):maxmemoryto 3 GB withCONFIG SETonly, not in the compose file, ran several Redis stop/start tests with queue backlogs, and restarted Redis once more before the 3 GB were set again. So this is not something an untouched install hits by itself, but any install whose dataset has grown abovemaxmemory(for example through the backlog described here, or a lowered limit) will.allkeys-lruevicted keys: within about two minutes only 292 472 keys were left, i.e. ≈ 1.98 million (87 %) were gone. That included cache entries, abuse counters and the payloads of queued and failed jobs.failed.v1-stats-usage), but their payloads did not: only 3 of the 5 398 usage payloads were still there, soqueue-retrycan no longer requeue them.evicted_keysread 0 (the counter is reset by the restart) and Redis logged no warning. From the outside the restart looked clean.So the risk in this issue is not limited to a growing backlog at runtime: with this policy and limit, a restart (update, host reboot, OOM) can drop queue data without any visible sign.
What helps today:
--maxmemory(and a size that fits the dataset) into your compose file, not onlyCONFIG SET; a restart returns to the compose value.allkeys-lruinstance: a separate Redis withnoevictionfor the queues (PR fix(queue): allow queues on a separate Redis via _APP_REDIS_QUEUE_* #14112 adds_APP_REDIS_QUEUE_*for that), the cache on its own instance.used_memoryclose tomaxmemoryand onevicted_keys, and checkredis-cli info keyspaceafter every restart. The usage queue cap proposed in fix(usage): cap the usage queue so a backlog cannot evict the Redis cache #14193 reduces how large the dataset can grow, but does not change what a restart does when it is already too large.