InterviewLegend

Design an App to Switch a Remote Smart Bulb

Frequently asked
Alex Chen27 min readGuide updated
In this lesson
  • Trace a tap in the app through the cloud to a bulb behind a home router, and back
  • Pick a device protocol and defend it against polling, WebSockets and CoAP
  • Get acknowledgements, offline bulbs, retries and racing taps right under deep questioning

Understanding the problem

The prompt

Something like this: design a system for an app that turns a remote smart bulb on and off.

This is the newest Samsara design prompt anyone has named. A Staff candidate interviewing for the Routing org got it in July 2026. It has relatives. A February 2025 virtual onsite described a light-bulb switch system. In 2024 a Senior Firmware Engineer was asked how they would design "a 'thing' to use at home", and a software engineer on Blind called their onsite design "some combo of hardware and software for a pure software role". The prompt sounds small. One button, one bulb, two states. The difficulty lives between the button and the bulb. Home networks block incoming connections. A bulb drops offline whenever someone flips the wall switch. And the app has to tell the truth about whether the light came on.

The Samsara angle
The July 2026 candidate's advice was blunt: "make sure you really understand the tech to use in depth", because "the interviewer will dig deep and will ding only surface knowledge." So pick a protocol you can explain down to its keepalives, acks and reconnects. Naming MQTT won't carry the round.

Picture the user at the airport, remembering the porch light. One tap on "off", and within a second the icon should change, and that icon has to be true. If the bulb is unreachable, the app should say so. And the light shouldn't flash on at 3 a.m. when the power comes back.

Requirements

Functional requirements

Agree on the surface first. A signed-in user sees the bulbs in their home with each one's current state and whether it's online. They tap on or off, and the app shows the change once the bulb confirms it. Anyone else in the same home who has the app open sees the change too. If the bulb is offline, the app says so, and the bulb ends up in the right state when it returns. Ask whether a bulb has Wi-Fi of its own or sits behind a hub, because that changes the first hop.

In scope

  • Turn a bulb on or off from the app, anywhere
  • Show the bulb's real state and whether it's online
  • Push state changes to every open app in the home
  • Handle offline bulbs, retries and two people tapping at once
  • Make sure only the home's members can switch its bulbs

Below the line (call it out, then skip)

  • Brightness, colour and scenes (same path, more fields)
  • Schedules and automations, unless asked
  • Firmware updates over the air
  • Voice assistants and third-party integrations

Non-functional requirements

Latency comes first, because a light switch that lags feels broken. For an online bulb, aim for the light to change within about 300 milliseconds most of the time and under a second at the 99th percentile. The app should hear back just as fast. Correctness is the second target, and it's subtler than it looks. The app must never show "on" for a bulb that isn't on. A late or repeated command must never undo a newer one. The command path should stay up even when parts of the cloud are struggling, so availability beats strict consistency for everything except the version check on each bulb's state. Then the numbers. Ask for them, and if the interviewer has none, propose some. Ten million bulbs, nearly all connected at once. Each gets switched about five times a day, with an evening peak around five times the average.

  • Connected bulbs: 10 million. Each one holds a connection open to the cloud all day. The connection count drives the design far more than the command rate does.
  • Commands: about 3,000 a second at peak. 10 million bulbs times 5 taps is 50 million a day, or about 580 a second on average. The evening peak at five times that is roughly 3,000.
  • Keepalive pings: about 170,000 a second. Each bulb sends one small ping every 60 seconds, and 10 million over 60 is about 170,000. The broker answers these itself, and they never touch a database.
  • Tap to light: under 1 second. About 300 milliseconds is typical for an online bulb. The budget covers the app, the cloud, the internet path into the home and the home Wi-Fi.

The set-up

Core entities

1

Bulb

The physical device: its id, the home it belongs to, its model and firmware, and the fingerprint of the certificate it uses to prove who it is.

2

Home and member

Who may switch what. A home has bulbs and members, and a member's role decides whether they can control or only view.

3

Shadow

The cloud's record of one bulb. It holds what the user wants, what the bulb last said, a version number for each, and whether the bulb is online.

4

Command

One request to change a bulb, carrying a request id so a retried tap isn't counted twice. It lives only long enough to be delivered.

Most of the design hangs on the shadow, which keeps two halves apart. Its desired half is the user's intent, "on, version 7". Its reported half is the last thing the bulb itself said, "off, version 6, online". While they differ, the app shows a pending state, and once the reported version reaches the desired one, the change is confirmed. AWS IoT calls this a device shadow and Azure calls it a device twin.

Where each record lives
TableFields
shadows (key-value store, keyed by bulb)bulb_id · desired_power · desired_version · reported_power · reported_version · online · last_seen
bulbs (Postgres)bulb_id · home_id · model · firmware · certificate_fingerprint
homes and members (Postgres)home_id · user_id · role
requests (key-value store, expires after a day)request_id · bulb_id · version
The shadow takes every write on the hot path, so it sits in a key-value store with conditional writes. Ownership is relational and read far more than written, so it stays in Postgres behind a cache.

API

Two audiences talk to the system, and they speak different protocols. The app uses plain HTTPS plus a WebSocket for live updates. The bulb uses MQTT, a small publish and subscribe protocol built for devices, on two topics of its own: one it listens on for commands, one it reports on.

The interface
RequestServer pushFire-and-forget
AppCommand APIswitch a bulb
POST /bulbs/{bulb_id}/power { power, request_id }
version, status (sent or bulb offline)
Returns once the intent is stored. Confirmation arrives later on the live stream.
AppCommand APIread every bulb in a home
GET /homes/{home_id}/bulbs
per bulb: desired, reported, online, last_seen
Live update gatewayAppstate changes for one home
WebSocket /homes/{home_id}/events
bulb_id, reported power, version, online
MQTT brokerBulba command for this bulb
topic bulbs/{bulb_id}/commands { power, version }
Always an absolute state with a version. Never "toggle".
BulbMQTT brokerwhat the bulb is doing now
topic bulbs/{bulb_id}/reported { power, version }
Sent after every change, on connect, and when someone uses the wall switch.

High-level design

The design splits into two halves that meet at the shadow. On the left, the app's requests come in over HTTPS and turn into stored intent plus a message to the bulb. On the right, the bulb's own messages come back through the broker and turn into stored truth plus a push to every open app. In the diagram, blue is outside our control (the phone and the bulb), violet is a service we run, amber moves messages, and green is stored state.

Loading diagram...

1) The bulb connects. On power-up the bulb joins the home Wi-Fi and opens an outbound TLS connection to the MQTT broker cluster on port 8883, presenting its factory certificate. It subscribes to its command topic and publishes its current state and last applied version. The direction matters, because a home router lets connections out and drops unsolicited ones coming in. From then on the bulb sends a tiny ping every 60 seconds, which is how the broker knows it's alive. Holding ten million of these lines open is the scaling problem, and it gets its own deep dive.

2) The tap. The app posts "power on" with a request id. The Command API asks the Device registry whether this user can switch this bulb, then writes the desired state and the next version, say 7, into the Shadow store with a conditional write. It publishes "on, version 7" to the bulb's command topic and returns "sent" with the version, all within a few tens of milliseconds. It doesn't wait for the bulb, because a hung bulb would otherwise pin a request thread. If the publish fails after the write, the shadow still holds the intent, and step 4 repairs it.

3) The bulb confirms. The Smart bulb switches and publishes "on, version 7" on its reported topic, and the broker forwards that into the Device event log. From there the Device events service writes it into the shadow if version 7 is newer than what's stored, then tells the Live update gateway, which pushes it to every open app in the home. Only now does the icon go solid. The broker accepting the publish in step 2 proved nothing about the light, which is the second deep dive.

4) The bulb was offline. Someone flipped the wall switch an hour ago, so the bulb has no power. The broker noticed when its pings stopped, and the shadow now says offline. A tap still stores the intent, and the API answers "bulb offline" so the app can say so honestly. When power returns, the bulb reconnects and reports version 6. Seeing desired at 7, the events service sends one command with the latest state, with no backlog of old taps replayed. How far to trust old intent is the third deep dive.

The Samsara angle
One 2024 Samsara candidate says the interviewer "refused to allow me to draw any pictures". It's a single report, but practice saying this design aloud: the bulb dials out, intent goes in the shadow, the bulb's report is the confirmation. If those lines are clear spoken, you don't need the boxes.

Technology choices

  • The MQTT broker cluster runs EMQX or HiveMQ, or AWS IoT Core if you'd rather not operate it. A broker is built for many long-lived, mostly idle connections, with keepalives, offline detection and per-topic routing included. If a node dies, its bulbs notice within one keepalive and reconnect to other nodes after a random delay, and the shadow tells each one what it missed.
  • The Shadow store is DynamoDB, keyed by bulb id. Every access is "one bulb by its id", and the conditional write ("only if the version is still 6") is the guard against lost updates. Postgres would cope at a few thousand writes a second too. DynamoDB copies every write to three availability zones (separate data centres in one region), so losing one loses nothing.
  • The Device registry is Postgres. Homes, members and bulbs are related records that need joins and foreign keys. Reads go through a cache with a short expiry, so removing a member takes effect within about a minute, and the database barely notices the command traffic.
  • The Device event log is Kafka, partitioned by bulb id. Kafka is an append-only log, so a message stays readable after a consumer takes it. Each consumer tracks its position, called an offset. If the events service crashes, it restarts from its last saved offset, and the replayed reports are harmless because shadow writes only accept newer versions.
  • The Live update gateway is WebSocket servers plus Redis pub/sub, one channel per home. Pub/sub can drop a message during a Redis failover. The cost is a stale icon for a moment while the light itself is right, and the app re-reads the shadows whenever it reconnects. When the app is closed, a phone notification through APNs or FCM can stand in for anything the user must hear about.

The broker and Kafka look alike from far away, and the interviewer may ask why both. The broker is a router for live connections: it keeps little and forgets fast. Kafka is a durable log that services can replay. Bulbs speak to the first. Our own services read the second.

Potential deep dives

How does a command reach a bulb behind a home router?

The bulb sits on a private home network behind a router doing network address translation (NAT): every device in the house shares one public IP address, and the router only lets in replies to connections that started inside. The cloud can't simply call the bulb. Whatever we pick has to start from the bulb's side.

BadThe cloud calls a server on the bulb

Approach

Run a tiny HTTP server on the bulb and have the cloud send a request to the home's public address when the user taps.

Challenges

The router drops the request, because nothing inside asked for it. Making it work means port forwarding or UPnP, an old protocol that lets devices open ports on the router by themselves. That breaks on carrier networks that share one address across many homes. Home addresses also change without notice. Worst of all, it exposes a cheap device with an open port to every scanner on the internet. Nobody should propose this, but be ready to say why it fails.

GoodThe bulb polls the cloud over HTTPS

Approach

The bulb asks "anything for me?" every few seconds. Outbound requests pass through NAT fine, so this works on any home network. Long polling improves it: the cloud holds each request open for up to 30 seconds and answers the moment a command arrives.

Challenges

Plain polling is slow or expensive. At one poll every 5 seconds, 10 million bulbs send 2 million requests a second to carry about 580 real commands, so over 99.9% come back empty. The user still waits 2.5 seconds on average. Long polling fixes the delay, but every bulb now holds an open request most of the time. That's a persistent connection anyway, with an HTTP header on every exchange and nothing built in for liveness or delivery.

GreatOne persistent MQTT connection per bulb

Approach

The bulb opens one TLS connection to the broker and keeps it. MQTT, a publish and subscribe protocol designed for small devices, has a fixed header as small as two bytes, so a command is a few dozen bytes. Every 60 seconds a keepalive ping holds NAT mappings open and proves liveness, and the broker drops a client after one and a half intervals of silence. A "last will" message, registered at connect time, lets the broker announce the bulb offline as soon as it notices the silence, with no extra code on our side. A command reaches an online bulb in one network trip.

Challenges

Ten million open connections cost memory and file handles on the broker, so the cluster is sized by how many connections it holds, while the message rate barely matters. Some networks block port 8883. MQTT also runs over WebSocket on port 443, which gets through almost anywhere.

What earns MQTT its place over a homemade WebSocket protocol is what comes built in: topics, keepalives, last will, delivery levels, sessions that survive a reconnect, and device libraries that already run on small microcontrollers. With raw WebSockets you would write each of those yourself. The interviewer will likely ask how the alternatives compare. Have the table in your head.

Protocol trade-offs for a bulb
ProtocolWhere it fitsWeak spot here
HTTPS pollingRare, non-urgent checksSlow, or millions of empty requests a second
Long pollingWhen only HTTP gets throughHolds connections anyway, without liveness or acks
WebSocketBrowsers and appsNo topics, acks or offline sessions unless you build them
MQTT over TLSAlways-on devices, many idle connectionsNeeds a broker sized for connections
CoAP over UDPBattery devices on constrained networksUDP mappings in home routers expire fast, so a server push often gets lost
The live update gateway still uses WebSocket for the app, where the browser and phone already speak it. The protocol choice is per audience.

There's one more hop to ask about, and it's the radio. A Wi-Fi bulb reaches the internet by itself. Many bulbs instead use Zigbee or Thread, low-power mesh radios that need a hub to reach the internet. Philips Hue's bridge is the familiar Zigbee example, and Thread calls it a border router. The hub holds the one MQTT connection for every bulb in the house and translates commands onto the mesh. Matter, the newer smart-home standard, runs over Wi-Fi or Thread and lets a phone on the same network switch the bulb locally without the cloud.

Loading diagram...
The Samsara angle
A 2024 Samsara Senior Firmware candidate said the design question "was not about designing a database or microservice". The device side is fair game in these rounds. Ask early which radio the bulb has and whether a hub exists. It shows you know where the real constraints sit.

How do we know the bulb turned on?

There are three different "it worked" signals in this system, and they're easy to mix up. First the API stores the intent, then the broker accepts the message, and finally the bulb changes state. Only the last one is what the user cares about, and only the bulb can produce it.

BadReport success when the publish returns

Approach

The Command API publishes the command, the broker accepts it, and the API tells the app "done". The icon goes solid right away.

Challenges

The broker accepting a message says nothing about the bulb. With MQTT, a publisher's acknowledgement comes from the broker, never from the subscriber, because each hop is acknowledged separately. If the bulb was half-connected, crashed mid-command or has a burnt-out relay, the app now lies. Users stop trusting an app the first time it says "off" while the porch light glows.

GoodWait for a reply from the bulb

Approach

Send the command with a correlation id and a reply topic, which MQTT 5 supports directly. The bulb applies the change and replies on that topic. The Command API holds the user's request open for up to two seconds and returns the bulb's answer, or "not responding" on timeout.

Challenges

It tells the truth, but it ties an HTTP request to a device. Thousands of requests a second now wait on home Wi-Fi, and a slow bulb pins a thread for the full timeout. The reply also only reaches the phone that tapped. Another family member's open app still shows the old state, and a later wall-switch change never reaches anyone.

The Good tier answers "did my command work?" The real requirement is wider: "what state is this bulb in right now?", for every viewer, whatever changed it. That's what forces the move to a shadow.

GreatDesired and reported state, with versions

Approach

A tap only writes desired state with a new version and returns. Separately, the bulb reports its real state with the version it applied, after every change and on every connect. The app shows "turning on" while the reported version trails the desired one and switches to "on" when it catches up. Every open app learns at once through the live gateway, whoever made the change.

Challenges

Pick a timeout for pending, around three seconds, after which the app shows "not responding" while the shadow keeps the intent. Changes made at the bulb need care too. If someone uses a physical button, the bulb reports a state nobody asked for. The events service then copies it into desired with a new version, or the cloud would push the old intent straight back.

desired: power on version 7
reported: power off version 6 online
-> app shows "Turning on..." until reported version reaches 7

MQTT's delivery levels come up here, so know them cold. At QoS 0 a message is sent once and forgotten. At QoS 1 the sender resends until the next hop acknowledges, so a message can arrive twice. QoS 2 runs a four-message handshake per hop to deliver exactly once, at roughly twice the round trips. Commands go at QoS 1, because an absolute state with a version makes a duplicate do nothing, and that makes QoS 2's extra cost pointless. The real-time updates lesson covers the app side of push in general.

What happens when the bulb is offline?

Offline is the normal case for a bulb. Every time someone turns it off at the wall, it loses power and drops its connection. If one bulb in ten is off at the wall in the evening, that's a million bulbs that can't hear us, and taps keep arriving for some of them. The question is what each of those bulbs should do when it wakes up.

BadQueue every command and replay them in order

Approach

Keep a queue per bulb. Every tap while it's offline goes on the end, and on reconnect the bulb receives the whole list in order.

Challenges

The bulb flickers through on, off, on as it works through history nobody wants. A "turn on" sent at 7 p.m. fires at 3 a.m. when the power returns. Queues for a million offline bulbs pile up in the broker's memory with no natural limit, and a queue that grows faster than it drains turns a short outage into a long one.

GoodPersistent sessions in the broker

Approach

The bulb connects with a persistent session, meaning MQTT 5's clean start flag is off and the session expires after, say, a day. The broker then holds QoS 1 messages for it while it's away and delivers them on reconnect. MQTT 5's message expiry drops any message older than a set age, so a tap from 7 p.m. can die ten minutes later.

Challenges

This is the standard tool, and it's better than a homemade queue. But it still replays history: three taps while offline arrive as three commands. The queued messages live in the broker, so if the node holding them fails without replicating sessions, they're gone. The broker also has no idea which message is the one that matters.

GreatReconcile from the shadow on reconnect

Approach

Don't queue commands at all. The shadow already holds the one thing a returning bulb needs, which is the latest desired state. On reconnect the bulb reports its last applied version. If desired is newer, the events service sends a single command with the latest state. Three taps while offline become one. A lighter variant publishes desired state as a retained message, one the broker keeps and hands to every new subscriber.

Challenges

Staleness is a product decision, so ask it out loud. "Desired state wins whenever the bulb returns" suits a light. Something like a door lock must expire old intent, so store an expiry with each desired state and drop it on reconnect when it's past.

Retries while the bulb is online need limits too. If no report arrives within about a second, the events service resends the same command with the same version, then again after two and four seconds, and then gives up and marks the bulb not responding. Resending is always safe, because the bulb ignores any version it has already applied.

The retry that can hurt most comes from the bulbs themselves. After a broker deploy gone wrong or an ISP outage across a city, every affected bulb reconnects the moment service returns, and each reconnect is a full TLS handshake costing on the order of a millisecond of server CPU. Ten million bulbs reconnecting within one minute is about 170,000 handshakes a second, enough to knock the brokers over again. Firmware must back off with jitter: wait a random time between zero and a growing cap, up to a few minutes. Spread over ten minutes, the same fleet is about 17,000 handshakes a second. The broker can also refuse early with MQTT 5's "server busy" code.

What if two taps race, or a command arrives twice?

Two people in the same house tap the same bulb within a second, one "on" and one "off". The app retries a tap because the network hiccupped. A command gets redelivered at QoS 1. Each of these is ordinary, and each one can leave the light in the wrong state if the design is naive. The first fix is in the API shape. A "toggle" command is dangerous, because delivering it twice is the same as not delivering it at all. Every command carries an absolute state, so applying it twice changes nothing. Then three guards, each with a version number, close the rest.

1

A request id at the API

The app makes one request id per tap and reuses it on retry. The API records which version that id produced, for a day. A retried tap gets the same version back and writes nothing new, so a flaky network can't bump the version twice.

2

A conditional write in the shadow

The API reads version 6 and writes version 7 only if the item still says 6. If the other phone got there first, the write fails, and the API re-reads and writes version 8. One of the taps wins, and every later step agrees on which.

3

The bulb ignores anything older

The bulb stores its last applied version in flash. A command whose version isn't newer gets ignored, so a late redelivery of version 7 can't undo version 8. Saving the version in flash means a power cut doesn't reset that memory.

on command (power, version):
if version <= last_applied: report current state, stop
switch to power, save last_applied = version
report (power, version)

Last write wins here, and it's the right rule for a light. The two people at the switch get whichever tap reached the shadow second, and both their apps show the same result within a second. Say why it's safe: nothing about a bulb needs both taps to survive, unlike a bank balance. The handling contention lesson covers compare-and-set against locking in general.

How do we hold ten million connections and route a command to the right one?

Commands are cheap at 3,000 a second. Connections are the cost. Each TLS connection needs memory for its encryption state and buffers, tens of kilobytes. Plan for about 100,000 connections per broker node to leave room for a failed neighbour's bulbs, and ten million bulbs need about 100 nodes. At 30 KB each, a node holds about 3 GB of connection state. That's comfortable for one machine.

A load balancer in front of the brokers passes TCP through and spreads new connections across nodes. Then the routing question: the Command API publishes to any node, but bulb b42's connection lives on one particular node. A clustered broker such as EMQX or HiveMQ keeps a shared table of which node holds each subscription and forwards the message there. If you build on raw WebSockets instead, you need that table yourself, typically bulb id to gateway node in Redis. Then a reconnect can leave a stale entry pointing at the old node, so store a connection number with each entry and ignore older ones.

Deploys are the planned version of a node failure, since restarting a node drops 100,000 bulbs at once. Drain nodes one at a time. MQTT 5 lets the broker send "use another server" before closing, and firmware jitter spreads the reconnects. During a rollout, track the handshake rate as closely as error rates. The scaling writes lesson covers partitioning by key in general.

How does a bulb prove who it is, and who may switch it?

A bulb that anyone can switch is a prank. A broker that lets one bulb listen to another's commands is a breach. Security here comes in three layers, and the interviewer may press on any of them.

1

Device identity from the factory

Each bulb gets its own certificate and private key at manufacture, ideally kept in a secure chip that won't export the key. It connects with mutual TLS, so the broker checks the bulb's certificate just as the bulb checks the broker's. A cloned bulb without the key can't connect.

2

Topic permissions per bulb

The broker only lets a bulb subscribe to its own command topic and publish to its own reported topic, matching the bulb id in its certificate. A compromised bulb can't read or send anyone else's commands.

3

Claiming and user access

During setup the app talks to the bulb over Bluetooth, hands it the Wi-Fi password and a one-time claim code, and the bulb presents that code when it first connects. That ties it to the home. After that, every tap is checked against the home's members in the registry.

Removing access runs the other way. A member who leaves the home loses control within the cache expiry, about a minute. A stolen or resold bulb gets its certificate revoked in the registry, and the broker refuses its next connection.

Practice the core in code

Shrink the design to one class you can run, holding the shadow for many bulbs. It accepts taps with request ids, stamps each with a version, accepts the bulb's reports only when they're newer, and answers what a reconnecting bulb should be sent. It leaves out the network, the broker and the app. What's left decides whether the light ends up in the state the user asked for.

1

Bulb shadow with versioned commands and acks

Medium
Problem
A cloud service controls smart bulbs. For each bulb it keeps a desired power state set by users, a version number that goes up by 1 on every new command, and the last state the bulb confirmed. Write a class BulbShadow.

set(bulb_id, power, request_id) records a user's command, where power is "on" or "off". If request_id was seen before, return the version it returned the first time and change nothing. Otherwise create the bulb if needed, starting at version 0 with reported state "unknown", add 1 to its version, store power as desired, and return the new version.

ack(bulb_id, version, power) is the bulb confirming it applied a command. Accept it only if the bulb exists and version is greater than the last accepted ack and no greater than the bulb's current version. Then store power as the reported state and return true. Otherwise return false and change nothing.

pending(bulb_id) returns [version, power] for the latest desired state if the last accepted ack is below the current version, and null otherwise or for an unknown bulb. status(bulb_id) returns [desired, reported], or null for an unknown bulb.

Input encoding. A test case is a JSON array of operations. The first entry is ["BulbShadow", []] and each later entry is [method, [args]]. The expected array holds each operation's return, with null for the constructor.
  1. BulbShadow()
  2. set("b1", "on", "r1")→ 1
  3. set("b1", "on", "r1")→ 1
  4. pending("b1")→ [1,"on"]
  5. ack("b1", 1, "on")→ true
  6. pending("b1")
  7. status("b1")→ ["on","on"]

The second set is the app retrying the same tap, so it gets version 1 back and nothing changes. Once the bulb acks version 1, nothing is pending.

How this uses the pattern

Keep one record per bulb with its desired power, current version, reported power and last accepted ack version, plus a map from request id to the version it produced.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Bulb shadow with versioned commands and acks

Loading...
Click "Run" to execute your code
The Samsara angle
This is the shadow from the design, small enough to run. Most bugs show up on repeats and late arrivals: a retried tap that bumps the version, a stale ack that overwrites a newer one, a reconnect that replays old commands. State the rule before coding. Versions only move forward, and a repeat is a read.
Take it further
Add report(bulb_id, power) for a change made at the bulb itself, such as a physical button. It should bump the version and set desired to match, so the cloud doesn't push the old state back. Then add an expiry to each desired state and have pending return null once it has passed.

Follow-ups to be ready for

The internet is down. The user is home and the app can't reach the cloud. With a hub or Matter, the phone can talk to the bulb over the local network. The hard part is merging afterwards. The local change must reach the shadow when the connection returns, as a report with a new version, so the cloud doesn't push the old state back.

Schedules. "Porch light on at sunset" can run in the cloud, which is easy to change but stops working when the home is offline. It can also run on the hub or bulb, which survives outages but needs a correct clock and time zone on the device. Many products do both: the device runs the schedule, and the cloud keeps a copy to show and edit.

Groups and "all off". Turning off 30 bulbs means 30 shadow writes and 30 commands, which is fine. Do them in parallel and confirm each one separately, so the app can say "29 of 30 off, the garage is offline" instead of failing the whole action. Behind a hub, one group command on the mesh radio switches them together and avoids the lights popping off one by one.

What we watch. The numbers that tell you the system works are the ones the user feels. Track the share of commands confirmed within one second, and the time from tap to confirmation at the median and 99th percentile. Watch the share of bulbs online, the reconnect rate per minute and the number of commands that timed out. A jump in reconnects is usually the first sign a broker node or a firmware release is in trouble.

The Samsara angle
Samsara's own business is connected devices in vehicles and on worksites that report into a cloud, and its design prompts come from that world. If time allows, note that the shadow, the versioned acks and the reconnect jitter carry over to any fleet of devices on unreliable networks.

What is expected at each level

Samsara's design round has been one hour in the virtual onsite in reports since 2024. One candidate described it starting as an MVP and then being pushed to scale, and many say interviewer styles vary a lot. Treat pushback as a new requirement and change course out loud. One rejection note cited "not taking feedback provided by the interviewer".

SWE II and Senior

Mostly breadth, with real depth in one place. You explain why the bulb must dial out, pick a persistent connection over polling with the numbers to back it, and walk the full path from tap to confirmation. You keep desired and reported state apart without being asked, and you can explain QoS 1 and why a duplicate command is harmless. Offline bulbs get a sensible answer, even if it's the broker's persistent session. The bar: the app never claims a state the bulb didn't report, and a retry never flips the light.

Staff

Depth over breadth, and you lead. This is the level the July 2026 candidate interviewed at, with the warning about surface knowledge. Expect the interviewer to keep digging into whatever protocol you pick, so pick the one you know best. You raise the reconnect storm and the jitter math yourself, size the broker fleet by connections, handle racing taps with versions at every hop, and treat staleness as a product question. You also cover device identity and topic permissions, and say what you'd measure. The bar: you could defend every hop, from the radio in the bulb to the WebSocket in the app, at the level of what happens when it fails.

Common questions

Does Samsara ask a smart bulb system design question?

It has come up. A Staff candidate named it in July 2026: design a system for an app that turns a remote smart bulb on and off. A February 2025 onsite described a light-bulb switch system, and 2024 reports describe a hardware and software design and "a 'thing' to use at home".

Which protocol should a smart bulb use to talk to the cloud?

For an always-powered bulb on Wi-Fi, MQTT over TLS on one persistent outbound connection is the usual answer. It gets through home routers, reaches the bulb in one network trip, and comes with keepalives, offline detection and delivery acknowledgements. Zigbee and Thread bulbs reach the cloud through a hub instead.

How do you handle a smart bulb that is offline?

Keep the user's latest desired state in a device shadow, tell the app the bulb is offline, and when the bulb reconnects send only the newest state. Replaying every queued command makes the light flicker through old history.

Key Takeaways

  • ✓Home routers block incoming connections, so each bulb dials out and keeps one MQTT connection open.
  • ✓Store desired and reported state with versions. Only the bulb's own report confirms the light changed.
  • ✓Offline bulbs get the latest desired state on reconnect, never a replay of every tap.
  • ✓Absolute states, request ids and versions at every hop make retries, duplicates and racing taps harmless.
Samsara interview guide

Know what Samsara asks before you walk in.

25 coding · 4 system design · 11 behavioral questions

Get Premium$49 a year · Instant access
Or start freeNo card.

Get their questions first.

Samsara System Design Interview QuestionsHad your Samsara interview?How we research

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.