Skip to content

Conversation

@fforbeck
Copy link
Member

@fforbeck fforbeck commented Nov 18, 2025

Overview

This PR refactors the egress tracking system to use asynchronous batch processing instead of synchronous invocation execution. The freeway gateway now serializes egress tracking invocations and sends them to a Cloudflare Queue, where the egress-consumer processes them in batches before forwarding to the upload-api in a CAR with multiple invocations.

Key Changes

Freeway Gateway (Producer)

Modified the egress tracking middleware to serialize invocations instead of executing them immediately:

  • Removed the direct connection to upload-api from withEgressClient
  • Invocations are now built, converted to IPLD view using buildIPLDView(), and archived to bytes
  • Serialized invocations are sent to EGRESS_QUEUE as message payloads
  • Egress Tracking controlled using feature flags: FF_EGRESS_TRACKER_ENABLED & FF_EGRESS_TRACKER_ROLLOUT_PERCENTAGE

Flow

  1. Gateway serves content and creates an egress record invocation
  2. Invocation is archived to bytes and queued
  3. Cloudflare Queue batches messages (configured batch size: 50, timeout: 30s)
  4. Egress-consumer receives batch, extracts invocations
  5. Consumer builds CAR message with all invocations
  6. Single POST to upload-api processes entire batch
  7. Upload-api executes each invocation and records egress in DynamoDB+Stripe

Additional Changes

  • Added missing dev packages
  • Fixed type issues
  • Fixed build issues
  • Fixed tests
  • Updated package-lock.json

@fforbeck fforbeck requested a review from travis November 18, 2025 13:29
@fforbeck fforbeck self-assigned this Nov 18, 2025
@fforbeck fforbeck force-pushed the feat/batch-egress-events branch from 151c208 to 336eec5 Compare November 18, 2025 13:40
@fforbeck fforbeck force-pushed the feat/batch-egress-events branch from 336eec5 to ff72d89 Compare November 18, 2025 13:47
Copy link
Member

@travis travis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@fforbeck fforbeck merged commit 28dc194 into main Nov 18, 2025
1 check passed
@fforbeck fforbeck deleted the feat/batch-egress-events branch November 18, 2025 18:47
@fforbeck fforbeck restored the feat/batch-egress-events branch November 18, 2025 19:40
alanshaw pushed a commit that referenced this pull request Nov 19, 2025
🤖 I have created a release *beep* *boop*
---


##
[2.32.0](v2.31.2...v2.32.0)
(2025-11-18)


### Features

* publish egress events to cf queue
([#191](#191))
([28dc194](28dc194))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants