LLD INTERVIEW WORKFLOW / OBJECT DESIGN BRIEF

Model key interactions

Step 5: walk the most important use cases through your objects, in order, as a sequence of method calls.

IntermediatePhase 10 / Topic 5 of 8ResponsibilitiesCollaborationsExtensibility
01

Overview

Step 5: walk the most important use cases through your objects, in order, as a sequence of method calls. This validates the class diagram: every call must be a method on the receiving class, data must come from its owner, and failure branches must have a clear handler.

In an interview, narrating 'the user calls BookingService.hold, which asks Show.hold, which checks each ShowSeat...' with a quick sequence sketch shows the design works end to end. It often reveals missing methods, misplaced responsibilities, and concurrency gaps before you write the full code.

A dress rehearsal

Actors run through the play in order with props. Any missing prop or unclear cue shows up now, not on opening night.

02

When to use it

  • After the class diagram, before or while coding.
  • When the interviewer asks 'walk me through booking a ticket'.
  • Debugging a design with unclear flows.
03

Where it shows up in interviews

End-to-end walkthrough

Recognize it when: 'what happens when a user...?'

  • Design a movie ticket system
  • Design an ATM
  • Design an elevator system
04

Where it is used in real software

Sequence diagrams in design docs

Key flows are documented as sequence diagrams for review.

Distributed tracing

Production traces show the actual call sequence and timings.

Integration tests

Tests often mirror the walkthrough of the main flows.

05

Key terms

Happy path
The main successful flow.
Failure branch
Alternative flow when a step fails.
Compensation
Undo earlier steps after a failure (release hold).
Atomic step
Must happen without interference (hold seats).
06

How it works, step by step

  1. 1
    Pick 1-2 key use cases

    Book seats; cancel booking.

  2. 2
    Write the call sequence

    Caller -> method -> callee.

  3. 3
    Mark atomic sections

    Hold must be all-or-nothing and synchronized.

  4. 4
    Add failure branches

    Seat taken, payment failed, hold expired.

  5. 5
    Fix design gaps

    Add missing methods or move responsibilities.

Book seats walkthrough
Step 1 / 4
User
BookingService
Show
Pricing
Payment
Booking

STEP 1holdSeats(user, show, [A5, A6]) -> Show.hold() atomically marks both seats held with expiry.

07

Gaps found during the walkthrough

Reviewing the book-seats flow

Step 1 / 4
GapFix
Two holds could raceShow.hold synchronized; all-or-nothing
No release on payment failureAdd Show.release in the failure branch
Price computed in controllerMove to PricingStrategy
Hold expiry never checkedHold.isExpired checked in confirm; background sweeper

NOWGap: Two holds could race | Fix: Show.hold synchronized; all-or-nothing

Each gap became a small, targeted design change.

08

Implementation

public Booking book(String userId, String showId, List<String> seatIds) {    Show show = shows.get(showId);                                   // 1. load aggregate    Hold hold = show.hold(seatIds, userId, clock.instant().plus(HOLD_TTL)); // 2. atomic hold (synchronized in Show)    Money total = pricing.total(show, seatIds);                      // 3. pricing strategy    boolean paid;    try {        paid = payments.charge(userId, total);                       // 4. external call outside any lock    } catch (RuntimeException e) {        show.release(hold);                                          // failure branch: compensate        throw e;    }    if (!paid) { show.release(hold); throw new PaymentDeclinedException(); }    show.confirm(hold, clock.instant());                             // 5. fails if hold expired    Booking booking = new Booking(ids.next(), showId, userId, seatIds, total);    bookings.save(booking);                                          // 6. persist    notifier.bookingConfirmed(booking);                              // 7. side effect last    return booking;}
09

Complexity and performance

Walkthroughs1-2 flows

Main + one failure.

Time~5 minutes

High value.

10

Trade-offs

Detail vs time

Narrate the main flow with key branches; skip trivial getters.

Diagram vs code

Sketch sequence arrows or write the orchestrating method directly; both validate the design.

11

Variants and related techniques

Sequence diagram

Formal notation of the same walkthrough.

Test-first walkthrough

Write the use case as a test, then implement.

12

Common mistakes

  • Holding locks during payment calls.

    Fix: Lock only for state changes; call external systems outside.

  • No compensation on failure.

    Fix: Release holds and reverse steps explicitly.

13

Interview questions

Walk me through booking a seat.

The service loads the show, which atomically holds the seats with an expiry; pricing computes the total; the payment gateway charges outside any lock; on failure the hold is released; on success the show confirms the hold (if not expired), a booking is saved, and a notification is sent.

Why do side effects like notifications come last?

So they only happen after the core state change succeeds; sending a confirmation for a booking that later fails would mislead the user.

14

Practice problems

ProblemDifficultyWhat it trains
Walk through an ATM withdrawalEasyFailure branches.
Walk through an elevator hall callMediumDispatcher and car.