</> MAANG.io

Expert

Design landmark systems in depth, from Dynamo, GFS, Bigtable and Kafka to payments and ads pipelines.

0 of 232 solved 0%

Section 1: Somebody Else's Code on Your Machines - Problem Understanding & Clarifications

Executive Summary: This section covers the opening minutes of a prompt that sounds like "start a container when a request arrives" and turns out to be four hard problems sharing one product: isolating hostile code, making scale-from-zero cost about 100 ms, finding a warm sandbox a million times a second, and running async events with honest retry semantics. We decompose the prompt, run a clarifying exchange in which each answer kills or creates a class of work, write the assumptions down, and meet the two functions that will test every later choice.

The interviewer reads the prompt aloud and then stops talking:

"Design a serverless function platform like AWS Lambda or Azure Functions. Customers upload code, the platform runs it in response to events (HTTP calls, queue messages, file uploads, schedules), scales each function from zero to thousands of concurrent executions in seconds, bills by the millisecond, and runs code from millions of mutually distrusting customers on shared hardware."

The tempting answer forms quickly: a request arrives, start a container with the customer's code, run it, return the result, let Kubernetes handle the rest. It takes four minutes to sketch, and it is the trap. Every phrase in the prompt that sounds like a feature is really a constraint, and the constraints fight each other:

  1. Isolation. "Mutually distrusting customers on shared hardware" means the code is hostile by assumption. Two companies' functions will share a physical host, and one of them may be an attacker who signed up for exactly that.
  2. Cold starts. "From zero" means there is often nothing running when a request arrives. If making a sandbox takes seconds, the product breaks. It has to cost around 100 ms.
  3. Placement and concurrency. "Thousands of concurrent executions in seconds" means every invoke must find an idle, initialized sandbox for that exact function among more than a million resident on the fleet, while per-tenant limits stop one customer eating everyone's capacity.
  4. Async execution. "Queue messages, file uploads" means many invokes have no caller waiting. Once the platform accepts an event, it must say exactly what happens when the function fails, times out or runs twice.

Key Insight: The word that hides the difficulty is function. To the customer it's a few lines of handler code. To the platform it's an untrusted program that must start in milliseconds, scale in seconds, vanish when idle, and never see a neighbour's memory. Name those tensions early and the interviewer knows you've seen past the container.

Decomposing the Prompt

Before asking anything, map the territory:

  • What it does: four verbs. Upload code, trigger it from events, execute it on demand, bill for exactly the time it ran.
  • Who uses it: millions of tenants who trust neither each other nor us. And a quieter second set of users, the event sources: object storage emitting upload notifications, queues with messages waiting, schedulers firing on the minute. They are machines, and they send traffic in bursts.
  • Why it exists: no servers to manage, and pay only for use. That second promise drives the economics. Idle capacity is our cost, so the platform wants as little kept warm as possible, and the customer complains when it isn't.
  • How it's used: synchronous HTTP or API calls where a client waits; asynchronous events where a source hands over a payload and walks away; and event-source mappings, where the platform itself polls a queue or stream and invokes the function with batches.

Flowchart: the serverless platform prompt splits into what, who, why and how, which lead to placement and concurrency, isolation, cold starts and at-least-once async

Quick check before moving on:

Sign in to continue reading

The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.

Sign in to read the full lesson

Sign in to MAANG.io

Use your Google or Microsoft account — no password to remember.

Continue with Google Continue with Microsoft

Please accept the terms above to continue.