See the dramatic difference between synchronous and asynchronous processing
When a user registers on your platform, you typically need to:
Total time if synchronous: ~2500ms
The user must wait while staring at a loading spinner. If any external service fails, the entire registration fails!
Everything runs during the HTTP request
Expected Issues:
Tasks run in background workers
Expected Benefits:
Processing registration...
ID:
Name:
Email:
Created:
Note: These tasks are running in background queue workers. The user received an instant response and doesn't have to wait for these to complete!
// All tasks run during request
$user = User::create($data);
Mail::send($welcomeEmail); // 800ms
CRM::updateContact($user); // 1200ms
Analytics::track($event); // 300ms
// User waits ~2500ms total
// Only create user
$user = User::create($data); // 50ms
// Fire event (instant)
UserRegistered::dispatch($user);
// Response returns immediately!
// Queued listeners run in background
UserRegisteredShouldQueueUserRegistered::dispatch()php artisan queue:work