Skip to content

🐛 Bug Report: Usage queue backlog evicts the cache from Redis #14084

Open

Description

@JoshiJoshiJoshi

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

  1. 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.

  2. 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 in v1-stats-usage.

  3. 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-lru evicts 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:

  1. 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 use maxmemory-policy noeviction, so a full Redis rejects new jobs instead of silently dropping old ones.
  2. Use volatile-lru for the cache instance together with TTLs on cache keys, so non-expiring keys are never evicted.
  3. Reduce the payload of usage jobs: aggregate per worker before enqueueing, or drop fields that are not used for the metric.
  4. Make the v1-stats-usage backlog visible, e.g. in the health endpoints, as is done for other queues.

Since when / regression?

  • --maxmemory 512mb --maxmemory-policy allkeys-lru for 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

  • noeviction on 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-lru only 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-lru would behave like noeviction.
  • 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):

🎲 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?

Activity

  1. added
    product / auth
    product / databases
    product / locale
    product / messaging
    product / self-hosted
    product / storage
    product / vcs
    sdk / cli
    on Oct 3, 2026
  2. changed the title [-]🐛 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[/+] on Oct 4, 2026
  3. JoshiJoshiJoshi commented on Oct 14, 2026

    @JoshiJoshiJoshi
    Author

    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.0 docker-compose.yml has the same settings):

    • The trigger was our own test procedure: we had raised maxmemory to 3 GB with CONFIG SET only, 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 above maxmemory (for example through the backlog described here, or a lowered limit) will.
    • At the restart Redis loaded a 1.5 GB RDB file with 2 271 213 keys into the 512 MB limit. During the load allkeys-lru evicted 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.
    • The failed lists themselves survived (for example 5 398 entries in failed.v1-stats-usage), but their payloads did not: only 3 of the 5 398 usage payloads were still there, so queue-retry can no longer requeue them.
    • Afterwards evicted_keys read 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:

  4. removed
    product / storage
    product / databases
    product / auth
    product / messaging
    product / vcs
    product / locale
    sdk / cli
    on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    product / self-hosted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions