Skip to content

feat(braze): optimize Track API batching algorithm - #4685

Merged
koladilip merged 1 commit into
developfrom
feat/braze-track-api-batching-optimization
Oct 6, 2025
Merged

koladilip merged 1 commit into
developfrom
feat/braze-track-api-batching-optimization

Conversation

@koladilip

@koladilip koladilip commented Sep 28, 2025 •

Copy link
Copy Markdown
Contributor

Summary

This PR implements a new batching algorithm for the Braze Track API that optimizes how events, attributes, and purchases are grouped and sent to Braze.

Resolves INT-4170

Changes Made

Core Implementation

  • New batchForTrackAPI function: Implements intelligent batching logic that considers both external ID count and request count limits
  • Added TRACK_BRAZE_MAX_EXTERNAL_ID_COUNT: New constant (75) to limit external IDs per batch
  • Refactored processBatch: Updated to use the new batching algorithm for improved efficiency

Key Improvements

  1. Dual Limit Enforcement: Respects both the 75 external ID limit and 75 request count limit per batch
  2. Better Data Grouping: Groups data by external ID first, then splits by request count limits
  3. Performance Optimization: Reduces unnecessary API calls by optimizing batch sizes
  4. Cleaner Code: Simplified the batching logic and removed complex iteration patterns

Testing

  • Comprehensive Test Suite: Added batchForTrackAPI.test.js with 280 lines of tests
  • Edge Case Coverage: Tests handle empty arrays, null/undefined values, and various batching scenarios
  • Limit Testing: Validates both external ID count and request count limits
  • All Existing Tests Pass: Verified backward compatibility

Technical Details

The new algorithm works by:

  1. Filtering out null/undefined items from input arrays
  2. Collecting all unique external IDs across attributes, events, and purchases
  3. Creating chunks based on the external ID limit (75)
  4. For each chunk, further splitting by request count limits for each data type
  5. Ensuring optimal batch sizes while respecting Braze API constraints

Impact

  • Improved API Efficiency: Better utilization of Braze API limits
  • Reduced API Calls: Optimized batching reduces the total number of requests
  • Better Performance: More efficient data processing and transmission
  • Maintained Compatibility: All existing functionality preserved

Testing

All tests pass, including the new comprehensive test suite for the batching algorithm.

@koladilip
koladilip requested a review from a team as a code owner September 28, 2025 09:57
@coderabbitai

coderabbitai Bot commented Sep 28, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Refactor
    • Improved Braze Track API batching to efficiently handle large volumes with per-user and per-type limits, grouped and consistently ordered data, and leaner payloads by omitting empty sections. Expect more reliable delivery and performance under high throughput.
  • Tests
    • Added comprehensive test coverage for batching scenarios and edge cases to ensure stability and correctness.

Walkthrough

Adds a Braze Track API batching implementation and tests: new batching utilities to create/clean track chunks, split by external_id and per-type limits (75), updated processBatch to use chunks and emit per-chunk metrics, a new config constant, and comprehensive unit tests for batching behavior.

Changes

Cohort / File(s) Summary
Braze Track batching logic
src/v0/destinations/braze/util.js
Adds createTrackChunk, cleanTrackChunk, addTrackStats, and batchForTrackAPI. Refactors processBatch to build requests from cleaned track chunks, emit per-chunk metrics, and export batchForTrackAPI. Imports TRACK_BRAZE_MAX_EXTERNAL_ID_COUNT.
Braze Track batching tests
src/v0/destinations/braze/batchForTrackAPI.test.js
New extensive test suite covering empty/null inputs, single-item cases, external_id-based splitting at 75, per-type request-count limits, grouping by external_id, mixed scenarios, ordering, edge cases at limits, and data-integrity checks.
Braze config constants
src/v0/destinations/braze/config.js
Adds and exports TRACK_BRAZE_MAX_EXTERNAL_ID_COUNT = 75.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant PB as processBatch
  participant BF as batchForTrackAPI
  participant MS as Metrics
  participant RB as Request Builder
  participant OUT as Output Array

  PB->>BF: batchForTrackAPI(attributes, events, purchases)
  BF-->>PB: [trackChunks] (each: {attributes, events, purchases, externalIds})

  loop For each chunk
    PB->>MS: addTrackStats(chunk, destination)
    PB->>RB: cleanTrackChunk(chunk)
    RB-->>PB: cleaned body (only non-empty attributes/events/purchases)
    PB->>OUT: push per-chunk request
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Suggested labels

DO NOT MERGE

Suggested reviewers

  • maheshkutty
  • ItsSudip
  • vinayteki95
  • sandeepdsvs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title “feat(braze): optimize Track API batching algorithm” concisely and accurately reflects the primary change in the PR by indicating a new batching optimization for the Braze Track API, matching the introduced implementation and test updates without extra noise.
Description Check ✅ Passed The description provides a clear summary, references the related Linear task, details the implementation changes, outlines technical behavior, and describes testing and impact, covering all essential information specified by the template.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/braze-track-api-batching-optimization

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8222117 and 8185d8c.

📒 Files selected for processing (3)
  • src/v0/destinations/braze/batchForTrackAPI.test.js (1 hunks)
  • src/v0/destinations/braze/config.js (2 hunks)
  • src/v0/destinations/braze/util.js (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/v0/destinations/braze/config.js
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js

⚙️ CodeRabbit configuration file

Focus on ESLint errors (max 3) and warnings (max 5).

Files:

  • src/v0/destinations/braze/batchForTrackAPI.test.js
  • src/v0/destinations/braze/util.js
🧬 Code graph analysis (2)
src/v0/destinations/braze/batchForTrackAPI.test.js (1)
src/v0/destinations/braze/util.js (12)
  • require (4-4)
  • require (7-7)
  • require (8-16)
  • require (17-28)
  • require (29-29)
  • require (30-30)
  • require (31-31)
  • externalId (698-698)
  • batchForTrackAPI (494-541)
  • i (121-121)
  • i (149-149)
  • i (518-518)
src/v0/destinations/braze/util.js (2)
src/v0/util/index.js (7)
  • type (116-116)
  • type (132-132)
  • type (1218-1218)
  • i (1422-1422)
  • i (1506-1506)
  • stats (33-33)
  • defaultRequestConfig (461-475)
src/v0/destinations/braze/config.js (2)
  • TRACK_BRAZE_MAX_EXTERNAL_ID_COUNT (47-47)
  • TRACK_BRAZE_MAX_REQ_COUNT (46-46)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Code Coverage
  • GitHub Check: UT Tests
  • GitHub Check: test_and_publish
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
src/v0/destinations/braze/util.js (1)

499-535: Verify alias-only batching against Braze’s identifier cap

externalIds only tracks item.external_id. Records that rely on user_alias come through with external_id === undefined, so they all collapse into the same Set entry. A mixed payload (e.g., 60 distinct external IDs + 60 distinct alias-only records) will stay in one chunk because per-type counts are below 75, yet it represents 120 unique users. If Braze enforces the 75-identifier ceiling across aliases as well, that chunk will still be rejected. Please double-check the API expectations and, if aliases do count, fold user_alias.alias_name (and label) into the identifier set before we ship this.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Sep 28, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.80%. Comparing base (892ebd7) to head (8185d8c).
⚠️ Report is 5 commits behind head on develop.

Additional details and impacted files
@@            Coverage Diff            @@
##           develop    #4685    +/-   ##
=========================================
  Coverage    91.79%   91.80%            
=========================================
  Files          645      650     +5     
  Lines        34086    34486   +400     
  Branches      8050     8099    +49     
=========================================
+ Hits         31290    31660   +370     
- Misses        2544     2596    +52     
+ Partials       252      230    -22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/v0/destinations/braze/util.js Resolved
@koladilip
koladilip enabled auto-merge (squash) October 6, 2025 07:23
- Implement new batchForTrackAPI function for improved batching logic
- Add support for TRACK_BRAZE_MAX_EXTERNAL_ID_COUNT limit (75 external IDs per batch)
- Optimize batching to respect both external ID count and request count limits
- Refactor processBatch to use new batching algorithm
- Add comprehensive test coverage for batchForTrackAPI function
- Improve performance by reducing unnecessary API calls and better data grouping

This change improves the efficiency of Braze Track API calls by implementing
a smarter batching strategy that considers both the number of unique external
IDs and the total number of requests per batch type.
@koladilip
koladilip force-pushed the feat/braze-track-api-batching-optimization branch from 8222117 to 8185d8c Compare October 6, 2025 07:55
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

sonarqubecloud Bot commented Oct 6, 2025

Copy link
Copy Markdown

@koladilip
koladilip merged commit 49ee4e0 into develop Oct 6, 2025
@koladilip
koladilip deleted the feat/braze-track-api-batching-optimization branch October 6, 2025 08:02
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