Scale PubNub applications for high-volume real-time events
Does it follow best practices?
Evaluation — 96%
↑ 1.45xAgent success when using this tile
Validation for skill structure
A logistics company tracks 2,000 delivery vehicles in real-time. Each vehicle sends location updates, speed, fuel level, engine status, driver status, and other telemetry data every 2 seconds. The data is sent via PubNub to a central dashboard. The current implementation is hitting performance issues: messages are too large, the publish rate is overwhelming certain channels, and the dashboard is sluggish because of the volume of data.
The engineering team needs a refactored PubNub message layer (JavaScript/Node.js) that dramatically reduces bandwidth while preserving all necessary data. The vehicles frequently report the same values (e.g., parked vehicles report identical location/speed for hours). Many telemetry fields are sometimes null (e.g., fuel level sensor is intermittently unavailable).
Produce the following files:
message-optimizer.js: A Node.js module that exports:
fleet-publisher.js: A Node.js module that exports:
dashboard-listener.js: A Node.js module that sets up a PubNub listener for incoming fleet messages, handling the high volume of incoming data efficiently without blocking.
The following files are provided as inputs. Extract them before beginning.
=============== FILE: inputs/sample-telemetry.json =============== { "vehicleIdentifier": "truck-4821", "currentLatitude": 37.7749, "currentLongitude": -122.4194, "currentSpeedMph": 35.5, "currentHeadingDegrees": 180, "fuelLevelPercentage": 72.3, "engineRunningStatus": "running", "driverActivityStatus": "driving", "cargoTemperatureFahrenheit": null, "tirePressureFrontLeft": null, "tirePressureFrontRight": null, "tirePressureRearLeft": null, "tirePressureRearRight": null, "lastMaintenanceTimestamp": 1704067200000, "currentOdometerMiles": 84521.3, "batteryVoltage": 12.6, "diagnosticTroubleCodesActive": [] }