<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mike Clarke</title>
    <description>The latest articles on DEV Community by Mike Clarke (@mike_clarke_50a95013f5c59).</description>
    <link>https://dev.to/mike_clarke_50a95013f5c59</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3868865%2Ff368d9be-f55c-4ab9-a26e-a73625709b2b.jpg</url>
      <title>DEV Community: Mike Clarke</title>
      <link>https://dev.to/mike_clarke_50a95013f5c59</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mike_clarke_50a95013f5c59"/>
    <language>en</language>
    <item>
      <title>How to Configure the Smart Traffic System: An Architectural Guide</title>
      <dc:creator>Mike Clarke</dc:creator>
      <pubDate>Wed, 04 Nov 2026 06:00:24 +0000</pubDate>
      <link>https://dev.to/mike_clarke_50a95013f5c59/how-to-configure-the-smart-traffic-system-an-architectural-guide-3dip</link>
      <guid>https://dev.to/mike_clarke_50a95013f5c59/how-to-configure-the-smart-traffic-system-an-architectural-guide-3dip</guid>
      <description>&lt;p&gt;Every developer thinks configuring a traffic controller is trivial until they actually have to design one. On paper, it is just cycling lights between red, yellow, and green. In reality, you are balancing concurrent telemetry streams, pedestrian interrupts, emergency vehicle overrides, and strict fail-safe guarantees.&lt;/p&gt;

&lt;p&gt;Static timer loops fail the moment a stadium lets out or an ambulance hits the grid. If you are trying to understand &lt;strong&gt;how to configure the smart traffic system&lt;/strong&gt;, you need to treat intersections as dynamic, distributed state machines rather than simple cron jobs. Here is how to approach the architecture.&lt;/p&gt;




&lt;h3&gt;
  
  
  The Core Concept: Decoupled Telemetry and Deterministic States
&lt;/h3&gt;

&lt;p&gt;A resilient smart traffic system splits into three decoupled layers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Ingestion Layer:&lt;/strong&gt; Consumes sensor inputs (loop detectors, camera object counts, pedestrian buttons, V2X emergency beacons).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rules &amp;amp; Scheduling Engine:&lt;/strong&gt; Calculates demand scores based on queue lengths, wait times, and priority classes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Actuator / Safety Layer:&lt;/strong&gt; A strict Finite State Machine (FSM) that enforces legal phase transitions (e.g., requiring clearing intervals between conflicting green lights).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To configure the system effectively, your scheduler should never mutate signal states directly. Instead, the scheduler emits &lt;em&gt;phase requests&lt;/em&gt;, and the safety controller validates them against hard constraints like minimum green time and all-red clearing intervals.&lt;/p&gt;




&lt;h3&gt;
  
  
  Orchestration Logic (Pseudocode)
&lt;/h3&gt;

&lt;p&gt;Here is a high-level representation of how to process sensor telemetry and score conflicting traffic phases before requesting an FSM state change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;structure IntersectionConfig:
    min_green_time = 10
    max_green_time = 60
    yellow_duration = 4
    all_red_clear = 2

function evaluateTrafficPhase(current_phase, sensor_stream):
    // 1. Check for critical overrides (Emergency, Transit)
    if sensor_stream.has_emergency_vehicle():
        return build_emergency_route(sensor_stream.emergency_lane)

    // 2. Aggregate demand metrics across active lanes
    phase_scores = {}
    for phase in available_phases:
        queue_depth = sensor_stream.get_vehicle_count(phase.lanes)
        wait_latency = sensor_stream.get_max_wait_seconds(phase.lanes)

        // Weight wait time to prevent lane starvation
        phase_scores[phase] = (queue_depth * 1.2) + (wait_latency * 0.8)

    target_phase = get_highest_priority(phase_scores)

    // 3. Enforce timing constraints before issuing transition
    if current_phase.elapsed_time &amp;lt; IntersectionConfig.min_green_time:
        return KEEP_CURRENT_PHASE

    if target_phase != current_phase:
        return schedule_transition(current_phase, target_phase, IntersectionConfig)

    return EXTEND_PHASE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how the scoring function incorporates both queue volume and latency. Without accounting for wait latency, a low-density cross street might never get a green light during peak rush hour on an arterial road.&lt;/p&gt;




&lt;h3&gt;
  
  
  Why Hands-On Practice Matters
&lt;/h3&gt;

&lt;p&gt;Writing pseudocode for an algorithm like this is the easy part. The real complexity surfaces when things break in production:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Race conditions:&lt;/strong&gt; What happens if an emergency vehicle preempts a phase right as the pedestrian countdown hits zero?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sensor degradation:&lt;/strong&gt; If a road sensor fails open and reports zero vehicles, does your configuration starve that lane indefinitely?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Distributed coordination:&lt;/strong&gt; Managing a single intersection is manageable; synchronizing a corridor of six intersections without causing gridlock requires green-wave timing and backpressure handling.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Reading system design posts gives you the high-level vocabulary, but you only master concurrency patterns, state management, and edge-case handling by getting your hands dirty with real scenarios.&lt;/p&gt;

&lt;p&gt;Practice this concept interactively on CodeCityApp — free trial at codecityapp.com&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codecityapp.com" rel="noopener noreferrer"&gt;CodeCityApp&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Configure the Smart Traffic System: An Architecture &amp; Implementation Guide</title>
      <dc:creator>Mike Clarke</dc:creator>
      <pubDate>Wed, 28 Oct 2026 06:00:24 +0000</pubDate>
      <link>https://dev.to/mike_clarke_50a95013f5c59/how-to-configure-the-smart-traffic-system-an-architecture-implementation-guide-3d28</link>
      <guid>https://dev.to/mike_clarke_50a95013f5c59/how-to-configure-the-smart-traffic-system-an-architecture-implementation-guide-3d28</guid>
      <description>&lt;p&gt;Static timers don't cut it anymore. If you've ever sat at an empty four-way intersection watching an empty cross-street hold a green light for 45 seconds, you know why legacy traffic systems fail. They treat variable human behavior like a deterministic cron job.&lt;/p&gt;

&lt;p&gt;Building dynamic city infrastructure demands modern software patterns. When you sit down to tackle &lt;strong&gt;how to configure the smart traffic system&lt;/strong&gt;, you aren't just toggling a few timing variables. You are designing an event-driven, distributed system capable of ingesting noisy edge telemetry, mitigating safety hazards via strict state machines, and dynamically recalculating green splits in real time. &lt;/p&gt;

&lt;p&gt;Here is how to think about the architecture, how to structure the configuration, and how to tie it all together.&lt;/p&gt;




&lt;h3&gt;
  
  
  The Core Architecture: From Telemetry to Actuation
&lt;/h3&gt;

&lt;p&gt;A resilient smart traffic system splits clean boundaries across three layers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Sensor Ingestion (The Edge):&lt;/strong&gt; Ingests events from inductive loops, thermal cameras, pedestrian buttons, and emergency vehicle optical/radio preemption transponders.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Policy Engine (Arbitration):&lt;/strong&gt; Determines phase priorities. It uses weighted queue algorithms (e.g., max-pressure control) to dynamically balance queue lengths against dwell times, preventing starvation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Safety State Machine (Actuator Layer):&lt;/strong&gt; Enforces non-negotiable physical constraints. No matter what the optimization policy calculates, this layer guarantees yellow-clearance minimums, all-red safety buffers, and conflict-phase isolation (no dual greens on intersecting paths).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When configuring the system, you define the intersection topology, timing envelopes, and sensor-to-phase bindings.&lt;/p&gt;




&lt;h3&gt;
  
  
  Configuration &amp;amp; Logic Skeleton (Pseudocode)
&lt;/h3&gt;

&lt;p&gt;Instead of hardcoding intervals, configure your intersection using an explicit schema that couples geometric phases with dynamic bounds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 1. Intersection Configuration Schema
Configuration IntersectionConfig {
    phases: [
        {
            id: "Phase_NorthSouth",
            minGreenSeconds: 10,
            maxGreenSeconds: 60,
            yellowDurationSeconds: 4,
            allRedSeconds: 2,
            conflictsWith: ["Phase_EastWest", "Phase_Pedestrian_Crosswalk"],
            sensors: ["cam_north_01", "loop_south_02"]
        },
        {
            id: "Phase_EastWest",
            minGreenSeconds: 10,
            maxGreenSeconds: 45,
            yellowDurationSeconds: 4,
            allRedSeconds: 2,
            conflictsWith: ["Phase_NorthSouth"],
            sensors: ["cam_east_01", "cam_west_01"]
        }
    ],
    emergencyPreemptionEnabled: true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, the runtime controller evaluates sensor inputs against the active phase constraints:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// 2. High-Level Controller Loop
function evaluateTrafficCycle(intersectionState, sensorStream) {
    activePhase = intersectionState.getCurrentPhase()
    elapsedTime = intersectionState.getTimeInCurrentPhase()

    // Check for high-priority preemption first
    if (sensorStream.hasEmergencyVehicle()) {
        targetPhase = sensorStream.getEmergencyTargetPhase()
        return transitionSafely(activePhase, targetPhase)
    }

    // Respect minimum safe green times
    if (elapsedTime &amp;lt; activePhase.minGreenSeconds) {
        return maintainCurrentPhase(activePhase)
    }

    // Calculate demand across competing phases
    demandScores = calculatePhaseDemands(intersectionState.getInactivePhases(), sensorStream)
    highestDemandPhase = demandScores.getTopCandidate()

    // Transition if active phase exceeded max green OR competing demand exceeds threshold
    if (elapsedTime &amp;gt;= activePhase.maxGreenSeconds or demandScores.shouldYield(activePhase)) {
        return transitionSafely(activePhase, highestDemandPhase)
    }

    return maintainCurrentPhase(activePhase)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that the optimization engine never directly switches lights. It proposes transitions to &lt;code&gt;transitionSafely()&lt;/code&gt;, which walks through yellow and all-red clearance steps deterministically.&lt;/p&gt;




&lt;h3&gt;
  
  
  Why Practice Matters: The Edge Cases Will Break You
&lt;/h3&gt;

&lt;p&gt;On paper, configuring an actuated traffic system seems straightforward: take inputs, apply weights, swap phases. &lt;/p&gt;

&lt;p&gt;In reality, edge conditions introduce dangerous failure modes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sensor dropouts:&lt;/strong&gt; What happens when an inductive loop fails open and registers infinite phantom cars?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Preemption races:&lt;/strong&gt; An ambulance heading North arrives simultaneously with a fire engine heading West.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Starvation deadlocks:&lt;/strong&gt; A high-volume arterial perpetually suppresses a low-volume side street, keeping cross-traffic trapped indefinitely.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You cannot test these failure paths safely on production hardware. Simulating concurrent sensor bursts, fail-safe defaults (like falling back to flashing red during system degradation), and state synchronization requires hands-on practice in an isolated environment.&lt;/p&gt;




&lt;h3&gt;
  
  
  Build and Test It Yourself
&lt;/h3&gt;

&lt;p&gt;Theory gets you started, but writing the control logic and stress-testing it against asynchronous edge events is where real distributed systems engineering happens.&lt;/p&gt;

&lt;p&gt;Practice this concept interactively on CodeCityApp — free trial at codecityapp.com&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codecityapp.com" rel="noopener noreferrer"&gt;CodeCityApp&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Configure the Smart Traffic System: A Developer's Guide</title>
      <dc:creator>Mike Clarke</dc:creator>
      <pubDate>Wed, 21 Oct 2026 06:00:26 +0000</pubDate>
      <link>https://dev.to/mike_clarke_50a95013f5c59/how-to-configure-the-smart-traffic-system-a-developers-guide-381f</link>
      <guid>https://dev.to/mike_clarke_50a95013f5c59/how-to-configure-the-smart-traffic-system-a-developers-guide-381f</guid>
      <description>&lt;p&gt;Static timers for traffic intersections belong in the 1990s. If you've ever found yourself waiting at an empty crossroad at 2:00 AM while a red light counts down from 45 seconds, you know why dynamic traffic routing is a critical engineering problem.&lt;/p&gt;

&lt;p&gt;Modern intersections require distributed event ingestion, state machines, and dynamic priority scheduling. When engineering teams ask &lt;strong&gt;how to configure the smart traffic system&lt;/strong&gt;, they aren't looking for a basic hardware manual—they need to know how to structure the control loop, manage sensor telemetry, and safely handle edge cases like emergency vehicle preemption without deadlocking an entire sector.&lt;/p&gt;

&lt;p&gt;Here is how to configure a reactive, resilient smart traffic control system from the ground up.&lt;/p&gt;




&lt;h3&gt;
  
  
  The Core Architecture: Three Decoupled Layers
&lt;/h3&gt;

&lt;p&gt;To configure an effective smart traffic system, avoid tightly coupling sensor inputs directly to actuation outputs. Instead, organize the controller around three decoupled tiers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Sensor Ingestion Layer:&lt;/strong&gt; Ingests live telemetry from inductive road loops, camera-based object detection, and connected-vehicle beacon endpoints (e.g., MQTT or WebSockets).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decision &amp;amp; Arbitration Engine:&lt;/strong&gt; A finite state machine (FSM) that evaluates dynamic weights—combining queue depth, wait duration, and vehicle classification (e.g., priority for transit buses or sirens).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Actuation &amp;amp; Safety Layer:&lt;/strong&gt; Validates proposed state transitions against hard safety constraints (minimum green times, mandatory yellow clearance, all-red intervals) before sending commands to physical controllers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When configuring parameters, your configuration file should separate &lt;em&gt;hard safety invariants&lt;/em&gt; from &lt;em&gt;tunable heuristic weights&lt;/em&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Architectural Pseudocode: The Dynamic Decision Loop
&lt;/h3&gt;

&lt;p&gt;Here is how the core control loop evaluates dynamic inputs to determine the next phase:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CONFIGURATION IntersectionConfig:
    MIN_GREEN_TIME = 10s
    MAX_GREEN_TIME = 60s
    YELLOW_CLEARANCE = 4s
    EMERGENCY_OVERRIDE_WEIGHT = 1000
    TRANSIT_PRIORITY_WEIGHT = 20

FUNCTION EvaluateNextPhase(intersectionState, sensorFeeds):
    // 1. Check safety constraint: Has active phase met minimum duration?
    IF intersectionState.activePhase.elapsedTime &amp;lt; MIN_GREEN_TIME:
        RETURN intersectionState.activePhase

    // 2. Score pending phases based on live metrics
    phaseScores = NEW Map()
    FOR EACH phase IN intersectionState.candidatePhases:
        densityScore = sensorFeeds.getVehicleCount(phase.laneGroup)
        waitTimePenalty = sensorFeeds.getOldestWaitingSeconds(phase.laneGroup) * 1.5
        priorityBoost = 0

        IF sensorFeeds.hasEmergencyVehicle(phase.laneGroup):
            priorityBoost += EMERGENCY_OVERRIDE_WEIGHT
        ELSE IF sensorFeeds.hasPublicTransit(phase.laneGroup):
            priorityBoost += TRANSIT_PRIORITY_WEIGHT

        phaseScores[phase.id] = densityScore + waitTimePenalty + priorityBoost

    // 3. Select phase with highest demand
    selectedPhase = phaseScores.getHighestScoringPhase()

    // 4. Trigger transition if demand shifts or max green reached
    IF selectedPhase != intersectionState.activePhase OR intersectionState.activePhase.elapsedTime &amp;gt;= MAX_GREEN_TIME:
        RETURN InitiateTransition(intersectionState.activePhase, selectedPhase, YELLOW_CLEARANCE)

    RETURN intersectionState.activePhase
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your deployment, this logic runs inside an isolated worker loop, isolated from volatile network I/O to guarantee real-time tick execution.&lt;/p&gt;




&lt;h3&gt;
  
  
  Why Hands-On Practice Matters
&lt;/h3&gt;

&lt;p&gt;Designing traffic systems on a whiteboard looks deceptively simple. In production, concurrency breaks assumptions fast.&lt;/p&gt;

&lt;p&gt;What happens when two ambulances approach conflicting lanes simultaneously? What happens when a camera feed drops out and sends stale zero-occupancy metrics? How does your system transition gracefully into a degraded failsafe state (like an all-way flashing yellow/red)?&lt;/p&gt;

&lt;p&gt;Reading architectural docs gives you the theory, but you only master event-driven state machines and real-time scheduling by simulating traffic flows, injecting edge-case faults, and refactoring your controllers under load.&lt;/p&gt;

&lt;p&gt;Practice this concept interactively on CodeCityApp — free trial at codecityapp.com&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codecityapp.com" rel="noopener noreferrer"&gt;CodeCityApp&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Mastering the Flow: How to Configure a Smart Traffic System</title>
      <dc:creator>Mike Clarke</dc:creator>
      <pubDate>Wed, 16 Sep 2026 06:00:18 +0000</pubDate>
      <link>https://dev.to/mike_clarke_50a95013f5c59/mastering-the-flow-how-to-configure-a-smart-traffic-system-321e</link>
      <guid>https://dev.to/mike_clarke_50a95013f5c59/mastering-the-flow-how-to-configure-a-smart-traffic-system-321e</guid>
      <description>&lt;p&gt;Hey folks!&lt;/p&gt;

&lt;p&gt;Ever found yourself stuck in a gridlocked city, wishing someone had a better handle on the traffic lights? Or maybe you've worked on a distributed system and realized that managing resource contention is a lot like optimizing traffic flow. In either case, the problem is real: &lt;strong&gt;how to configure a smart traffic system&lt;/strong&gt; to keep things moving efficiently, prevent bottlenecks, and adapt to changing conditions.&lt;/p&gt;

&lt;p&gt;Traditional traffic light systems are often time-based, cycling through greens and reds without much regard for actual vehicle presence or density. Smart traffic systems, on the other hand, are dynamic. They leverage sensors, data analytics, and often AI/ML to make real-time decisions, optimizing flow, reducing emissions, and improving safety. For us developers, this isn't just about civic planning; it's a fascinating challenge in distributed systems, real-time data processing, and intelligent control.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Core Concept: Dynamic Optimization
&lt;/h3&gt;

&lt;p&gt;At its heart, configuring a smart traffic system involves creating an intelligent agent that can observe traffic conditions, predict future states, and issue commands to traffic signals. Think of it as a control loop:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Observe:&lt;/strong&gt; Gather data from sensors (e.g., inductive loops, cameras, lidar) at intersections, detecting vehicle presence, speed, and queue length.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Analyze &amp;amp; Predict:&lt;/strong&gt; Process this data. Are there long queues on one road? Is an emergency vehicle approaching? Use algorithms to predict future traffic density and potential congestion points.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Decide:&lt;/strong&gt; Based on analysis, determine the optimal signal timings for each phase at an intersection, or even coordinate multiple intersections. This might involve optimizing for minimal waiting time, maximum throughput, or priority for certain vehicles.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Act:&lt;/strong&gt; Send commands to the traffic light controllers to adjust their patterns.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This cycle repeats continuously, adapting to the ebb and flow of urban life. The 'smart' part comes from the complexity of the decision-making logic, often involving techniques like reinforcement learning, genetic algorithms, or even simple heuristic-based rules. The challenge is balancing conflicting demands – giving green to one direction often means red for another. It's a zero-sum game that needs careful arbitration.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pseudocode: A Glimpse into the Brain
&lt;/h3&gt;

&lt;p&gt;Let's sketch out a very simplified conceptual model for a single intersection with four approaches (North, East, South, West):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;CLASS TrafficController:
    ATTRIBUTES:
        sensors: Map&amp;lt;Direction, List&amp;lt;SensorData&amp;gt;&amp;gt;  // Vehicle counts, speeds per lane
        signals: Map&amp;lt;Direction, TrafficSignal&amp;gt; // Green, Yellow, Red states
        current_phase: TrafficPhase // e.g., N-S Green, E-W Red
        phase_timer: Timer
        min_green_time: Integer
        max_green_time: Integer

    METHOD initialize():
        SET current_phase = default_phase
        START phase_timer with min_green_time

    METHOD update_traffic_data(new_sensor_data):
        sensors.update(new_sensor_data)

    METHOD decide_next_phase():
        IF phase_timer.elapsed() &amp;gt;= min_green_time THEN
            // Calculate priority scores for each potential next phase
            priority_scores = calculate_priority_for_all_phases(sensors.data)

            // Example: Prioritize phase with highest queue length
            next_phase_candidate = find_phase_with_highest_priority(priority_scores)

            IF next_phase_candidate != current_phase AND 
               phase_timer.elapsed() &amp;gt;= calculate_optimal_duration(current_phase, sensors.data) THEN
                INITIATE transition_to_phase(next_phase_candidate)
            ELSE IF phase_timer.elapsed() &amp;gt;= max_green_time THEN
                // Force transition if max green time reached
                INITIATE transition_to_phase(next_phase_candidate)
            END IF
        END IF

    METHOD transition_to_phase(new_phase):
        signals.set_yellow(current_phase) // Short yellow transition
        WAIT for yellow_duration
        signals.set_red(current_phase)
        signals.set_green(new_phase)
        SET current_phase = new_phase
        RESTART phase_timer

    METHOD calculate_priority_for_all_phases(data):
        // This is where the 'smart' algorithms go:
        // - Count vehicles waiting for each phase
        // - Consider emergency vehicle alerts
        // - Factor in pedestrian requests
        // - Apply weighted heuristics or ML model predictions
        RETURN map_of_phase_to_priority_score

    METHOD calculate_optimal_duration(current_phase, data):
        // Determine how long the current green should extend
        // - Based on current queue reduction
        // - Anticipated incoming traffic
        RETURN duration_in_seconds
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This pseudocode scratches the surface. A real system would involve networking, fault tolerance, multi-intersection coordination, and a robust data pipeline. But it illustrates the core decision-making loop.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Practice Matters in Smart Systems
&lt;/h3&gt;

&lt;p&gt;Reading about smart traffic systems is one thing; actually designing and configuring one is another. The devil is in the details: sensor accuracy, latency in communication, the subtle tuning of algorithms to avoid oscillation (e.g., lights flipping too quickly), and handling edge cases like sensor failures or sudden spikes in traffic. You need to understand how your decisions impact the system's behavior, often in non-obvious ways.&lt;/p&gt;

&lt;p&gt;Experimenting with different configuration parameters, testing various algorithms, and seeing their impact on simulated traffic flow is crucial. It’s where you truly internalize the trade-offs and complexities involved in making a system &lt;em&gt;truly&lt;/em&gt; smart and resilient. This kind of hands-on experience builds intuition that no amount of theoretical reading can replace.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ready to Build Smarter Cities?
&lt;/h3&gt;

&lt;p&gt;The journey from concept to a functioning smart traffic system is filled with intriguing challenges. It's a perfect playground for applying your programming and problem-solving skills to real-world, impactful problems. Get your hands dirty, tweak some parameters, and see the digital cars flow!&lt;/p&gt;

&lt;p&gt;Practice this concept interactively on CodeCityApp — free trial at codecityapp.com&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codecityapp.com" rel="noopener noreferrer"&gt;CodeCityApp&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Smart Traffic Configuration: Your Guide to Smarter City Systems</title>
      <dc:creator>Mike Clarke</dc:creator>
      <pubDate>Wed, 09 Sep 2026 06:00:17 +0000</pubDate>
      <link>https://dev.to/mike_clarke_50a95013f5c59/smart-traffic-configuration-your-guide-to-smarter-city-systems-5eda</link>
      <guid>https://dev.to/mike_clarke_50a95013f5c59/smart-traffic-configuration-your-guide-to-smarter-city-systems-5eda</guid>
      <description>&lt;h1&gt;
  
  
  Smart Traffic Configuration: Your Guide to Smarter City Systems
&lt;/h1&gt;

&lt;p&gt;Hey fellow developers,&lt;/p&gt;

&lt;p&gt;Ever found yourself stuck in a gridlock, wishing the traffic lights just &lt;em&gt;knew&lt;/em&gt; what was going on? Or maybe you've tried to navigate a city during peak hour and felt like the urban planning was stuck in the last century. That's not just a personal frustration; it's a massive, real-world problem that smart traffic systems aim to solve. And as developers, we're the ones building them.&lt;/p&gt;

&lt;p&gt;Today, we're diving into the nitty-gritty of &lt;strong&gt;how to configure the smart traffic system&lt;/strong&gt; – not just the theoretical 'what if', but the practical 'how-to' that moves us closer to dynamic, responsive urban infrastructure.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Gridlock Problem: Why Smart Traffic Matters
&lt;/h2&gt;

&lt;p&gt;Traditional traffic systems are often static, time-based, or rely on simple loop detectors. They don't adapt well to unexpected events like accidents, sudden influxes of vehicles due to a concert, or even just daily fluctuations in commute patterns. The result? Wasted fuel, increased pollution, stressed commuters, and lost productivity.&lt;/p&gt;

&lt;p&gt;Smart traffic systems, on the other hand, leverage data, algorithms, and real-time communication to optimize traffic flow. They're about making decisions on the fly, reducing congestion, and improving safety. From intelligent signal timing to adaptive route guidance, these systems are the brains behind a smoother, greener city.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Core Concepts: What Are We Configuring?
&lt;/h2&gt;

&lt;p&gt;At its heart, configuring a smart traffic system involves setting up rules, parameters, and algorithms that dictate how traffic lights, signs, and even autonomous vehicles interact. Here are the key components we typically configure:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Sensor Data Ingestion:&lt;/strong&gt; This is the input. We're talking about data from cameras (vehicle counts, speed, occupancy), inductive loops, GPS trackers, and even mobile device data. The system needs to know &lt;em&gt;what's happening now&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Traffic Light Control Logic:&lt;/strong&gt; This is the brain. Instead of fixed timers, we implement dynamic algorithms. These might be based on machine learning models predicting congestion, optimization algorithms like greedy approaches, or even reinforcement learning agents that 'learn' optimal signal timings.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Prioritization Rules:&lt;/strong&gt; Think emergency vehicles, public transport, or high-volume thoroughfares. We configure priorities to ensure critical movements are facilitated.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Network-wide Optimization:&lt;/strong&gt; It's not just about one intersection; it's about optimizing flow across an entire urban grid. This involves coordinating signals between adjacent intersections to create 'green waves' and prevent blockages downstream.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Anomaly Detection &amp;amp; Response:&lt;/strong&gt; Configuration includes rules for identifying incidents (accidents, stalled vehicles) and triggering appropriate responses, such as adjusting signal timings, displaying alerts on variable message signs, or dispatching emergency services.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Simulation &amp;amp; Testing Parameters:&lt;/strong&gt; Before deploying anything live, we simulate various scenarios. Configuring these simulation environments and tuning parameters is crucial for validation.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Pseudocode: A Glimpse into Dynamic Signal Control
&lt;/h2&gt;

&lt;p&gt;Let's consider a simplified pseudocode example for dynamic signal timing at a single intersection based on vehicle counts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// System Configuration Variables
SET MIN_GREEN_TIME = 15 // seconds
SET MAX_GREEN_TIME = 60 // seconds
SET DETECTION_INTERVAL = 5 // seconds, how often sensors are read
SET CONGESTION_THRESHOLD = 20 // vehicles, for a lane

// Intersection State
DECLARE current_phase = 'NORTH_SOUTH'
DECLARE north_south_vehicle_count = 0
DECLARE east_west_vehicle_count = 0
DECLARE phase_timer = 0

// Main Loop for Traffic Light Controller
FUNCTION run_traffic_controller():
  WHILE TRUE:
    // Read sensor data
    north_south_vehicle_count = GET_SENSOR_DATA('NORTH_SOUTH_APPROACH')
    east_west_vehicle_count = GET_SENSOR_DATA('EAST_WEST_APPROACH')

    // Increment phase timer
    phase_timer = phase_timer + DETECTION_INTERVAL

    IF current_phase == 'NORTH_SOUTH':
      IF phase_timer &amp;gt;= MIN_GREEN_TIME:
        IF east_west_vehicle_count &amp;gt; CONGESTION_THRESHOLD AND north_south_vehicle_count &amp;lt; (east_west_vehicle_count / 2):
          // Switch to East-West if heavy congestion there and NS is light
          TRIGGER_YELLOW_LIGHT('NORTH_SOUTH')
          WAIT(3) // Yellow light duration
          current_phase = 'EAST_WEST'
          phase_timer = 0
        ELSE IF phase_timer &amp;gt;= MAX_GREEN_TIME:
          // Force switch if max green time reached
          TRIGGER_YELLOW_LIGHT('NORTH_SOUTH')
          WAIT(3)
          current_phase = 'EAST_WEST'
          phase_timer = 0
      END IF
      SET_LIGHTS('NORTH_SOUTH', 'GREEN')
      SET_LIGHTS('EAST_WEST', 'RED')

    ELSE IF current_phase == 'EAST_WEST':
      IF phase_timer &amp;gt;= MIN_GREEN_TIME:
        IF north_south_vehicle_count &amp;gt; CONGESTION_THRESHOLD AND east_west_vehicle_count &amp;lt; (north_south_vehicle_count / 2):
          // Switch to North-South
          TRIGGER_YELLOW_LIGHT('EAST_WEST')
          WAIT(3)
          current_phase = 'NORTH_SOUTH'
          phase_timer = 0
        ELSE IF phase_timer &amp;gt;= MAX_GREEN_TIME:
          // Force switch
          TRIGGER_YELLOW_LIGHT('EAST_WEST')
          WAIT(3)
          current_phase = 'NORTH_SOUTH'
          phase_timer = 0
      END IF
      SET_LIGHTS('EAST_WEST', 'GREEN')
      SET_LIGHTS('NORTH_SOUTH', 'RED')

    WAIT(DETECTION_INTERVAL)
  END WHILE
END FUNCTION
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This pseudocode illustrates a basic reactive system. Real-world systems are far more complex, incorporating predictive models, multi-intersection coordination, and robust error handling. But the fundamental idea is to use data to dynamically adjust parameters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Practice Configuration Matters
&lt;/h2&gt;

&lt;p&gt;Reading about &lt;code&gt;MIN_GREEN_TIME&lt;/code&gt; or &lt;code&gt;CONGESTION_THRESHOLD&lt;/code&gt; is one thing; actually seeing how changes to these values impact traffic flow is another. Misconfiguring a smart traffic system can have disastrous consequences – creating new bottlenecks, increasing accident risk, or even bringing a city to a standstill. That's why hands-on practice, experimentation in a safe environment, and understanding the nuances of parameter tuning are absolutely essential for any developer working in this domain.&lt;/p&gt;

&lt;p&gt;Experimenting with different algorithms, tweaking thresholds, and observing the system's response in various simulated scenarios builds intuition and expertise that no amount of theoretical reading can provide. It prepares you for the complex, ever-changing demands of urban environments.&lt;/p&gt;

&lt;p&gt;Practice this concept interactively on CodeCityApp — free trial at codecityapp.com&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codecityapp.com" rel="noopener noreferrer"&gt;CodeCityApp&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Demystifying Smart Traffic: How to Configure an Intelligent System</title>
      <dc:creator>Mike Clarke</dc:creator>
      <pubDate>Wed, 02 Sep 2026 06:00:15 +0000</pubDate>
      <link>https://dev.to/mike_clarke_50a95013f5c59/demystifying-smart-traffic-how-to-configure-an-intelligent-system-blc</link>
      <guid>https://dev.to/mike_clarke_50a95013f5c59/demystifying-smart-traffic-how-to-configure-an-intelligent-system-blc</guid>
      <description>&lt;p&gt;Hey fellow devs!&lt;/p&gt;

&lt;p&gt;Ever found yourself stuck in a gridlock, wishing the traffic lights just &lt;em&gt;knew&lt;/em&gt; what was going on? That’s not just a pipe dream; it's the very problem we're solving with &lt;strong&gt;smart traffic systems&lt;/strong&gt;. Configuring one isn't about simply setting timers; it's about building an intelligent, adaptive network that responds to real-time conditions. This isn't just theory – it's a fascinating challenge that blends data science, IoT, and control systems.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Problem: Static Traffic Control is Obsolete
&lt;/h3&gt;

&lt;p&gt;Traditional traffic light systems operate on fixed cycles, often optimized for peak hours or historical averages. But what happens when there's an accident, a sudden surge in pedestrian traffic, or a special event? These static systems fail spectacularly, leading to congestion, increased pollution, and frustrated commuters. As cities grow, the inefficiency compounds, making a strong case for dynamic, intelligent solutions.&lt;/p&gt;

&lt;p&gt;Our mission, should we choose to accept it, is to build a system that can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Sense:&lt;/strong&gt; Gather real-time data from various sources.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Analyze:&lt;/strong&gt; Process that data to understand current traffic flow and predict future trends.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Adapt:&lt;/strong&gt; Dynamically adjust traffic signals and other controls to optimize flow.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Learn:&lt;/strong&gt; Improve its performance over time through machine learning.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Concept: An Adaptive Ecosystem
&lt;/h3&gt;

&lt;p&gt;At its core, configuring a smart traffic system means orchestrating a symphony of sensors, data pipelines, decision-making algorithms, and actuators. Think of it like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Ingestion (The Eyes and Ears):&lt;/strong&gt; This is where real-time information streams in. We're talking about magnetic loop detectors embedded in the road, cameras performing vehicle counting and classification (potentially even recognizing emergency vehicles), GPS data from connected vehicles, pedestrian sensors, and even weather reports.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Processing &amp;amp; Fusion (The Brain's Cortex):&lt;/strong&gt; Raw sensor data is noisy and disparate. We need to clean, normalize, and combine it. This might involve spatial temporal analysis to understand traffic density across junctions, identifying queues, and calculating average speeds. Edge computing can play a vital role here, processing data closer to the source to reduce latency.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Decision-Making Engine (The Logic Core):&lt;/strong&gt; This is where the 'smart' truly happens. Algorithms, ranging from simple rule-based systems to complex Reinforcement Learning (RL) agents, take the processed data and decide the optimal course of action. Should the green light duration on Main Street be extended? Should a turn lane be prioritized? This engine aims to minimize overall travel time, reduce idle time, and manage congestion.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Actuation &amp;amp; Feedback (The Hands and Mouth):&lt;/strong&gt; Once a decision is made, commands are sent to the traffic signal controllers, variable message signs, or even integrated public transport systems. The system then continuously monitors the impact of its decisions, feeding new data back into the cycle for continuous improvement.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  A Glimpse into the Code: The Decision-Making Loop (Pseudocode)
&lt;/h3&gt;

&lt;p&gt;Let’s imagine a simplified decision engine for a single intersection. This pseudocode demonstrates the iterative nature of the system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FUNCTION configureSmartTrafficSystem():
    INITIALIZE trafficSignalControllers
    INITIALIZE dataAggregator
    INITIALIZE decisionEngine
    INITIALIZE learningModule

    WHILE systemIsRunning:
        // 1. Gather Real-time Data
        trafficData = dataAggregator.collectSensorData()

        // 2. Process and Analyze Data
        processedTrafficState = decisionEngine.analyzeTrafficState(trafficData)

        // 3. Make a Decision
        IF learningModule.isReadyForAdvancedDecision():
            // Use RL or predictive models for complex scenarios
            newSignalPlan = learningModule.predictOptimalSignalPlan(processedTrafficState)
        ELSE:
            // Fallback to rule-based or simpler algorithms
            newSignalPlan = decisionEngine.calculateRuleBasedSignalPlan(processedTrafficState)
        END IF

        // 4. Actuate Control
        trafficSignalControllers.applySignalPlan(newSignalPlan)

        // 5. Monitor and Learn (asynchronously or in background)
        performanceMetrics = trafficSignalControllers.getPerformanceMetrics()
        learningModule.updateModel(processedTrafficState, newSignalPlan, performanceMetrics)

        WAIT_FOR_NEXT_CYCLE_OR_EVENT()
    END WHILE
END FUNCTION

// Example of a dataAggregator method
CLASS DataAggregator:
    METHOD collectSensorData():
        sensorReadings = {}
        FOR EACH sensor IN listOfSensors:
            sensorReadings[sensor.id] = sensor.readData()
        END FOR
        RETURN sensorReadings
END CLASS

// Example of a simple rule-based decision engine method
CLASS DecisionEngine:
    METHOD calculateRuleBasedSignalPlan(state):
        IF state.majorRoadQueueLength &amp;gt; state.minorRoadQueueLength * 2:
            RETURN { 'majorRoadGreenDuration': 60, 'minorRoadGreenDuration': 15 }
        ELSE IF state.pedestrianCrossingsRequested:
            RETURN { 'pedestrianCrossWalkTime': 20, 'vehicleLightsRed': True }
        ELSE:
            RETURN { 'majorRoadGreenDuration': 30, 'minorRoadGreenDuration': 30 }
        END IF
    END METHOD
END CLASS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This isn't a full solution, but it illustrates the logical flow: sense, process, decide, act, and learn. Each component can be a complex system in itself, using everything from Kafka streams for data ingestion to TensorFlow for deep reinforcement learning.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Practice Matters in This Domain
&lt;/h3&gt;

&lt;p&gt;Understanding these concepts abstractly is one thing; actually seeing how data flows, how algorithms react to changing conditions, and how different configurations impact system performance is another. Traffic simulation environments are invaluable here. They allow you to experiment with different sensor placements, test various decision algorithms (e.g., comparing fixed-time, actuated, and AI-driven approaches), and observe the emergent behavior of the system under diverse traffic patterns without deploying a single sensor in the real world.&lt;/p&gt;

&lt;p&gt;This hands-on approach helps you grasp the nuances of latency, data integrity, algorithm tuning, and the sheer complexity of optimizing for multiple, often conflicting, objectives (e.g., minimizing average wait time vs. ensuring emergency vehicle priority).&lt;/p&gt;

&lt;p&gt;Configuring a smart traffic system is a multidisciplinary engineering feat. It's challenging, but incredibly rewarding, as you're directly contributing to more efficient, sustainable, and livable cities.&lt;/p&gt;

&lt;p&gt;Practice this concept interactively on CodeCityApp — free trial at codecityapp.com&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codecityapp.com" rel="noopener noreferrer"&gt;CodeCityApp&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Your AI generated hundreds of pieces of content. None of it ever shipped.</title>
      <dc:creator>Mike Clarke</dc:creator>
      <pubDate>Fri, 14 Aug 2026 14:00:06 +0000</pubDate>
      <link>https://dev.to/mike_clarke_50a95013f5c59/your-ai-generated-hundreds-of-pieces-of-content-none-of-it-ever-shipped-4o44</link>
      <guid>https://dev.to/mike_clarke_50a95013f5c59/your-ai-generated-hundreds-of-pieces-of-content-none-of-it-ever-shipped-4o44</guid>
      <description>&lt;p&gt;Your AI generated hundreds of pieces of content. None of it ever shipped.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A queue in a &lt;code&gt;ready&lt;/code&gt; state is not done. Done means consumed and delivered.&lt;/li&gt;
&lt;li&gt;Generation and publication are two separate stages. An automated bridge between them is not optional.&lt;/li&gt;
&lt;li&gt;Any queue without a consumer and a depth alert is a silent failure waiting to accumulate.&lt;/li&gt;
&lt;li&gt;"The work looks done" is the most dangerous state in an autonomous system.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;In ARIA — the autonomous content operations system we run at Elevare Digital — we watched two queues quietly fill up over time. Content was being generated. It was landing in the database in a &lt;code&gt;ready&lt;/code&gt; state. Every upstream metric looked fine.&lt;/p&gt;

&lt;p&gt;None of it ever reached the destination. Not a single item.&lt;/p&gt;

&lt;p&gt;The root cause was not a bug. It was a design assumption that never got questioned: publication was a manual step, and nobody ran it.&lt;/p&gt;




&lt;h2&gt;
  
  
  What the system looked like
&lt;/h2&gt;

&lt;p&gt;ARIA's content pipeline has two distinct stages. Stage one: generation. The agents do their work, write the content, and mark the row &lt;code&gt;ready&lt;/code&gt;. Stage two: publication. Something takes those &lt;code&gt;ready&lt;/code&gt; rows and pushes them out.&lt;/p&gt;

&lt;p&gt;Stage one was fully automated. Stage two was manual by design — a decision that made sense early on when we wanted a human in the loop before anything shipped publicly.&lt;/p&gt;

&lt;p&gt;The problem is that "manual by design" eventually became "never runs." There was no consumer process watching the queue. There was no alert watching the queue depth. The count just grew.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- What we were looking at in Supabase:&lt;/span&gt;
&lt;span class="c1"&gt;-- content_queue table, simplified&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;content_queue&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="n"&gt;gen_random_uuid&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="n"&gt;content_id&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt; &lt;span class="k"&gt;REFERENCES&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="nb"&gt;text&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="s1"&gt;'pending'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;-- statuses: pending | generating | ready | published | failed&lt;/span&gt;
  &lt;span class="n"&gt;created_at&lt;/span&gt; &lt;span class="n"&gt;timestamptz&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="n"&gt;updated_at&lt;/span&gt; &lt;span class="n"&gt;timestamptz&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;-- The generation side was automated and ran correctly.&lt;/span&gt;
&lt;span class="c1"&gt;-- Items moved from 'pending' -&amp;gt; 'generating' -&amp;gt; 'ready'.&lt;/span&gt;
&lt;span class="c1"&gt;-- Nothing moved them from 'ready' -&amp;gt; 'published'.&lt;/span&gt;
&lt;span class="c1"&gt;-- The query below returned a number that kept growing:&lt;/span&gt;

&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;content_queue&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'ready'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That count was not a success metric. It was a backlog. We were reading it as one and ignoring the other.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why this is easy to miss
&lt;/h2&gt;

&lt;p&gt;When you look at a pipeline dashboard and see items flowing into &lt;code&gt;ready&lt;/code&gt;, it feels like progress. The agents are working. The generation numbers are up. The logs are clean.&lt;/p&gt;

&lt;p&gt;The gap between &lt;code&gt;ready&lt;/code&gt; and &lt;code&gt;published&lt;/code&gt; is invisible unless you specifically instrument it. We hadn't. There was no metric on queue depth over time, no alert threshold, nothing that would fire if &lt;code&gt;ready&lt;/code&gt; stopped draining.&lt;/p&gt;

&lt;p&gt;This is the specific failure mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Pseudocode for what ARIA's generation side was doing — correctly:&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;generateContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jobId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;updateStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jobId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;generating&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;runGenerationAgents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jobId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;saveContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;updateStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;jobId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ready&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// &amp;lt;-- work stops here&lt;/span&gt;
  &lt;span class="c1"&gt;// Nothing downstream is listening. This is a dead end.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// What the publication side needed but didn't have:&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;publishConsumer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// This function did not exist as an automated process.&lt;/span&gt;
  &lt;span class="c1"&gt;// It existed as a manual script someone had to remember to run.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;readyItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getItemsByStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ready&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;readyItems&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;publish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;updateStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;published&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The generation function had no idea there was no consumer on the other end. It just kept doing its job.&lt;/p&gt;




&lt;h2&gt;
  
  
  The fix: every queue gets a consumer and a depth alert
&lt;/h2&gt;

&lt;p&gt;The rule we applied after this: no queue exists without two things attached to it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An automated consumer that drains it.&lt;/li&gt;
&lt;li&gt;A depth alert that fires if items in a terminal-waiting state (like &lt;code&gt;ready&lt;/code&gt;) exceed a threshold for too long.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The consumer can be a Deno edge function on a schedule, a Supabase pg_cron job, a webhook trigger — the mechanism matters less than the guarantee that &lt;em&gt;something&lt;/em&gt; is watching and pulling.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- pg_cron job that checks for stranded 'ready' items&lt;/span&gt;
&lt;span class="c1"&gt;-- and alerts if the queue hasn't drained&lt;/span&gt;

&lt;span class="c1"&gt;-- First, a view that makes the staleness visible:&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;VIEW&lt;/span&gt; &lt;span class="n"&gt;stranded_content&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;content_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;updated_at&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;updated_at&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;time_in_state&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;content_queue&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt;
  &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'ready'&lt;/span&gt;
  &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;updated_at&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;INTERVAL&lt;/span&gt; &lt;span class="s1"&gt;'2 hours'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- Then a function that pages someone if this view has rows:&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;OR&lt;/span&gt; &lt;span class="k"&gt;REPLACE&lt;/span&gt; &lt;span class="k"&gt;FUNCTION&lt;/span&gt; &lt;span class="n"&gt;alert_on_stranded_queue&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;RETURNS&lt;/span&gt; &lt;span class="n"&gt;void&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="err"&gt;$$&lt;/span&gt;
&lt;span class="k"&gt;DECLARE&lt;/span&gt;
  &lt;span class="n"&gt;stranded_count&lt;/span&gt; &lt;span class="nb"&gt;integer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;BEGIN&lt;/span&gt;
  &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;stranded_count&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;stranded_content&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;IF&lt;/span&gt; &lt;span class="n"&gt;stranded_count&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
    &lt;span class="c1"&gt;-- Call your alerting mechanism here.&lt;/span&gt;
    &lt;span class="c1"&gt;-- We use a Supabase edge function that posts to our ops channel.&lt;/span&gt;
    &lt;span class="n"&gt;PERFORM&lt;/span&gt; &lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;http_post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;current_setting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'app.alert_webhook_url'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json_build_object&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s1"&gt;'message'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'%s items stranded in ready state'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stranded_count&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="s1"&gt;'severity'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'warning'&lt;/span&gt;
      &lt;span class="p"&gt;)::&lt;/span&gt;&lt;span class="nb"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'{"Content-Type": "application/json"}'&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;END&lt;/span&gt; &lt;span class="n"&gt;IF&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;END&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;$$&lt;/span&gt; &lt;span class="k"&gt;LANGUAGE&lt;/span&gt; &lt;span class="n"&gt;plpgsql&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- Schedule it:&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;cron&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;schedule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="s1"&gt;'check-stranded-queue'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s1"&gt;'*/30 * * * *'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;-- every 30 minutes&lt;/span&gt;
  &lt;span class="s1"&gt;'SELECT alert_on_stranded_queue()'&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The threshold and interval depend on your expected throughput. The point is that a human gets paged before the count becomes embarrassing.&lt;/p&gt;




&lt;h2&gt;
  
  
  The lesson isn't about the bug
&lt;/h2&gt;

&lt;p&gt;This wasn't a bug in the traditional sense. The code did exactly what it was written to do. Generation worked. The &lt;code&gt;ready&lt;/code&gt; status was accurate. The manual publication step was documented.&lt;/p&gt;

&lt;p&gt;The failure was architectural: we treated "generated" as a proxy for "shipped" without building anything to enforce the difference.&lt;/p&gt;

&lt;p&gt;In an autonomous pipeline, every state transition needs an owner. If the transition from &lt;code&gt;ready&lt;/code&gt; to &lt;code&gt;published&lt;/code&gt; requires a human action, then the system needs to &lt;em&gt;demand&lt;/em&gt; that action — not wait quietly while the queue fills.&lt;/p&gt;

&lt;p&gt;A full queue is not progress. It's generated work that went nowhere. The two look identical from the outside until you add the one metric that matters: how long has this item been waiting, and who knows about it?&lt;/p&gt;




&lt;p&gt;&lt;em&gt;— Mike Clarke, founder of Elevare Digital.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>coding</category>
      <category>webdev</category>
      <category>learning</category>
    </item>
    <item>
      <title>Configuring Smart Traffic Systems: A Developer's Deep Dive</title>
      <dc:creator>Mike Clarke</dc:creator>
      <pubDate>Wed, 12 Aug 2026 06:00:21 +0000</pubDate>
      <link>https://dev.to/mike_clarke_50a95013f5c59/configuring-smart-traffic-systems-a-developers-deep-dive-4i64</link>
      <guid>https://dev.to/mike_clarke_50a95013f5c59/configuring-smart-traffic-systems-a-developers-deep-dive-4i64</guid>
      <description>&lt;p&gt;As developers, we often tackle complex problems, and few are as dynamic and critical as managing urban traffic. The constant ebb and flow of vehicles, pedestrians, and public transport presents a fascinating challenge. If you've ever stared at a gridlocked intersection and thought, "There has to be a better way," then you're already thinking like a smart traffic system architect. Today, we're diving into &lt;strong&gt;how to configure a smart traffic system&lt;/strong&gt; – not just the fancy AI, but the foundational logic that makes it tick.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Gridlock Dilemma: Why Smart Systems Matter
