Chapter 10 · Article 46 of 55
Designing a Traffic Signal Control System
Design a traffic signal control system that manages vehicle and pedestrian traffic flow at a multi-way intersection. The system must safely coordinate signal phases across multi…
Article outline14 sections on this page+
Problem Statement
Design a traffic signal control system that manages vehicle and pedestrian traffic flow at a multi-way intersection. The system must safely coordinate signal phases across multiple roads, handle pedestrian crossing requests, respond to emergency vehicle preemption, and adapt timing based on real-time traffic conditions detected by sensors.
Scenario: You are tasked with designing the software control system for a standard 4-way intersection in an urban environment. The intersection has dedicated left-turn lanes, pedestrian crosswalks on all four sides, inductive loop sensors embedded in the road surface, and emergency vehicle detection receivers. The system must guarantee that no two conflicting directions ever receive a GREEN signal simultaneously, while maximizing traffic throughput and minimizing average wait times.
The controller must operate 24/7 with minimal human intervention, gracefully handle hardware failures, and support remote configuration updates from a central traffic management center.
Requirements
Functional Requirements
- Multiple Signal States - Each traffic signal must support RED, YELLOW, and GREEN states, plus protected left-turn arrows (GREEN_ARROW, YELLOW_ARROW).
- Configurable Timing - Signal phase durations must be configurable per intersection, per time-of-day, and per day-of-week without requiring firmware updates.
- Pedestrian Crossing Signals - Dedicated WALK / DON'T WALK / countdown signals activated by pedestrian push buttons, with sufficient crossing time calculated from crosswalk length.
- Emergency Vehicle Override - Preemption system that detects approaching emergency vehicles (via optical or radio receivers) and transitions the intersection to grant them a green corridor.
- Sensor-Based Adaptive Timing - Inductive loop sensors and/or cameras detect vehicle presence and queue length; the controller extends or truncates green phases dynamically.
- Intersection Coordination - Support for "green wave" coordination with adjacent intersections via offset timing, enabling platoon progression along arterial roads.
Non-Functional Requirements
- Real-Time Operation - Signal transitions must occur within deterministic time bounds (< 100ms command-to-actuation latency).
- Fault Tolerance - The system must detect hardware failures (burned-out bulbs, sensor malfunctions) and fall back to safe modes (flashing red or fixed-timing operation).
- Safety Guarantee - The system must enforce conflict monitoring: no two conflicting movements may simultaneously display GREEN. A hardware conflict monitor must exist as an independent safety layer.
- Availability - 99.99% uptime target; battery backup for minimum 4 hours of operation during power outages.
- Auditability - All state transitions, configuration changes, and override events must be logged with timestamps.
Constraints & Assumptions
- 4-way intersection with North-South and East-West arterials
- Each approach has 3 lanes: left-turn, through, and right-turn
- Protected left-turn phases (leading lefts) on all four approaches
- Pedestrian push buttons on all four corners; ADA-compliant audio signals
- Emergency vehicle detection via optical preemption sensors (e.g., Opticom-style infrared/strobe detection)
- Minimum yellow time: 3 seconds; minimum all-red clearance: 2 seconds
- Pedestrian crossing time calculated at 3.5 ft/sec walking speed
- System operates on a dedicated embedded controller (no cloud dependency for real-time decisions)
- Communication with central management system via cellular/fiber for configuration and telemetry (non-critical path)
Key Entities & Relationships
| Entity | Responsibility |
|---|---|
| TrafficSignal | Physical signal head; displays current state |
| SignalState | Enum: RED, YELLOW, GREEN, GREEN_ARROW, YELLOW_ARROW, FLASHING_RED |
| Intersection | Aggregate root; contains all roads, signals, and controller |
| Road | A directional approach to the intersection |
| Lane | Individual lane within a road (left, through, right) |
| TrafficController | Core logic; manages phase sequencing and timing |
| Timer | Countdown mechanism for phase durations |
| Sensor | Detects vehicle presence, queue length, or emergency vehicles |
| PedestrianSignal | WALK/DON'T WALK display with countdown |
| EmergencyOverride | Preemption logic that interrupts normal sequencing |
| SignalPhase | A specific combination of signal states across all approaches |
| PhaseSequence | Ordered list of phases constituting a full cycle |
ASCII Class Diagram
┌─────────────────────────────────────────────────────────────────────────┐
│ Intersection │
│ - id: String │
│ - roads: List<Road> │
│ - controller: TrafficController │
│ - conflictMatrix: boolean[][] │
└──────────────────────────────────┬──────────────────────────────────────┘
│ 1
│
┌──────────────┼──────────────┐
│ │ │
▼ * ▼ 1 ▼ *
┌──────────────┐ ┌───────────────┐ ┌──────────────┐
│ Road │ │ Traffic │ │ Sensor │
│ - direction │ │ Controller │ │ - type │
│ - lanes[] │ │ - currentPhase│ │ - location │
│ - signals[] │ │ - sequence │ │ + detect() │
└──────┬───────┘ │ - strategy │ └──────────────┘
│ │ + advance() │ │
│ │ + override() │ │ notifies
▼ * └───────┬───────┘ │
┌──────────────┐ │ ▼
│ Lane │ │ uses ┌──────────────────┐
│ - type │ ├────────▶│ TimingStrategy │
│ - sensor │ │ │ (interface) │
└──────────────┘ │ ├──────────────────┤
│ │ FixedTiming │
┌──────────────┐ │ │ AdaptiveTiming │
│TrafficSignal │◀─────────┘ │ EmergencyTiming │
│ - state │ controls └──────────────────┘
│ - position │
│ + change() │ ┌──────────────────┐
└──────┬───────┘ │ SignalPhase │
│ │ - phaseId │
│ has │ - signalStates{} │
▼ │ - duration │
┌──────────────┐ │ - minGreen │
│ SignalState │ │ - maxGreen │
│ «enumeration»│ └──────────────────┘
│ RED │
│ YELLOW │ ┌──────────────────┐
│ GREEN │ │ EmergencyOverride │
│ GREEN_ARROW │ │ - priority │
│ YELLOW_ARROW │ │ - direction │
│ FLASHING_RED │ │ + activate() │
└──────────────┘ │ + deactivate() │
└──────────────────┘
┌──────────────────┐
│ PedestrianSignal │
│ - state: WALK| │
│ DONT_WALK| │
│ COUNTDOWN │
│ - countdown: int │
│ + request() │
└──────────────────┘
Design Decisions & Trade-offs
1. Fixed Timing vs Adaptive (Sensor-Based)
| Approach | Pros | Cons |
|---|---|---|
| Fixed Timing | Simple, predictable, no sensor dependency | Inefficient during off-peak; ignores actual demand |
| Adaptive Timing | Responds to real demand; reduces average wait | Requires sensors; more complex failure modes |
Decision: Use adaptive timing as the primary strategy with fixed timing as the fallback. The Strategy pattern allows runtime switching between algorithms. During sensor failure, the controller degrades gracefully to pre-programmed fixed-timing plans.
2. Centralized vs Distributed Control
Decision: Each intersection operates autonomously with a local controller (distributed). A central management system provides configuration updates, coordination offsets, and monitoring - but is not in the critical path. If communication with central is lost, the intersection continues operating with its last-known configuration.
Rationale: Real-time safety decisions cannot depend on network latency or availability. Distributed control ensures each intersection remains safe independently.
3. Safety Interlocks (All-Red Phase)
Decision: Every phase transition includes a mandatory all-red clearance interval (minimum 2 seconds). This ensures vehicles that entered the intersection during the yellow phase have time to clear before conflicting movements begin.
Additionally, a hardware-level conflict monitor operates independently of the software controller. If it detects conflicting greens, it immediately forces the intersection into flashing-red mode - a fail-safe that cannot be overridden by software.
4. Emergency Vehicle Priority Handling
Decision: Emergency preemption uses a priority queue. When an emergency vehicle is detected:
- Current phase is truncated (yellow → all-red)
- The approach direction of the emergency vehicle receives GREEN
- All other directions remain RED
- After the vehicle passes (sensor clears), the controller transitions back to normal sequencing via a recovery phase
For simultaneous emergency vehicles from conflicting directions, the system serves them sequentially based on detection order (FIFO) with a maximum preemption hold time of 60 seconds.
5. Pedestrian Signal Coordination
Decision: Pedestrian phases are integrated into the signal phase sequence rather than operating independently. When a pedestrian button is pressed, the request is queued and served during the next compatible vehicle phase (parallel pedestrian movement). Exclusive pedestrian phases (Barnes Dance / scramble) are configurable but disabled by default due to throughput impact.
Pedestrian countdown timers are calculated from crosswalk distance and a 3.5 ft/sec walking speed, with a buffer for slower pedestrians.
Design Patterns Used
| Pattern | Application |
|---|---|
| State | TrafficSignal uses the State pattern to encapsulate behavior for each SignalState. Each state knows its valid transitions and enforces them. |
| Observer | Sensor objects publish detection events. The TrafficController subscribes to these events and adjusts timing decisions accordingly. |
| Strategy | TimingStrategy interface with implementations: FixedTimingStrategy, AdaptiveTimingStrategy, EmergencyTimingStrategy. The controller swaps strategies at runtime. |
| Command | Signal change operations are encapsulated as SignalChangeCommand objects, enabling logging, undo (for preemption recovery), and queuing. |
| Template Method | PhaseSequence defines the skeleton algorithm for cycling through phases (begin → extend/gap-out → yellow → all-red → next). Subclasses override extension logic. |
State Transition Diagram
┌─────────────────────────────────────────┐
│ TRAFFIC SIGNAL STATE MACHINE │
└─────────────────────────────────────────┘
min_green expired
AND (max_green expired
┌──────────┐ OR gap-out detected) ┌──────────┐
│ │ ─────────────────────────────────▶│ │
│ GREEN │ │ YELLOW │
│ │ │ │
│ (15-60s) │ │ (3-5s) │
└──────────┘ └────┬─────┘
▲ │
│ │ timer expired
│ ▼
│ all-red clearance expired ┌──────────┐
│ ◀──────────────────────────────────────│ │
│ AND next phase activated │ RED │
│ │ │
└────────────────────────────────────────│(variable)│
└──────────┘
┌─────────────────────────────────────────────────────────┐
│ EMERGENCY PREEMPTION (from any state): │
│ │
│ ANY STATE ──▶ YELLOW (3s) ──▶ ALL_RED (2s) ──▶ │
│ ──▶ GREEN (preemption direction only) │
│ ──▶ [vehicle clears] ──▶ RECOVERY ──▶ NORMAL │
└─────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────┐
│ PEDESTRIAN SIGNAL (parallel with compatible vehicle): │
│ │
│ DONT_WALK ──▶ WALK (7s) ──▶ COUNTDOWN (15-25s) ──▶ │
│ ──▶ DONT_WALK │
└─────────────────────────────────────────────────────────┘
Edge Cases
1. Sensor Failure
Detection: Heartbeat monitoring; if a sensor reports no activity for an abnormal duration (e.g., 5 minutes on a normally busy road during daytime), flag it as potentially failed. Mitigation: Switch to fixed-timing mode for the affected approach. Log the failure and alert maintenance via the central system.
2. Simultaneous Emergency Vehicles from Conflicting Directions
Handling: Serve in FIFO order based on detection timestamp. Maximum preemption hold of 60 seconds prevents indefinite blocking. If a second emergency vehicle arrives from a conflicting direction while preemption is active, it queues and is served immediately after the first clears.
3. Power Failure and Recovery
During failure: Battery backup maintains operation. If battery is depleted, the intersection goes dark. On recovery: The controller boots into a known safe state (all-red for 5 seconds), then begins the phase sequence from phase 1. It does NOT resume mid-phase from before the failure.
4. Pedestrian Button Spam
Handling: Once a pedestrian request is registered, subsequent presses are ignored until the request is served. A single boolean flag per crosswalk - no queue accumulation. Debounce at the hardware level (500ms minimum between accepted presses).
5. Stuck State Detection
Detection: A watchdog timer monitors that the controller advances phases within expected bounds (max cycle length + tolerance). If the controller appears stuck (same phase for > 3× max configured duration), the conflict monitor forces flashing-red mode and alerts maintenance.
6. Detector Stuck-On (Vehicle Sensor Permanently Triggered)
Handling: If a sensor reports continuous presence for > 5 minutes, treat it as failed. Revert to fixed timing for that phase and flag for maintenance.
Extensibility Points
-
New Intersection Types
- T-junctions: Reduce phase count; remove one approach from the conflict matrix
- Roundabouts: Metering signals with different phase logic
- 5-way intersections: Extended conflict matrix; more phases
- The
Intersectionclass accepts a configurable conflict matrix, making topology changes a configuration concern rather than a code change
-
Adaptive AI-Based Timing
- The
TimingStrategyinterface allows plugging in ML-based optimization (e.g., reinforcement learning agents trained on historical traffic patterns) - Real-time camera feeds can provide richer input than inductive loops (queue length, vehicle classification, turning movement counts)
- The
-
Connected Vehicle Communication (V2I)
- Vehicle-to-Infrastructure (V2I) via DSRC or C-V2X enables:
- Signal Phase and Timing (SPaT) broadcast to approaching vehicles
- Priority requests from transit vehicles (bus signal priority)
- Cooperative adaptive cruise control integration
- Add a
V2ICommunicatorcomponent that publishes SPaT messages and receives priority requests through the existing Observer infrastructure
- Vehicle-to-Infrastructure (V2I) via DSRC or C-V2X enables:
-
Multi-Modal Integration
- Bicycle detection and dedicated bike signal phases
- Rail/tram preemption (similar to emergency but with longer clearance times)
- Transit Signal Priority (TSP) with conditional vs unconditional priority levels
Interview Follow-ups
Q1: How would you handle a scenario where the central management system pushes a configuration update that contains an invalid conflict matrix?
Answer: Configuration updates must be validated locally before being applied. The controller runs a conflict matrix validation check: for every phase in the proposed sequence, verify that no two movements marked as conflicting are simultaneously GREEN. If validation fails, the update is rejected, the controller continues with its current configuration, and an error is reported to the central system. This follows a "validate-then-apply" pattern with atomic configuration swaps - the old config remains active until the new one is fully validated.
Q2: How would you design the system to support "green wave" coordination across multiple intersections on an arterial?
Answer: Each intersection maintains a cycle length and an offset relative to a reference clock. The central system calculates offsets based on inter-intersection distance and target speed (e.g., 35 mph). Locally, each controller synchronizes its phase start to (system_time mod cycle_length) == offset. This requires only clock synchronization (GPS-based) and a single offset parameter - no real-time inter-controller communication needed. The coordination is "time-based" rather than "event-based," making it resilient to communication failures.
Q3: What happens if the conflict monitor hardware itself fails?
Answer: The conflict monitor is designed as a fail-safe device - if it loses power or its internal diagnostics detect a fault, it defaults to forcing flashing-red mode. This is implemented via a normally-energized relay: the relay must be actively held open by a healthy conflict monitor. If the monitor fails for any reason, the relay de-energizes and forces flashing red. This is a hardware-level safety guarantee independent of software.
Hint-Only Questions
Q4: How would you implement transit signal priority (TSP) that balances bus schedule adherence against general traffic delay?
Hints:
- Consider conditional vs unconditional priority (only grant priority if the bus is behind schedule)
- Think about how TSP interacts with the existing phase extension/early-return mechanisms in adaptive timing
- Consider the impact on pedestrian phases and cross-street traffic
Q5: How would you design the system to detect and respond to a "spillback" condition where queued vehicles block an upstream intersection?
Hints:
- Think about what sensor data from adjacent intersections would indicate spillback
- Consider how the controller should modify its phase timing (truncate green for the blocked direction)
- Explore how this relates to the coordination offset mechanism
Counter Questions to Ask Interviewer
-
Scale & Scope: "Are we designing a single intersection controller, or a network-wide traffic management system? This significantly affects whether we need inter-controller communication protocols."
-
Hardware Constraints: "What embedded platform are we targeting? This affects whether we can run ML-based adaptive algorithms locally or need to keep logic simple (finite state machines only)."
-
Safety Certification: "Does this system need to meet any specific safety standards (e.g., NEMA TS2, ITE ATC)? That would constrain our architecture and require formal verification of the conflict logic."
-
Failure Mode Preference: "When the system detects an unrecoverable fault, should it default to flashing red (safest but causes congestion) or attempt to continue in fixed-timing mode (less disruption but slightly higher risk)?"
-
Pedestrian Priority: "What's the priority balance between vehicle throughput and pedestrian wait time? Should we support exclusive pedestrian phases (Barnes Dance), or always run pedestrians parallel with compatible vehicle movements?"
-
Integration Requirements: "Does this need to integrate with existing traffic management systems (e.g., SCATS, SCOOT, InSync)? That would constrain our communication protocols and data formats."
References
- NEMA TS2 Standard - National Electrical Manufacturers Association standard for traffic controller assemblies and communication protocols.
- Manual on Uniform Traffic Control Devices (MUTCD) - Federal Highway Administration guidelines for signal timing, clearance intervals, and pedestrian accommodation.
- Highway Capacity Manual (HCM) - Transportation Research Board methodology for intersection capacity analysis and level-of-service calculations.
- NTCIP 1202 - National Transportation Communications for ITS Protocol for actuated signal controllers.
- Design Patterns: Elements of Reusable Object-Oriented Software - Gamma et al. (Gang of Four) - State, Observer, Strategy, Command patterns.
- Traffic Signal Timing Manual (FHWA-HOP-08-024) - Federal Highway Administration guide for signal timing optimization.
- SAE J2735 - Standard for V2X message sets including Signal Phase and Timing (SPaT) messages.
- Erta, K. et al. - "Reinforcement Learning for Adaptive Traffic Signal Control" - Survey of ML approaches to signal optimization.