Black Friday: the Laravel testing course is $149 instead of $249, through Dec 7. See the course →
logo

Sync queue works differently than async

Another time I learned the hard way

Joel Clermont
Joel Clermont
2024-08-06

From our daily Laravel tips email. Get the next one in your inbox.

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?

Want a tip like this in your inbox every weekday?

Each one takes less than 2 minutes to read. Join 4,000+ Laravel developers who already get them.

email
No spam. Only real-world advice.
Toss a coin in the jar if you found this helpful.