&lt;/h3&gt;

&lt;p&gt;Traditional traffic light systems are, for the most part, static. They operate on pre-defined timers, regardless of actual traffic density. This leads to frustrating scenarios: an empty main road gets a long green light while a dozen cars wait impatiently on a side street, or vice-versa. This inefficiency isn't just annoying; it costs time, wastes fuel, increases pollution, and can even delay emergency services.&lt;/p&gt;

&lt;p&gt;The goal of a smart traffic system is to move beyond these fixed schedules. It aims for dynamic, adaptive control, optimizing traffic flow in real-time. This isn't just about making commutes smoother; it's about building more efficient, sustainable, and responsive cities.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Core Concept: Sensors, Logic, and Actuation
&lt;/h3&gt;

&lt;p&gt;At its heart, a smart traffic system is a feedback loop. It observes, decides, and acts. Here's a breakdown:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Sensing (Input)&lt;/strong&gt;: This is where data is collected. Inductive loops embedded in the road, cameras with computer vision capabilities, radar, and even connected vehicle data can tell the system about vehicle presence, speed, queue length, and pedestrian crossings.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Processing/Logic (Decision)&lt;/strong&gt;: This is the brain of the operation. Based on the data from the sensors, the system's algorithms decide the optimal traffic light phasing. Simple systems might use rule-based logic (e.g., "if queue on street A &amp;gt; 5 and queue on street B &amp;lt; 2, extend green for A"). More advanced systems employ machine learning models to predict traffic patterns or reinforce learning agents to dynamically learn optimal strategies.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Actuation (Output)&lt;/strong&gt;: Once a decision is made, the system controls the traffic signals. This involves sending commands to change light states (red, yellow, green) and their durations.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Configuring such a system involves defining these relationships, setting thresholds, and refining the algorithms. It's less about hard-coding every single scenario and more about building a flexible, adaptable framework.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pseudocode Snapshot: A Simple Adaptive Intersection
&lt;/h3&gt;

