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.

Ruby on Rails Module 15

Rails internals and extending Rails interview questions

Interview questions on rails internals and extending Rails: warm-ups, then what each harder question tests and how a good answer starts.

11 questions: 3 warm-ups and 8 with model answers · Levels: Fresher to staff

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher to mid

    What does the Rails executor do around a request, and when do you call it yourself?

    Answered in the lesson Rack middleware, the executor and threads

  2. Fresher to mid

    What is the difference between nil?, blank? and present? in Rails?

    Answered in the lesson Active Support: extensions and notifications

  3. Fresher to mid

    What does isolate_namespace change in an engine, and what breaks without it?

    Answered in the lesson Engines, generators and application templates

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

    Kaksha's new middleware adds x-kaksha-bytes, the body's size, whenever the body responds to to_ary. The header appears on every HTML page but never on the attendance export, which streams its CSV row by row. A teammate proposes calling body.to_a first so that the header is always set. Diagnose the gap and say what to do instead.

    What it tests
    Whether the candidate knows the Rack 3 body contract (each, to_ary, close), why a middleware must not buffer a streamed body, and how to report a size that is known only at the end.
    First step
    Compare the two kinds of body. A Rails view response is complete in memory and responds to to_ary, so its size is known before the headers go out. The export is an Enumerator that builds rows while the server sends them, so no layer can know its size before the last row. Then work out what body.to_a would cost: the whole export in memory before the first byte leaves.
    Follow-ups

    From the lesson Rack middleware, the executor and threads

    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

    Under Puma, teachers at one Kaksha centre now and then see another centre's batch list. The batch query is scoped by Centre.current, a class method that memoises the signed-in teacher's centre in @current. Debug the leak, fix it, and say how you would prove the fix with a test that fails before it and passes after.

    What it tests
    Whether the candidate sees that state on a class is shared by every Puma thread, moves per-request data into Current or an argument, knows the executor clears Current, and can force the failing order in a test.
    First step
    Notice that @current on a class is one value for the whole process: the first request fills it and every later request, on any thread, reads it, so the leak needs no unlucky timing. Then move the centre into a Current attribute set from the signed-in teacher in a before_action, or pass it to the query as an argument.
    Follow-ups

    From the lesson Rack middleware, the executor and threads

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 4 minutes
  3. Mid to senior

    After deploying a new monitoring subscriber, the p99 latency of every controller action doubled. The subscriber logs event names to an external service. Explain how you would diagnose this, what the likely cause is, and how you would fix it without removing the monitoring.

    What it tests
    Understanding that subscribers run synchronously, diagnosing with timing, and moving slow work out of the subscriber callback.
    First step
    Check whether the subscriber blocks the request thread. Wrap the subscriber body in a timing call and log the duration. If each event adds tens of milliseconds and an action fires many events, the latency increase is explained. Subscribers run inside instrument, so slow work delays the response.
    Follow-ups

    From the lesson Active Support: extensions and notifications

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  4. Mid to senior

    A multi-tenant application sets the current tenant in ApplicationController and reads it in models using a class variable @@current_tenant. One customer reports seeing another customer's data. What caused this, and how would you fix the models without changing the controller?

    What it tests
    Recognising shared mutable class state, thread-safety of class variables, and using class_attribute or Current attributes for per-request data.
    First step
    Class variables are shared across all threads. When two requests run at once, one thread overwrites the tenant the other set. The fix is to store the tenant in a place that is per-request, such as ActiveSupport::CurrentAttributes, not in a class variable.
    Follow-ups

    From the lesson Active Support: extensions and notifications

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  5. Senior to staff

    You need to add instrumentation to a fee calculation service so that tests can assert which fee rules were applied and integration tests can measure timing. Design the event naming, payload structure, and show how a test would subscribe, trigger a calculation, and verify the payload.

    What it tests
    Naming events with action.namespace, including testable data in the payload, subscribing in setup, unsubscribing in teardown, and asserting on captured events.
    First step
    Name the event following Rails convention: calculate.fees or apply_rule.fees. The payload should include the student id, the rule that matched, and the calculated amount. In a test, subscribe before the action, capture events in an array, and assert on the payload after the call.
    Follow-ups

    From the lesson Active Support: extensions and notifications

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  6. Mid to staff

    A fees slice of one Rails app is owned by three people, ships in the app's deploy, and a second app will need it next quarter. It also calls two concerns from app/models/concerns. Choose a mountable engine, a packwerk package or a separate service, defend the choice, and say what you would do in the first week.

    What it tests
    Whether the candidate decides from reuse, release schedule and ownership rather than tidiness, and can sequence the work so the boundary is enforced before the second app arrives.
    First step
    Separate the requirements that only one option satisfies. A second app loading the code rules out a package; no independent release and three maintainers rule out a service. That leaves an engine, but an engine is a poor first step while the slice still calls two shared concerns, so say what you would do before the gemspec exists.
    Follow-ups

    From the lesson Engines, generators and application templates

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 5 minutes
  7. Mid to senior

    A deploy stops with "table feature_flags_flags already exists" after the feature_flags engine was upgraded and bin/rails feature_flags:install:migrations was run. The table holds live rows. Diagnose the cause from what the app's db/migrate folder and schema_migrations table would show, fix it without losing data, and prevent it.

    What it tests
    Whether the candidate reads db:migrate:status and the engine's copied files, knows that install:migrations decides by the class names in db/migrate, and repairs migration history instead of dropping or editing a live table.
    First step
    Run bin/rails db:migrate:status and list db/migrate. Look for an engine copy with the .feature_flags suffix that is down while an older version is up with NO FILE: the task copied again a migration the app had deleted. Its first line names the original version, so confirm it matches the one that created the table.
    Follow-ups

    From the lesson Engines, generators and application templates

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 5 minutes
  8. Mid to senior

    Design an application template for twelve Rails apps that must also be applied again every quarter as the team's defaults change. Say which Thor actions are safe to repeat and which need a guard, how the template reports what it changed, and how you would test it before it touches twelve apps.

    What it tests
    Whether the candidate knows which Thor actions repeat safely, guards the ones that do not on a stable marker, and can test a template without a repository of live apps.
    First step
    Sort the actions into three groups. Whole-file actions compare content and write nothing on a second run; insertions such as route and insert_into_file skip only their own exact text; gem, generate and run act every time. Say which of your defaults fall in each group, then pick the guard for each of the last two.
    Follow-ups

    From the lesson Engines, generators and application templates

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 5 minutes

All Ruby on Rails interview questions · The Ruby on Rails 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.