logo
podcast Podcast
get help Get Unstuck

Sync queue works differently than async

Another time I learned the hard way

Joel Clermont
Joel Clermont
2024-08-06

It is tempting to simplify your local development environment compared to what you use in production.

For example, in production you might have Horizon set up with Redis for your queues, but locally you might think it's "just as good" to use the simpler sync driver.

This way you don't need to have Redis configured, you don't need to run a queue worker, or worry about restarting your queue worker as you change code.

But this convenience can lead to bugs that you don't catch until they are in production.

I got burned by this. The sync queue config doesn't serialize your models when they are queued. Without the serialization step, you can detect which specific attributes were changed on the model.

My queued job was relying on this behavior, and the tests passed, but obviously once this shipped to production and the models were serialized, it no longer had "dirty" changes to detect. Oops!

It was a dumb mistake for sure, but it was initially missed because the environment was different.

Lesson learned! Every time my local environment is different from production, it eventually bites me.

Here to help,

Joel

P.S. Have you seen our free book on Laravel security?

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.