&lt;p&gt;Let's consider a basic 4-way intersection. Our goal is to dynamically adjust green light times based on detected traffic volume. We'll use a &lt;code&gt;TrafficLight&lt;/code&gt; object for each approach and a &lt;code&gt;Sensor&lt;/code&gt; object to detect vehicles.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Define a simplified TrafficLight object
class TrafficLight:
    constructor(id, initial_state, min_green_time, max_green_time)
    method set_state(new_state)
    method get_current_state()

// Define a simplified Sensor object
class Sensor:
    constructor(location_id)
    method get_vehicle_count() // Returns number of vehicles detected
    method get_queue_length() // Returns estimated queue length

// Main Traffic Management System Logic
function configure_smart_intersection(intersection_id, approaches):
    // approaches: a map from approach_id (e.g., 'north_bound') to a tuple of (TrafficLight, Sensor)

    current_green_approach = 'north_bound' // Start with a default
    timer_for_current_approach = 0

    loop indefinitely:
        // 1. Get current traffic data
        traffic_data = {}
        for approach_id, (light, sensor) in approaches.items():
            traffic_data[approach_id] = {
                'vehicle_count': sensor.get_vehicle_count(),
                'queue_length': sensor.get_queue_length()
            }

        // 2. Apply Decision Logic
        current_light, current_sensor = approaches[current_green_approach]

        // Check if current green time has exceeded minimum or if other approaches demand attention
        if timer_for_current_approach &amp;gt;= current_light.min_green_time:
            // Look for approaches with significant queues that aren't currently green
            candidate_next_approach = null
            max_queue = 0

            for other_approach_id, (other_light, other_sensor) in approaches.items():
                if other_approach_id != current_green_approach:
                    if other_sensor.get_queue_length() &amp;gt; max_queue:
                        max_queue = other_sensor.get_queue_length()
                        candidate_next_approach = other_approach_id

            // If a significant queue is detected elsewhere OR max_green_time is reached
            if (candidate_next_approach != null and max_queue &amp;gt; THRESHOLD_FOR_SWITCH) or 
               timer_for_current_approach &amp;gt;= current_light.max_green_time:
                // Initiate switch sequence (e.g., yellow for current, then red, then green for next)
                // (Simplified for pseudocode)
                current_light.set_state('YELLOW')
                wait(YELLOW_DURATION)
                current_light.set_state('RED')

                current_green_approach = candidate_next_approach // Or pick based on priority
                next_light, _ = approaches[current_green_approach]
                next_light.set_state('GREEN')
                timer_for_current_approach = 0
            else:
                // Extend current green light
                timer_for_current_approach += TIME_STEP
        else:
            // Must complete minimum green time
            timer_for_current_approach += TIME_STEP

        wait(TIME_STEP) // Simulate time passing
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This pseudocode illustrates a basic reactive system. Real-world systems incorporate predictive models, coordination between multiple intersections, pedestrian detection, emergency vehicle preemption, and sophisticated optimization algorithms. The &lt;code&gt;THRESHOLD_FOR_SWITCH&lt;/code&gt; and &lt;code&gt;TIME_STEP&lt;/code&gt; would be configurable parameters crucial for fine-tuning performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Hands-On Practice is Non-Negotiable
&lt;/h3&gt;

&lt;p&gt;Understanding the concepts is one thing; making a system like this work in a dynamic environment is another. The real challenge lies in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Parameter Tuning&lt;/strong&gt;: What's the optimal &lt;code&gt;THRESHOLD_FOR_SWITCH&lt;/code&gt;? How do &lt;code&gt;min_green_time&lt;/code&gt; and &lt;code&gt;max_green_time&lt;/code&gt; interact across multiple intersections?&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Edge Cases&lt;/strong&gt;: What happens during peak hours, during an accident, or when sensors fail?&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Scalability&lt;/strong&gt;: How do you extend this logic from one intersection to an entire city?&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Performance&lt;/strong&gt;: Ensuring real-time decisions without introducing latency.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are problems best solved by building, testing, and iterating. Reading about algorithms is great, but getting your hands dirty with a simulated environment lets you see the immediate impact of your configuration choices. It's where you learn the nuances of balancing flow, preventing deadlocks, and optimizing for various metrics.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ready to Build Smarter Cities?
&lt;/h3&gt;

&lt;p&gt;Configuring smart traffic systems is a fantastic way to apply your development skills to a tangible, impactful problem. It combines elements of data processing, algorithms, and real-time control. Instead of just theorizing, imagine deploying your own adaptive traffic logic and seeing the results unfold.&lt;/p&gt;

&lt;p&gt;Practice this concept interactively on CodeCityApp — free trial at codecityapp.com&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codecityapp.com" rel="noopener noreferrer"&gt;CodeCityApp&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Your pipeline was green for weeks. It shipped nothing.</title>
      <dc:creator>Mike Clarke</dc:creator>
      <pubDate>Tue, 11 Aug 2026 14:00:05 +0000</pubDate>
      <link>https://dev.to/mike_clarke_50a95013f5c59/your-pipeline-was-green-for-weeks-it-shipped-nothing-59l6</link>
      <guid>https://dev.to/mike_clarke_50a95013f5c59/your-pipeline-was-green-for-weeks-it-shipped-nothing-59l6</guid>
      <description>&lt;p&gt;There is a category of production failure that monitoring tools are almost designed to miss. The system runs. The pings arrive. Every dashboard stays green. And somewhere behind that green, nothing is happening.&lt;/p&gt;

&lt;p&gt;We hit this with ARIA, the autonomous system we run at Elevare Digital. A pipeline had been silent for weeks. Not crashing — silent. The health checks came in on schedule. The function executed. And the work it existed to do was not getting done.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Takeaways&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Liveness (did it run?) and function (did it accomplish anything?) are different properties. Most health checks only measure one.&lt;/li&gt;
&lt;li&gt;A cron that reschedules, retries, or re-checks the same item will emit healthy pings indefinitely while producing zero output.&lt;/li&gt;
&lt;li&gt;The fix is to make your health signal carry a payload: items processed, rows moved, work done.&lt;/li&gt;
&lt;li&gt;Alert on &lt;em&gt;absence of output&lt;/em&gt; over a window, not just on errors.&lt;/li&gt;
&lt;li&gt;A green heartbeat on a pipeline that produces nothing is a failure wearing a healthy costume.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What we were checking vs. what we needed to check
&lt;/h2&gt;

&lt;p&gt;The health check looked like this conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// What we had — liveness only&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;runPipeline&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;doWork&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// might do nothing&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;recordHealth&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ok&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;timestamp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function ran. It called &lt;code&gt;doWork()&lt;/code&gt;. It recorded &lt;code&gt;status: ok&lt;/code&gt;. Monitoring saw the ping. Everything looked fine.&lt;/p&gt;

&lt;p&gt;The problem: &lt;code&gt;doWork()&lt;/code&gt; had silently reduced itself to re-checking one item it had already processed. It found nothing new, did nothing, and returned without error. The health signal had no idea. It recorded that the function executed — which was true — and implied from that the pipeline was functioning — which was not.&lt;/p&gt;

&lt;p&gt;This distinction sounds obvious written out. It is easy to miss in practice because the failure mode produces no errors, no exceptions, no timeouts. It produces only silence, and your monitoring is not listening for silence.&lt;/p&gt;




&lt;h2&gt;
  
  
  The mechanism in plain terms
&lt;/h2&gt;

&lt;p&gt;Cron fires. Function wakes up. Function checks for work. No new work is found (or the same old item keeps surfacing and getting skipped). Function exits cleanly. Health ping is recorded.&lt;/p&gt;

&lt;p&gt;Repeat. Every interval. For weeks.&lt;/p&gt;

