Skip to content

Make the explanation of the Medusa event bus, Redis and BullMQ more explicit #14078

@mateomoreno

Description

@mateomoreno

What Medusa version and documentation are you using?

v2

Preliminary Checks

Issue Summary

Our Redis instance spiked using 3.82GB of memory with over 1.3M keys. Investigation showed that 1.29M keys (99%) are RedisEventBusService entries that have accumulated over the past 6 weeks with no cleanup. We thought this is because we had a scheduled job that ran daily at 3 AM, emitting vendor.pricing.update events for batch processing (~30,000 events/day). Without a retention policy, these events were not getting purged from Redis. We were under the impression all redis events had a ttl by default. However, upon understanding BullMQ and its relationship with Redis, we realized that BullMQ's default is removeOnComplete = true. But that doesn't actually mean events are deleted it just marks them as eligible to be deleted. Without {age, count} object, lazy cleanup never triggers.

How can this issue be resolved?

  1. We added this to our medusa-config.ts

{ resolve: '@medusajs/medusa/event-bus-redis', options: { redisUrl: process.env.REDIS_URL, jobOptions: { removeOnComplete: { age: 3600, // Remove completed jobs after 1 hour count: 1000, // Keep max 1000 completed jobs }, removeOnFail: { age: 86400, // Remove failed jobs after 24 hours count: 5000, // Keep max 5000 failed jobs }, }, }, },

Are you interested in working on this issue?

  • I would like to fix this issue

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions