Preparing your design workspace

Loading the problem and your latest saved attempt…

Split a Traffic Signal System into Three Services

Replace two traffic components that call each other over HTTP and share a database with three services that do not block each other, define how they talk, and write the camera feed's callback for 50,000 sensor items per second.

Problem statement

Split a traffic system into three services that do not block each other. Today two components, SignalAdjuster and CameraFeed, talk over HTTP and share one database, and this setup makes signal updates arrive late.

Define the protocols between the services, say which service owns each constraint below, and write the callback CameraFeed runs for incoming sensor data in pseudo code.

Constraints - About 50,000 sensor data items arrive per second. - Signal state is write-only. - Alerts use both asynchronous and synchronous messages.

For this exercise, assume: - The city has about 2,000 intersections. Cameras and road sensors at each one send small data items, such as a vehicle count, a queue length or a detected event, each under 1 KB. Video stays on the cameras.

- SignalAdjuster sets each intersection's signal timing, such as how long each green lasts, from the last few seconds of that intersection's data. - Each intersection has a controller that accepts a new signal state over the network and confirms it.

The controller enforces the safety rules itself (never two conflicting greens, minimum yellow and red times). It keeps running its current timing until it receives a new one.

- Write-only means signal state flows one way: only the service that decides it writes it, keeps a history of what it sent, and sends it to the controllers. No other service changes it or waits to read it. - Routine alerts, such as a camera that stopped sending or heavy congestion, go to the operators' dashboard.

Urgent alerts, such as a crash blocking a junction, go to the city's emergency dispatch system, which must confirm each one.

Out of scope: the video models on the cameras, the controllers' internal safety logic, and long-term traffic reports.

What to build

  1. Cameras and road sensors at every intersection can send data items, and the system accepts them without waiting on signal decisions or alerts.
  2. Each intersection's signal timing is updated from its recent traffic and sent to its controller.
  3. Routine alerts reach the operators' dashboard, and urgent alerts reach emergency dispatch and are confirmed.

At scale

  • About 50,000 sensor data items arrive per second. For this exercise, assume they come from about 2,000 intersections (about 25 items per intersection per second) and each is under 1 KB, so at most about 50 MB per second.
  • For this exercise, assume rush hours and large events can push the rate to about 3 times normal for several minutes.
  • For this exercise, assume a new signal timing must reach the controller within 2 seconds of the data that caused it, and data older than 10 seconds is too old to drive a signal.
  • For this exercise, assume emergency dispatch must confirm an urgent alert within 2 seconds, or an operator is paged. Routine alerts may take up to 30 seconds. No alert may be lost, even when a service restarts.