Building Web Apps with Laravel Module 10
Events, queues, scheduling and real time interview questions
Interview questions on events, queues, scheduling and real time: warm-ups, then what each harder question tests and how a good answer starts.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
An observer and a listener both react to events. How do they differ?
Answered in the lesson Events, listeners and model observers
-
Fresher to mid
How does a presence channel differ from a private channel?
Answered in the lesson Broadcasting and Reverb: real-time updates
-
Fresher to mid
What changes when QUEUE_CONNECTION is sync instead of database?
Answered in the lesson Queues and jobs: work after the response
-
Fresher to mid
Why is one cron entry enough for a Laravel application with many scheduled tasks?
Answered in the lesson Task scheduling, Artisan commands and processes
-
Fresher to mid
What does MAIL_MAILER=log do in a Laravel project, and when is it the right choice?
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to senior
PaymentReceived has three synchronous listeners, run in this order: add to the day's total in the cache, write a ledger row, tell the centre manager. About one payment in a hundred, the ledger listener throws. The event is dispatched inside the payment's transaction. What does the cashier see, what is left behind, and how would you restructure it?
- What it tests
- Following an exception through synchronous listeners and a transaction, telling database writes from effects outside it, and separating rules from reactions.
- First step
- Write down every step in the order the dispatcher runs it, and mark which writes belong to the database transaction. Then follow the exception from the ledger listener outwards until something catches it, and list what each earlier step has already done.
- Follow-ups
-
- What does the cashier do next, and what happens to the total if they try again?
- Where should the ledger row be written, and why there?
- How would a test prove that a failing ledger write leaves nothing behind?
From the lesson Events, listeners and model observers
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Mid to senior
Pathshala moves its queue from the database driver to Redis and changes nothing else. Within a day, some receipt jobs fail with ModelNotFoundException for payments that are in the database when you look a minute later. On the database driver this never happened. Explain why, and fix it.
- What it tests
- Knowing when a queued listener reaches the queue relative to the transaction, how the database driver differs from Redis there, and what a queued job does with a model it carries.
- First step
- Compare where the job is stored by each driver with where the payment row is written, and ask which of the two a worker can see first. Then read what the listener's job holds about the payment.
- Follow-ups
-
- Why did the database driver hide the bug?
- Which setting or interface fixes it, and at what level would you apply it?
- Should these jobs delete themselves when the model is missing?
From the lesson Events, listeners and model observers
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
A teacher publishes test marks for a class batch of 120 students. Pathshala must store the marks, recompute every student's rank in the batch, email each guardian their child's marks and refresh a cached leaderboard. Decide what goes in the action, in listeners and in jobs, and defend the design.
- What it tests
- Telling rules from reactions under volume, sizing slow work with numbers, choosing event granularity and keeping every reaction correct when the save fails.
- First step
- For each of the four pieces of work, ask two questions: are the marks wrong without it, and how long does it take for 120 students? Place each piece by the answers, then decide how many events one publication should dispatch.
- Follow-ups
-
- One event for the publication, or one per student?
- What happens to the emails if the save fails at student 73?
- Where do the marks' observers fit, if marks are stored with a bulk insert?
From the lesson Events, listeners and model observers
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A parent says their child, enrolled only at the Pune centre, saw doubts from an Andheri class batch appear live on the board. The channel tests in CI are green. How do you trace how this happened, and what do you change so it cannot happen again?
- What it tests
- Tracing a leak through channel names, callbacks, payloads and tests, and knowing which test set-ups prove nothing about authorisation.
- First step
- Write down every way a page can receive a message: the channel the event is sent on, the callback that guards it, and what the payload contains. Then ask which of those the green tests actually exercised, and against which broadcaster.
- Follow-ups
-
- Which channel names would you check first in the events?
- Why can a passing suite say nothing about this bug?
- What would you put in the payload, and what would you leave out?
From the lesson Broadcasting and Reverb: real-time updates
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
After every deploy, teachers say the doubt board stops updating until they reload the page, and doubts posted during the deploy never appear on boards that stayed open. Reverb and a queue worker run under a process supervisor. Explain the likely causes and what you change in the deploy and in the page.
- What it tests
- Understanding long-running processes in a deploy, what happens to messages while a page is disconnected, and designing a page that recovers its state.
- First step
- List the processes a deploy touches and what each holds in memory: the web workers, the queue worker and Reverb. Then follow one doubt posted mid-deploy from the request to the page, and mark every place it can wait or be lost.
- Follow-ups
-
- Why do restarts matter more for Reverb and the queue worker than for PHP-FPM?
- What should the page do when its connection comes back?
- How would you check the fix before the next deploy?
From the lesson Broadcasting and Reverb: real-time updates
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
Pathshala wants three live features: a fee status that changes once when the payment gateway calls back, a classroom quiz where 200 students answer and see the results move, and a notice ticker that changes a few times a day. Choose polling, server-sent events or WebSockets for each, and defend each choice with numbers.
- What it tests
- Matching delivery to how often data changes, which way it flows and how many pages wait, and costing the choice in requests, open connections and processes to run.
- First step
- For each feature, write how often the data changes, how many pages wait for it at once, and whether the page must send anything back. Turn those three facts into requests a minute, connections held and processes to run.
- Follow-ups
-
- What changes if the quiz grows to 2,000 students?
- Is one transport for all three features a reasonable choice?
- Where does each choice fail first under load?
From the lesson Broadcasting and Reverb: real-time updates
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
After a deploy, Pathshala's fee reminders stop going out. The jobs table grows to 12,000 rows, the worker process is up and its output is silent, and nothing reaches the failed jobs table. Before the deploy everything worked. What do you check, in what order, and what are the likely causes?
- What it tests
- Reading the jobs table to see where rows wait, knowing which queues and connection a worker takes, and knowing that a long-running worker keeps the code and settings it started with.
- First step
- Group the waiting rows by queue and by when they become available, and compare the queues with the list the running worker was started with. Then check whether that worker started before or after the deploy.
- Follow-ups
-
- Which change in the deploy could send new jobs to a queue that no worker takes?
- Why can a worker that was not restarted miss a change the deploy made?
- What alert would have caught this within minutes?
From the lesson Queues and jobs: work after the response
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
Pathshala must send 40,000 fee reminders between 09:00 and 10:00 on the first morning of each month. The SMS provider accepts at most 50 requests a second, each send takes about 300 ms, and the provider is sometimes down for ten minutes. Design the queue side: jobs, queues, workers, limits and outage handling.
- What it tests
- Sizing workers from throughput and latency, enforcing a provider's limit across workers, keeping one kind of work from starving the rest, and riding out an outage without losing or doubling reminders.
- First step
- Work out the rate you need (40,000 in an hour is about 11 a second) and how many sends one worker makes per second at 300 ms each. Then decide where the limit of 50 a second is enforced, since every worker must respect it.
- Follow-ups
-
- How many workers do you start, and what keeps them under the provider's limit?
- What do the jobs do during a ten-minute outage, and how do you avoid a burst when it ends?
- How do you make sure a guardian gets one reminder even if a job runs twice?
From the lesson Queues and jobs: work after the response
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Mid to senior
A monthly report job takes about two minutes for a large centre and has #[Tries(3)] and #[Timeout(300)]. On the database queue with a new project's settings, large centres get their report twice, and the second build starts while the first is still running. Nothing is logged as failed. Explain why, and fix it.
- What it tests
- Knowing what retry_after does on the database queue, how it must relate to a job's timeout, and how to protect a long job without changing the settings of every other job.
- First step
- Find the database connection's retry_after in config/queue.php and compare it with how long the job runs. Then ask what a worker sees in a reserved row once that many seconds have passed.
- Follow-ups
-
- Why is nothing logged as failed?
- Which settings do you change, and for which jobs?
- What still protects the report if the settings drift again?
From the lesson Queues and jobs: work after the response
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Mid to senior
A nightly job batch of 50 receipt jobs is dispatched with allowFailures. Two jobs fail on a mail timeout, and in the morning someone runs queue:retry-batch and both succeed. The accountant's summary, sent from the finally callback, arrived at night listing two failures and never arrived again. Explain what happened and redesign the summary.
- What it tests
- Knowing when then, catch, finally and the failure callback of a job batch run, what a retry changes in the job batch's counts, and where a once-only report belongs.
- First step
- Read the job batch's row in job_batches before and after the retry: total, pending and failed jobs. Then compare those counts with the condition the source uses for finally and the one it uses for then.
- Follow-ups
-
- What do the pending and failed counts show after the retry, and why?
- Where should a summary that must reflect the final state be sent from?
- When would you dispatch the receipts without allowFailures?
- How do you keep job_batches from growing without limit?
From the lesson Batches, chains, workers and Horizon
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to staff
Pathshala's workers run as systemd units with Restart=on-failure and queue:work --max-time=3600. After each deploy, which ends with queue:restart, the backlog grows during the day; by evening no worker runs, though no job failed. systemctl status shows the units inactive with status 0. What is wrong, and how do you fix and watch it?
- What it tests
- Knowing which worker stops end with exit status 0, how systemd's Restart= values treat a clean exit, and how to alert on missing workers rather than on failed jobs.
- First step
- List every way a worker can stop and the exit status each one leaves. Then read the unit's Restart= value against that list, one way of stopping at a time, and note which stops it would bring back.
- Follow-ups
-
- Why do the workers disappear even without a deploy?
- Which other settings of the unit must match the worker's timeout?
- What would you alert on, so that this is noticed within minutes?
From the lesson Batches, chains, workers and Horizon
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
After a move to Redis and Horizon, one supervisor works the queues otp and reports, in that order, with balance auto and maxProcesses 10. During the monthly report run, login codes for parents arrive two to four minutes late. Explain why, and change the Horizon configuration so that codes stay fast. How do you prove it worked?
- What it tests
- Knowing how Horizon's balancing assigns worker processes to queues, how to keep a time-critical queue fast during a long backlog, and how to measure queue wait times.
- First step
- Compare how many processes the supervisor gave each queue during the report run with the jobs waiting on each, and check what decides that assignment under balance auto and its autoScalingStrategy.
- Follow-ups
-
- Would a plain queue:work --queue=otp,reports worker have behaved differently?
- How do you size the workers for both queues, so that neither starves?
- Which settings must change together with a supervisor's timeout?
From the lesson Batches, chains, workers and Horizon
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
Pathshala moved its scheduler from one server to three. Since then the monthly fee report reaches the accountant three times. The task already has onOneServer(), and every server's .env sets CACHE_STORE=file. What is wrong, and what do you change?
- What it tests
- Knowing how the scheduler keeps one task from running on several servers, what that guard depends on, and how to prove a fix before the next run.
- First step
- Look at where the lock that onOneServer() takes is kept, and whether all three servers see the same lock when they start the scheduler in the same minute.
- Follow-ups
-
- Which stores can hold such a lock for several servers, and what must the servers share?
- How would you show, before next month, that only one server sends the report?
- What else goes wrong when each server has a cache store of its own?
From the lesson Task scheduling, Artisan commands and processes
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Mid to senior
Pathshala's attendance summary is scheduled with dailyAt('09:00') and reached teachers at 09:00 India time for a year. After a move to a new server it arrives at 14:30. Nobody changed routes/console.php. What happened, and how do you make the hour survive the next move?
- What it tests
- Knowing which clock a task's time follows, telling the server's clock, the application's timezone and a task's own timezone apart, and checking a schedule before it runs.
- First step
- Run php artisan schedule:list on the new server, with and without the India time option, and compare the hour with what teachers expect. Then compare config('app.timezone') on the old and the new deployment.
- Follow-ups
-
- Why not fix it by setting the application's timezone to Asia/Kolkata?
- What changes if a new centre in London wants a task at 01:30 London time?
- How could a deploy check catch the wrong hour before the teachers do?
From the lesson Task scheduling, Artisan commands and processes
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A deploy script runs php artisan pathshala:check-config and then the migrations, joined by &&. One evening the check printed in red that the mail sender address was empty, yet the migrations ran and the release went out. How do you make the check, and the script, trustworthy?
- What it tests
- Knowing that scripts read exit statuses rather than output, how a command reports failure, how a script stops on one, and how tests pin a command's status down.
- First step
- Run the check by hand and print its exit status straight after it. A red message with status 0 is a success to the shell, which is why && went on to the migrations.
- Follow-ups
-
- Which ways can a command end with a non-zero status, and which should a check use?
- How would a console test have caught this before the deploy?
- What else in a deploy script lets it carry on past a failure?
From the lesson Task scheduling, Artisan commands and processes
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
Under load, about one queued fee receipt in a hundred fails with a model-not-found error for its payment, yet the payment is in the database a second later. The controller saves the payment and queues the receipt on Redis inside one transaction. What is happening, and how do you fix it?
- What it tests
- Knowing when a queued job becomes visible to a worker compared with the commit of the data it needs, and which settings make a queue wait for that commit.
- First step
- Put two moments side by side: when the job reaches Redis and when the transaction commits. Then ask what a worker that takes the job between them can read from the database.
- Follow-ups
-
- What changes when the jobs table lives in the same database?
- What should happen to the receipt when the transaction rolls back instead of committing?
- How would you prove the fix before the next busy day?
From the lesson Mail and notifications
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Mid to senior
Pathshala's payment notification goes by SMS and mail. After the mail provider was down for ten minutes, 140 guardians got the same SMS two or three times but one email each. The notification is sent from a queued listener with three tries. Find the cause and the fix.
- What it tests
- Knowing what a retry repeats, how the channels of one notification are sent when the notification is not queued itself, and how to make a send safe to repeat.
- First step
- Write down what one attempt of the listener does, channel by channel, and what has already happened by the time the mail channel throws.
- Follow-ups
-
- What changes when the notification itself is queued?
- How can the SMS gateway or your own table stop a repeat from reaching the phone?
- Would sending mail before SMS fix it?
From the lesson Mail and notifications
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
Pathshala must send next term's fee notice to 40,000 guardians in one evening, each on the channels they chose, in their own language, and never twice. The SMS gateway accepts 50 messages a second. How would you design the send?
- What it tests
- Planning a large notification run: the jobs it creates, a rate limit for one channel, each recipient's language and choices, and a run that can be restarted safely.
- First step
- Estimate the messages per channel from the share of guardians who chose each one, and compare the SMS count with what the gateway accepts in one evening.
- Follow-ups
-
- How do you keep a guardian from getting the notice twice if the run is started again?
- What happens to a guardian who turns SMS off halfway through the run?
- What would you watch while the run is going?
From the lesson Mail and notifications
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
All Building Web Apps with Laravel interview questions · The Building Web Apps with Laravel track