Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

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.

23 questions: 5 warm-ups and 18 with model answers · Levels: Fresher to staff

Warm-up questions

Short questions with short answers, each answered in full.

  1. 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

  2. Fresher to mid

    How does a presence channel differ from a private channel?

    Answered in the lesson Broadcasting and Reverb: real-time updates

  3. Fresher to mid

    What changes when QUEUE_CONNECTION is sync instead of database?

    Answered in the lesson Queues and jobs: work after the response

  4. 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

  5. Fresher to mid

    What does MAIL_MAILER=log do in a Laravel project, and when is it the right choice?

    Answered in the lesson Mail and notifications

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. 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

    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.

    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
  2. 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

    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
  3. 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

    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
  4. 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

    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
  5. 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

    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
  6. 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

    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
  7. 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

    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
  8. 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

    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
  9. 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

    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
  10. 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

    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
  11. 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

    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
  12. 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

    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
  13. 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

    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
  14. 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

    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
  15. 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

    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
  16. 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

    From the lesson Mail and notifications

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 4 minutes
  17. 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

    From the lesson Mail and notifications

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  18. 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

    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

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.