&lt;p&gt;From the outside: healthy system.&lt;br&gt;
From the inside: a poster that clocks in, sits down, does nothing, clocks out, and files a timesheet marked "completed."&lt;/p&gt;


&lt;h2&gt;
  
  
  The fix: make the health signal carry evidence of work
&lt;/h2&gt;

&lt;p&gt;We changed the health record to include output metrics. Not just "did it run" but "what did it produce."&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// What we changed to — function-level health&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;runPipeline&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;doWork&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;recordHealth&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ok&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;timestamp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="na"&gt;items_processed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// the actual payload&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we added a check that looks at recent health records and alerts when a supposedly-active pipeline has emitted zero output over a window:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Supabase: find active pipelines that reported no work over the last N intervals&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt;
  &lt;span class="n"&gt;pipeline_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;COUNT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;runs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items_processed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;total_output&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;MAX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;recorded_at&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;last_run&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;pipeline_health&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;recorded_at&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;interval&lt;/span&gt; &lt;span class="s1"&gt;'7 days'&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;pipeline_name&lt;/span&gt;
&lt;span class="k"&gt;HAVING&lt;/span&gt; &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;items_processed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;last_run&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query has no interesting results on a healthy system. When it returns rows, a pipeline ran repeatedly and moved nothing — and that is worth an alert regardless of what the status field says.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why this failure mode is common
&lt;/h2&gt;

&lt;p&gt;Most health check patterns are borrowed from web services, where liveness and function are closely coupled. If your API endpoint returns 200, it almost certainly did the thing it exists to do. The request-response cycle forces the work to happen before the response is emitted.&lt;/p&gt;

&lt;p&gt;Background pipelines are different. The work is decoupled from the signal. The function can complete — cleanly, successfully — and still have accomplished nothing. The health check fires after execution regardless of output.&lt;/p&gt;

&lt;p&gt;So when teams instrument a pipeline the same way they instrument an endpoint, they end up measuring the wrong thing.&lt;/p&gt;




&lt;h2&gt;
  
  
  What to add to any pipeline health check
&lt;/h2&gt;

&lt;p&gt;Three fields that matter more than &lt;code&gt;status: ok&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;PipelineHealthRecord&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;pipeline_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;recorded_at&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ok&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;error&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// These are the fields that actually tell you something&lt;/span&gt;
  &lt;span class="nl"&gt;items_processed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// work done this run&lt;/span&gt;
  &lt;span class="nl"&gt;items_available&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// work seen (optional but useful)&lt;/span&gt;
  &lt;span class="nl"&gt;error_detail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;items_available&lt;/code&gt; you can distinguish between two very different situations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Available = 0, processed = 0: queue is empty, pipeline is idle. Probably fine.&lt;/li&gt;
&lt;li&gt;Available &amp;gt; 0, processed = 0: work exists, pipeline is not touching it. Not fine.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The second case is what we had. The pipeline could see work (or thought it could), entered its processing loop, and exited without moving anything. Status: ok the whole time.&lt;/p&gt;




&lt;h2&gt;
  
  
  The alert logic
&lt;/h2&gt;

&lt;p&gt;Once the health records carry real output data, the alert becomes straightforward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;checkPipelineOutput&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pipelineName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;supabase&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pipeline_health&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;items_processed, recorded_at&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pipeline_name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pipelineName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gte&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;recorded_at&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toISOString&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;recorded_at&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;ascending&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// no runs at all — separate alert&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;totalOutput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;row&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items_processed&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;runCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;runCount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;totalOutput&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sendAlert&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;pipeline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;pipelineName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`Ran &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;runCount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; times in the last 7 days. Produced zero output.`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;severity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;high&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The threshold (&lt;code&gt;runCount &amp;gt; 3&lt;/code&gt;) is tunable. The point is that multiple runs with zero output is the signal. A single zero-output run might be a quiet period. Several in a row is the pipeline telling you something is wrong, if you are listening.&lt;/p&gt;




&lt;h2&gt;
  
  
  The honest lesson
&lt;/h2&gt;

&lt;p&gt;We were not measuring the wrong thing by accident. We followed a normal health check pattern and it was simply insufficient for this class of job. The pattern works fine for services. It does not work for pipelines.&lt;/p&gt;

&lt;p&gt;Log the absence of work as loudly as the presence of errors. Zero output on a pipeline that should be producing is not a quiet success. It is an invisible failure, and the only difference between that and a noisy crash is that the noisy crash gets fixed.&lt;/p&gt;




&lt;p&gt;— Mike Clarke, founder of Elevare Digital.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>coding</category>
      <category>webdev</category>
      <category>learning</category>
    </item>
    <item>
      <title>The cleanup code that ate every code block in our published articles</title>
      <dc:creator>Mike Clarke</dc:creator>
      <pubDate>Tue, 04 Aug 2026 14:00:21 +0000</pubDate>
      <link>https://dev.to/mike_clarke_50a95013f5c59/the-cleanup-code-that-ate-every-code-block-in-our-published-articles-5620</link>
      <guid>https://dev.to/mike_clarke_50a95013f5c59/the-cleanup-code-that-ate-every-code-block-in-our-published-articles-5620</guid>
      <description>&lt;p&gt;Liquid syntax error: Variable '{{% raw %}' was not properly terminated with regexp: /\}\}/&lt;/p&gt;
</description>
      <category>programming</category>
      <category>coding</category>
      <category>webdev</category>
      <category>learning</category>
    </item>
    <item>
      <title>Smart Traffic Systems: Configuring Flow for a Smarter City</title>
      <dc:creator>Mike Clarke</dc:creator>
      <pubDate>Wed, 29 Jul 2026 06:00:20 +0000</pubDate>
      <link>https://dev.to/mike_clarke_50a95013f5c59/smart-traffic-systems-configuring-flow-for-a-smarter-city-odd</link>
      <guid>https://dev.to/mike_clarke_50a95013f5c59/smart-traffic-systems-configuring-flow-for-a-smarter-city-odd</guid>
      <description>&lt;h2&gt;
  
  
  Smart Traffic Systems: Configuring Flow for a Smarter City
&lt;/h2&gt;

&lt;p&gt;Ever found yourself stuck in a gridlocked intersection, wondering why the lights aren't cooperating? Or perhaps you've mused about the sheer inefficiency of fixed-timer traffic signals in a dynamic urban landscape. As developers, these aren't just annoyances; they're ripe problems begging for intelligent solutions. And that's where smart traffic systems come in.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Problem: Static Systems vs. Dynamic Reality
&lt;/h3&gt;

&lt;p&gt;Traditional traffic light systems operate on pre-programmed timings. They don't care if an ambulance needs to pass, if a bus is running behind schedule, or if one lane is bumper-to-bumper while another is empty. This static approach leads to congestion, increased travel times, higher fuel consumption, and crucially, frustrated citizens. We can do better.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Concept: Dynamic, Data-Driven Control
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;How to configure a smart traffic system?&lt;/strong&gt; At its core, it's about shifting from reactive, static timing to proactive, data-driven optimization. A smart system continuously gathers data from various sources: loop detectors, cameras (for vehicle count and classification), GPS data from connected vehicles, even weather sensors. This data feeds into an intelligent agent, often leveraging AI/ML algorithms, to make real-time decisions about traffic light signalization, lane usage, pedestrian crossings, and even suggesting alternative routes.&lt;/p&gt;

&lt;p&gt;Think of it as a central brain that constantly analyzes the pulse of the city's arteries and adjusts flow accordingly. The goal is to minimize overall travel time, reduce congestion, prioritize emergency vehicles, and optimize public transport efficiency. It's a complex optimization problem, often involving multi-agent systems and reinforcement learning.&lt;/p&gt;

&lt;h3&gt;
  
  
  A Glimpse Under the Hood (Pseudocode):
&lt;/h3&gt;

&lt;p&gt;Let's imagine a simplified scenario for a single intersection. Our smart system needs to decide which phase (e.g., North-South green, East-West red) to activate and for how long.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Initialize system components
TrafficLightController = new Controller()
SensorDataStream = new DataStreamService()
OptimalPhaseSelector = new MLModel()

// Main Loop - runs continuously
LOOP:
    // 1. Gather Real-time Data
    currentTrafficData = SensorDataStream.getLiveTrafficData(intersectionID)
    // currentTrafficData might include:
    //    - VehicleCountsPerLane
    //    - AverageWaitingTimesPerLane
    //    - PresenceOfEmergencyVehicles
    //    - PedestrianCrossingRequests

    // 2. Process Data and Determine Optimal Phase
    optimalPhaseResult = OptimalPhaseSelector.predictOptimalPhase(
        currentTrafficData,
        historicalTrafficPatterns,
        currentWeatherConditions
    )
    // optimalPhaseResult might contain:
    //    - recommendedPhase (e.g., 'NS_GREEN')
    //    - recommendedDuration (e.g., 45 seconds)
    //    - priorityFlags (e.g., 'EmergencyVehiclePresent')

    // 3. Command Traffic Lights
    IF optimalPhaseResult.priorityFlags.contains('EmergencyVehiclePresent'):
        TrafficLightController.triggerEmergencyPhase(optimalPhaseResult.recommendedPhase)
    ELSE:
        TrafficLightController.setPhase(optimalPhaseResult.recommendedPhase, optimalPhaseResult.recommendedDuration)

    // 4. Log and Monitor (for debugging and retraining)
    Log.event("Phase changed to " + optimalPhaseResult.recommendedPhase + " for " + optimalPhaseResult.recommendedDuration)
    Monitor.displayCurrentTrafficFlow()

    WAIT for short interval // Re-evaluate every few seconds
END LOOP

// --- Additional functions for OptimalPhaseSelector (simplified) ---

