Low-Level Design Tutorial 0/42 lessons ~6 min read Lesson 41

    LLD Design Exercise

    This design exercise walks through a timed LLD session for an online auction system — bidders, items, bids, timers, and winner notification.

    Course progress0%
    Focus
    9 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    This design exercise walks through a timed LLD session for an online auction system — bidders, items, bids, timers, and winner notification. Work through it as mock interview practice after completing prior modules.

    Set a forty-five minute timer. Pause after each phase to compare your output with the reference approach below. Focus on process, not memorizing this exact domain.

    Auctions combine concurrency (last-second bids), state (item lifecycle), and observer (outbid alerts).

    Understanding the topic

    Key concepts

    • AuctionItem: start price, end time, current high bid.
    • Bid: bidder, amount, timestamp.
    • BidValidator: min increment, auction open check.
    • AuctionService: placeBid, closeAuction.
    • Notifier: outbid and win messages.
    • Concurrent last-moment bids need synchronized accept.
    text
    sequenceDiagram
    Client->>ParkingLot: park(vehicle)
    ParkingLot->>SpotFinder: findAvailable(type)
    SpotFinder-->>ParkingLot: spot
    ParkingLot->>Ticket: issue()

    Step-by-step explanation

    1. Phase 1 (5 min): actors — seller, bidder, system; reqs — bid, auto-close, notify.
    2. Phase 2 (10 min): classes AuctionItem, Bid, AuctionHouse, BidService, Notifier.
    3. Phase 3 (10 min): sequence for placeBid validating and updating high bid.
    4. Phase 4 (10 min): extension — proxy bidding max amount.
    5. Phase 5 (10 min): trade-offs — single JVM lock vs distributed lock at scale.
    6. Review: SOLID, patterns used, missing edge cases.

    Informative example

    Reference solution core — synchronized bid acceptance:

    java
    public final class AuctionItem {
    private final String id;
    private final Money startPrice;
    private final Instant endsAt;
    private Bid highBid;
    public AuctionItem(String id, Money startPrice, Instant endsAt) {
    this.id = id;
    this.startPrice = startPrice;
    this.endsAt = endsAt;
    }
    public synchronized Optional<Bid> placeBid(Bid candidate) {
    if (Instant.now().isAfter(endsAt)) return Optional.empty();
    Money min = highBid == null ? startPrice : highBid.amount().add(Money.of(1));
    if (candidate.amount().compareTo(min) < 0) return Optional.empty();
    Bid previous = highBid;
    highBid = candidate;
    return Optional.ofNullable(previous);
    }
    public synchronized Optional<Bid> winner() {
    return Instant.now().isAfter(endsAt) ? Optional.ofNullable(highBid) : Optional.empty();
    }
    }
    public record Bid(String bidderId, Money amount, Instant at) {}
    public final class AuctionService {
    private final Map<String, AuctionItem> items = new ConcurrentHashMap<>();
    private final Notifier notifier;
    public AuctionService(Notifier notifier) { this.notifier = notifier; }
    public boolean bid(String itemId, Bid bid) {
    AuctionItem item = items.get(itemId);
    Optional<Bid> outbid = item.placeBid(bid);
    outbid.ifPresent(b -> notifier.send(b.bidderId(), "Outbid on " + itemId));
    return outbid.isPresent() || item != null;
    }
    }

    Self-practice: redraw diagram without looking; add ProxyBidder class for extension phase.

    Real-world use

    Real-world applications

    • Capstone mock before real interviews.
    • Team internal design dojo sessions.
    • Comparing student designs with reference model.

    Best practices

    • Time each phase strictly during practice.
    • Record yourself explaining aloud.
    • After session, note one SOLID win and one gap.
    • Repeat weekly with different problem if auction easy.
    • Peer review diagrams for coupling smells.

    Common mistakes

    • Skipping timer — unrealistic pacing.
    • Reading solution before attempting full pass.
    • No extension phase practice.
    • Ignoring notify outbid requirement in reqs.

    Advanced interview questions

    Q1BeginnerWhy auction as exercise?
    Combines concurrency, validation, time bounds, and notifications — common interview themes.
    Q2BeginnerCore auction classes?
    AuctionItem, Bid, AuctionService, Notifier, optional ProxyBidder.
    Q3IntermediateHandle sniping bids at deadline?
    Soft close: extend end time if bid within last minute — state rule on item.
    Q4IntermediateProxy bidding design?
    ProxyBidder stores max; service auto-raises up to max when outbid.
    Q5AdvancedScale auctions to HLD?
    Shard by itemId; single-writer partition; websocket push for bids — mention after LLD complete.

    Summary

    Timed auction exercise mirrors interview structure. Synchronized bid acceptance prevents lost updates. Notifier handles outbid and win events. Practice extensions: proxy bid, soft close. Compare your timed attempt to reference code.

    Ready to mark this lesson complete?Track your journey across the entire course.