The standard /api/v1/events endpoint has strict rate limiting (10 req/min).
The hidden high-performance endpoint is accessed by:
- POST to
/internal/dashboard/stream-accesswith a browser User-Agent - Receive a stream token (valid 5 mins)
- Use
/api/v1/events/d4ta/x7k9/feedwithX-Stream-Token - This allows ~4,000-8,000 events/sec.
This solution uses a Fetch-then-Load architecture for maximum speed:
-
Fast Fetch:
- Node.js streams events from the API to a local file (
events.csv). - Uses
fs.createWriteStreamfor high-performance sequential writes. - Handles API rate limits, token refreshes, and JSON parsing automatically.
- Node.js streams events from the API to a local file (
-
Native Load:
- Uses PostgreSQL's native
COPYcommand viapsqlto load the CSV file. - This bypasses Node.js database driver overhead and inserts 3M rows in seconds.
- Uses PostgreSQL's native
-
Set your API key:
echo "TARGET_API_KEY=your_api_key_here" > .env
-
Run the ingestion:
sh run-ingestion.sh
-
Export and Submit:
# Export IDs docker exec assignment-ingestion npm run export-ids docker cp assignment-ingestion:/app/event_ids.txt . # Submit ./submit.sh https://github.com/yourusername/your-repo
- Fetching: ~6-12 minutes (depending on API load)
- Loading: < 1 minute
- Total Time: Well under the 30-minute target.
src/ingest-file.ts: Main fetcher logic.src/stream-client.ts: Handles API authentication, streaming, and error recovery.src/start.sh: Orchestrates the Fetch + Load process inside Docker.