FUNCTION predictOptimalPhase(data, history, weather):
    // Example logic (highly simplified):
    IF data.EmergencyVehicles &amp;gt; 0:
        RETURN {recommendedPhase: 'ClearPathForEmergency', recommendedDuration: 10, priorityFlags: ['EmergencyVehiclePresent']}

    ELSE IF data.LaneTraffic['NorthBound'] &amp;gt; data.LaneTraffic['EastBound'] * 2 AND data.WaitingTimes['NorthBound'] &amp;gt; 60:
        RETURN {recommendedPhase: 'NS_GREEN', recommendedDuration: 60}

    ELSE IF data.PedestrianRequests['EastCross'] AND data.SafeToCross:
        RETURN {recommendedPhase: 'EW_PED_GREEN', recommendedDuration: 20}

    ELSE:
        // Fallback to a default or historical pattern if no strong signal
        RETURN {recommendedPhase: history.getDefaultPhaseForTimeOfDay(), recommendedDuration: 30}
END FUNCTION
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This pseudocode barely scratches the surface. A real-world system would involve complex state machines, robust fault tolerance, distributed sensing, and sophisticated machine learning models trained on vast datasets. The &lt;code&gt;OptimalPhaseSelector&lt;/code&gt; would likely be a black box of intricate algorithms deciding based on predicted future states, not just current ones.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Practice Matters in This Domain
&lt;/h3&gt;

&lt;p&gt;Configuring a smart traffic system isn't just about writing code; it's about understanding complex systems, optimizing for multiple conflicting objectives, and handling real-time data under pressure. There are countless edge cases, from sensor failures to unexpected traffic surges. Practicing these concepts – building simplified models, simulating various scenarios, and tweaking parameters – is crucial for developing the intuition needed to build robust, life-changing solutions.&lt;/p&gt;

&lt;p&gt;It's one thing to read about Reinforcement Learning; it's another to apply it to make a simulated city's traffic flow smoother. These are problems where your algorithms have a direct, tangible impact.&lt;/p&gt;

&lt;p&gt;Practice this concept interactively on CodeCityApp — free trial at &lt;a href="http://codecityapp.com" rel="noopener noreferrer"&gt;codecityapp.com&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://codecityapp.com" rel="noopener noreferrer"&gt;CodeCityApp&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The upsert said it worked. It wrote zero rows. Every single run.</title>
      <dc:creator>Mike Clarke</dc:creator>
      <pubDate>Tue, 28 Jul 2026 14:00:04 +0000</pubDate>
      <link>https://dev.to/mike_clarke_50a95013f5c59/the-upsert-said-it-worked-it-wrote-zero-rows-every-single-run-47e1</link>
      <guid>https://dev.to/mike_clarke_50a95013f5c59/the-upsert-said-it-worked-it-wrote-zero-rows-every-single-run-47e1</guid>
      <description>&lt;p&gt;Your scanner runs. It fetches data. It loops through rows, calls upsert, increments a success counter. It logs &lt;code&gt;✓ 42 rows processed&lt;/code&gt;. You check the table. Empty.&lt;/p&gt;

&lt;p&gt;That ran every day for a while before we caught it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ON CONFLICT (col)&lt;/code&gt; will &lt;strong&gt;not&lt;/strong&gt; use a partial unique index (&lt;code&gt;WHERE col IS NOT NULL&lt;/code&gt;) as the conflict arbiter. Postgres requires the predicate to be restated in the statement itself.&lt;/li&gt;
&lt;li&gt;PostgREST's upsert path can't restate that predicate. Every row throws a quiet error.&lt;/li&gt;
&lt;li&gt;A loop that only increments on success will report a perfectly healthy run that wrote absolutely nothing.&lt;/li&gt;
&lt;li&gt;Fix: replace the partial index with a plain, unconditional unique index.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;At Elevare Digital, ARIA runs data ingestion pipelines that pull from external sources and upsert into Postgres via Supabase. Standard stuff. One scanner's job was to fetch records and land them in a table, using a unique column as the conflict target so re-runs were idempotent.&lt;/p&gt;

&lt;p&gt;The index on that column had been created like this, probably by someone being careful about NULLs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;UNIQUE&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;records_external_id_idx&lt;/span&gt;
  &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;records&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;external_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;external_id&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reasonable-looking. Partial indexes are useful. This one quietly broke everything.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Postgres actually requires
&lt;/h2&gt;

&lt;p&gt;When you write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;records&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;external_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'abc-123'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'{...}'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;CONFLICT&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;external_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;DO&lt;/span&gt; &lt;span class="k"&gt;UPDATE&lt;/span&gt;
  &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;EXCLUDED&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Postgres needs to identify which unique constraint or index to use as the arbiter. For a &lt;strong&gt;full&lt;/strong&gt; unique index, &lt;code&gt;ON CONFLICT (external_id)&lt;/code&gt; is enough — Postgres finds it.&lt;/p&gt;

&lt;p&gt;For a &lt;strong&gt;partial&lt;/strong&gt; unique index, Postgres requires the conflict target to include the index predicate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;records&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;external_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'abc-123'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'{...}'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;CONFLICT&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;external_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;external_id&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;  &lt;span class="c1"&gt;-- restate the predicate&lt;/span&gt;
&lt;span class="k"&gt;DO&lt;/span&gt; &lt;span class="k"&gt;UPDATE&lt;/span&gt;
  &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;EXCLUDED&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without that &lt;code&gt;WHERE&lt;/code&gt; clause, Postgres cannot match the partial index. It doesn't fall back. It throws an error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can verify this yourself in a few lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Create a table with a partial unique index&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;demo&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;serial&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;external_id&lt;/span&gt; &lt;span class="nb"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="nb"&gt;text&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;UNIQUE&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;demo_ext_id_partial&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;demo&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;external_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;external_id&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;-- This fails — Postgres can't match the partial index&lt;/span&gt;
&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;demo&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;external_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'x1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;CONFLICT&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;external_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;DO&lt;/span&gt; &lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;EXCLUDED&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;-- ERROR: there is no unique or exclusion constraint matching the ON CONFLICT specification&lt;/span&gt;

&lt;span class="c1"&gt;-- This works — predicate restated&lt;/span&gt;
&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;demo&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;external_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'x1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;CONFLICT&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;external_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;external_id&lt;/span&gt; &lt;span class="k"&gt;IS&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;
&lt;span class="k"&gt;DO&lt;/span&gt; &lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;EXCLUDED&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;-- INSERT 0 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Why PostgREST couldn't restate the predicate
&lt;/h2&gt;

&lt;p&gt;ARIA calls Supabase's upsert via PostgREST. The request looks something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;supabase&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;records&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upsert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;onConflict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;external_id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PostgREST translates &lt;code&gt;onConflict: 'external_id'&lt;/code&gt; into:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;CONFLICT&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;external_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;DO&lt;/span&gt; &lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's no interface in PostgREST's upsert path to append an arbitrary &lt;code&gt;WHERE&lt;/code&gt; predicate to the conflict target. So every row-level upsert hit the same error. Every row.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why the loop reported success
&lt;/h2&gt;

&lt;p&gt;The ingestion loop looked roughly like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;successCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;row&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;fetchedRows&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;supabase&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;records&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upsert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;row&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;onConflict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;external_id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;successCount&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// error case: nothing. no log, no throw, no increment.&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`✓ &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;successCount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; rows processed`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When &lt;code&gt;error&lt;/code&gt; was non-null, the loop just... continued. No log. No counter. The success counter never moved, but &lt;code&gt;fetchedRows.length&lt;/code&gt; rows later, it logged a number that looked fine because the fetch itself succeeded.&lt;/p&gt;

&lt;p&gt;Actually — it logged &lt;code&gt;0&lt;/code&gt;. But nobody was watching for zero. Zero looks like "nothing to sync today."&lt;/p&gt;

&lt;p&gt;A counter that only moves on success will always look plausible. You need to also track failures:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;successCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;errorCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;row&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;fetchedRows&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;supabase&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;records&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upsert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;row&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;onConflict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;external_id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;errorCount&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;upsert failed:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;row&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;external_id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;successCount&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`processed: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;successCount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; ok, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;errorCount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; failed of &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;fetchedRows&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; fetched`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;errorCount&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`ingestion completed with &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;errorCount&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; errors`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now a run that writes nothing will at least be loud about it.&lt;/p&gt;




&lt;h2&gt;
  
  
  The fix
&lt;/h2&gt;

&lt;p&gt;Drop the partial index. Create a plain one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;DROP&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;records_external_id_idx&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;UNIQUE&lt;/span&gt; &lt;span class="k"&gt;INDEX&lt;/span&gt; &lt;span class="n"&gt;records_external_id_idx&lt;/span&gt;
  &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;records&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;external_id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If NULLs are genuinely a concern, handle them at the application layer or with a &lt;code&gt;NOT NULL&lt;/code&gt; constraint on the column. A partial index to "exclude NULLs" is not worth the silent failure mode when you need conflict arbitration.&lt;/p&gt;

&lt;p&gt;After the index swap, the PostgREST upsert matched correctly and rows started landing.&lt;/p&gt;




&lt;h2&gt;
  
  
  The honest lesson
&lt;/h2&gt;

&lt;p&gt;Postgres did nothing wrong here. The docs describe this requirement. The error message is clear. The problem was that the error was being swallowed and nothing downstream cared that zero rows were written.&lt;/p&gt;

&lt;p&gt;Two independent things had to both be true for this to stay hidden:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A partial index being used as an &lt;code&gt;ON CONFLICT&lt;/code&gt; target without the predicate&lt;/li&gt;
&lt;li&gt;A loop that treated errors as a no-op&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Either one alone might have surfaced faster. Together, they produced a system that appeared healthy and did nothing.&lt;/p&gt;

&lt;p&gt;When you write an ingestion loop, the number that matters isn't "how many did I try" or "how many succeeded." It's the ratio. And if errors are silent, you'll never compute it.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;— Mike Clarke, founder of Elevare Digital.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>coding</category>
      <category>webdev</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
