Nearby search
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Layer 3 · Go deeper · 11 min

    Go deeper

    Size it, build it, then make the calls an interviewer will push you on.

    Back of the envelope

    Size it up

    Tap through each step of the arithmetic.

    How many searches a second must search plan for?

      How lopsided are reads and writes?

        How much data does search actually need?

          How many machines does scoring take at the peak?

            Build-up · 5 steps

            Build the high-level design

            One functional requirement at a time, ending with a design that works for one country before any scaling.

            Step 1 of 5

            Search nearby

            Start with PostgreSQL and PostGIS. Its GiST index, an R-tree, finds places whose boxes touch your 2 km circle, and only those rows pay for an exact distance check.

            6 interview moments

            You’re the candidate

            The interviewer pushes on the hard parts. Pick an approach and see how it holds up.

            1. Deep dive 1 of 6

              Interviewer

              “200 million places, and “near me” is two-dimensional. How do you index locations for search?”

              Your move. Pick an approach:

            2. Deep dive 2 of 6

              Interviewer

              ““Biryani, open now, under ₹₹, rated 4+, within 2 km.” Where do you evaluate each condition?”

              Your move. Pick an approach:

            3. Deep dive 3 of 6

              Interviewer

              “Place A has two 5-star reviews, 300 m away. Place B averages 4.6 over 3,000 reviews, 1.5 km away. Which ranks first, and how?”

              Your move. Pick an approach:

            4. Deep dive 4 of 6

              Interviewer

              “Connaught Place might have 40 biryani places per km²; rural western Rajasthan, about 0.05. What radius do you search?”

              Your move. Pick an approach:

            5. Deep dive 5 of 6

              Interviewer

              “Search now has its own copy of every place. How do you keep it within minutes of the database without losing updates?”

              Your move. Pick an approach:

            6. Deep dive 6 of 6

              Interviewer

              “20,000 searches a second against a 200 GB index. How do you shard, copy and cache it?”

              Your move. Pick an approach:

            Build-up · 8 steps

            Follow one search, then one review

            The read path is caches, a search service and a regional index. The write path is three small services on one database. Change data capture is the only bridge.

            Step 1 of 8

            Search request

            The app sends a point or viewport plus filters. Viewport searches snapped to map tiles are often answered by the CDN; the rest reach the search service through the gateway.