Events Streaming API

Real-time event streaming API with time-windowed queries, viewport filtering, automatic response mode selection, and WebSocket subscriptions.

Last updated: 2025-02-18

Events Streaming API

The Events Streaming API provides efficient access to logistics events for map visualization, dashboards, and analytics. It automatically selects the optimal response format based on query parameters.

certexi.com/app/geo/heatmap
Loading interactive demo...

500 logistics events rendered from the streaming API with automatic mode selection.

Core Endpoint

GET/api/events/stream

Query events within a time window and viewport

Required Parameters:

ParameterTypeDescription
fromISO 8601Start of time window
toISO 8601End of time window

Optional Parameters:

ParameterTypeDescription
minLngnumberViewport west bound
maxLngnumberViewport east bound
minLatnumberViewport south bound
maxLatnumberViewport north bound
typestringFilter by event type (entry, exit, placement, etc.)
warehousenumberFilter by warehouse ID
limitnumberMax events (default: 10000)

Response Modes

The API automatically selects the optimal response format:

Time RangeEvent CountResponse ModeFormat
< 1 day< 10,000Raw eventsIndividual points
< 1 day> 10,000Spatial clustersGrouped with count
1-7 daysAnyHourly bucketsAggregated by hour
7-30 daysAnyDaily bucketsAggregated by day
> 30 daysAnyWeekly bucketsAggregated by week

Raw Events Response

{
  "mode": "raw",
  "total": 847,
  "events": [
    {
      "id": "evt-001",
      "type": "entry",
      "lat": 25.6714,
      "lng": -100.3097,
      "timestamp": "2025-01-15T14:32:07Z",
      "tu_id": "TU-2025-00042",
      "operator": "carlos.mendez",
      "warehouse": "Monterrey Hub"
    }
  ]
}

Clustered Response

{
  "mode": "clustered",
  "total": 24500,
  "clusters": [
    {
      "lat": 25.67,
      "lng": -100.31,
      "count": 342,
      "types": { "entry": 120, "exit": 115, "placement": 107 }
    }
  ]
}

Aggregated Response

{
  "mode": "aggregated",
  "total": 156000,
  "buckets": [
    {
      "start": "2025-01-15T00:00:00Z",
      "end": "2025-01-15T01:00:00Z",
      "count": 245,
      "byType": { "entry": 82, "exit": 78, "placement": 85 }
    }
  ]
}

WebSocket Subscription

For real-time updates, subscribe to the WebSocket endpoint:

const ws = new WebSocket('wss://your-app.com/api/events/ws');

ws.onopen = () => {
  ws.send(JSON.stringify({
    action: 'subscribe',
    filters: {
      warehouse: 1,
      types: ['entry', 'exit', 'placement'],
    },
  }));
};

ws.onmessage = (event) => {
  const data = JSON.parse(event.data);
  // { type: 'event', payload: { ... } }
};

Event Types

TypeDescriptionTypical Frequency
entryVehicle enters facility50-200/day
exitVehicle departs facility50-200/day
placementAsset placed in slot200-500/day
removalAsset removed from slot200-500/day
verificationSupervisor verification100-300/day
weighingScale measurement50-200/day
incidentCompliance incident0-10/day
motionCCTV motion detection50-500/day

Performance

ScenarioTarget LatencyActual
10k events in window< 200ms~120ms
50k events (clustered)< 300ms~200ms
100k events (aggregated)< 400ms~250ms
1M events (weekly buckets)< 500ms~300ms

Rate Limits

PlanRequests/minMax time window
Free trial3024 hours
Professional10090 days
Enterprise5001 year

Client Integration

import { useEvents } from '@/hooks/useEvents';

const {
  events,
  clusters,
  isLoading,
  totalCount,
  renderMode,
} = useEvents({
  timeWindow: { from, to },
  bounds: { minLng, minLat, maxLng, maxLat },
  enabled: true,
});

// renderMode: 'raw' | 'clustered' | 'aggregated'
// Events are automatically cached with 5-min TTL
ℹ️

Memory Management

The client-side cache holds a maximum of 5 time slices (50MB). LRU eviction removes the least-recently-used slice when a new one loads. All pending requests are cancelled on component unmount.

Events Streaming API | Certexi Docs