Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thomasb's avatar
Level 18

Queueing in a multi-tenancy application

Hi Everyone.

At the company I work for we are building out a multi-tenancy application but we have stumbled on a bit of a tough issue.

Currently the env is loaded when the site is requested. It checks the (domain) url and returns the correct environment variables for that domain. Now the problem we have is that we are using the queue for time-consuming tasks, but since our env is loaded per domain, the queue isn't using the correct database when running because it does not know about which domain it is on.

Does anyone have experienced this problem before? Any solutions or ideas ?

Thanks in advance!

0 likes
5 replies
usama.ashraf's avatar

I suggest using a single storage for all your queues. If that's feasible, use a common Redis instance to work your queues. As far as distribution is concerned, if need be, Redis has good clustering support.

thomasb's avatar
Level 18

We need different databases per client because it's pretty sensitive data that should be separated from each other. (hospitals, etc..) How could I go about using a single storage for queueing, can u explain it a bit more?

Thanks already for answering tho! ;)

usama.ashraf's avatar
Level 7

Configure all your domains with the same Redis instance but different queue names.

Once you run the listener/worker/supervisor it'll be listening on the Redis port (default: 6379). You can use different queues by prepending the domain names to a common term, like: domain-1-redis-queue, domain-2-redis-queue, domain-3-redis-queue etc.

This way all your domains will have their own 'pipes' to push jobs through, so to speak.

thomasb's avatar
Level 18

Ok, thanks man! Going to try it out.

usama.ashraf's avatar

Or you could launch multiple workers with different databases configured, one per domain, which is really not that fun.

Please or to participate in this conversation.