:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(ingestion): merge-event rate overflow condition via pluggable strategies (#72855)
Paweł Ledwoń069697e7de71
diff --git a/nodejs/src/ingestion/common/overflow-redirect/main-lane-overflow-redirect.test.ts b/nodejs/src/ingestion/common/overflow-redirect/main-lane-overflow-redirect.test.tsindex 2198c477b3d4..08830bf06c19 100644--- a/nodejs/src/ingestion/common/overflow-redirect/main-lane-overflow-redirect.test.ts+++ b/nodejs/src/ingestion/common/overflow-redirect/main-lane-overflow-redirect.test.ts@@ -1,8 +1,10 @@+import { createTestEventHeaders } from '~/tests/helpers/event-headers'import { HealthCheckResultOk } from '~/types'import { MainLaneOverflowRedirect, MainLaneOverflowRedirectConfig } from './main-lane-overflow-redirect'-import { OverflowEventBatch } from './overflow-redirect-service'+import { OverflowEventGroup } from './overflow-redirect-service'import { OverflowRedisRepository } from './overflow-redis-repository'+import { eventRateStrategy, mergeEventRateStrategy } from './overflow-strategy'const createMockRepository = (): jest.Mocked<OverflowRedisRepository> => ({batchCheck: jest.fn().mockResolvedValue(new Map()),@@ -11,14 +13,16 @@ const createMockRepository = (): jest.Mocked<OverflowRedisRepository> => ({healthCheck: jest.fn().mockResolvedValue(new HealthCheckResultOk()),})-const createBatch = (+const createGroup = (token: string,distinctId: string,eventCount: number = 1,firstTimestamp: number = Date.now()-): OverflowEventBatch => ({+): OverflowEventGroup => ({key: { token, distinctId },- eventCount,+ headersPerEvent: Array.from({ length: eventCount }, () =>+ createTestEventHeaders({ token, distinct_id: distinctId })+ ),firstTimestamp,})@@ -30,8 +34,7 @@ describe('MainLaneOverflowRedirect', () => {return new MainLaneOverflowRedirect({redisRepository: mockRepository,localCacheTTLSeconds: 60,- bucketCapacity: 10,- replenishRate: 1,+ strategies: [{ ...eventRateStrategy(), bucketCapacity: 10, replenishRate: 1 }],overflowType: 'events',...overrides,})@@ -44,7 +47,7 @@ describe('MainLaneOverflowRedirect', () => {describe('handleEventBatch', () => {it('returns empty set when no events exceed rate limit', async () => {- const batch = [createBatch('token1', 'user1', 5)]+ const batch = [createGroup('token1', 'user1', 5)]const result = await service.handleEventBatch(batch)@@ -53,7 +56,7 @@ describe('MainLaneOverflowRedirect', () => {it('returns keys that exceed rate limit', async () => {// Bucket capacity is 10, so 15 events should exceed- const batch = [createBatch('token1', 'user1', 15)]+ const batch = [createGroup('token1', 'user1', 15)]const result = await service.handleEventBatch(batch)@@ -62,7 +65,7 @@ describe('MainLaneOverflowRedirect', () => {})it('flags newly rate-limited keys in Redis', async () => {- const batch = [createBatch('token1', 'user1', 15)]+ const batch = [createGroup('token1', 'user1', 15)]await service.handleEventBatch(batch)@@ -70,7 +73,7 @@ describe('MainLaneOverflowRedirect', () => {})it('checks Redis for keys not in local cache', async () => {- const batch = [createBatch('token1', 'user1', 5)]+ const batch = [createGroup('token1', 'user1', 5)]await service.handleEventBatch(batch)@@ -80,7 +83,7 @@ describe('MainLaneOverflowRedirect', () => {it('returns keys that are already flagged in Redis', async () => {mockRepository.batchCheck.mockResolvedValue(new Map([['token1:user1', true]]))- const batch = [createBatch('token1', 'user1', 1)]+ const batch = [createGroup('token1', 'user1', 1)]const result = await service.handleEventBatch(batch)@@ -92,14 +95,14 @@ describe('MainLaneOverflowRedirect', () => {// First call: Redis says key is flaggedmockRepository.batchCheck.mockResolvedValue(new Map([['token1:user1', true]]))- const batch1 = [createBatch('token1', 'user1', 1)]+ const batch1 = [createGroup('token1', 'user1', 1)]await service.handleEventBatch(batch1)// Reset mockmockRepository.batchCheck.mockClear()// Second call: should use cache, not repository- const batch2 = [createBatch('token1', 'user1', 1)]+ const batch2 = [createGroup('token1', 'user1', 1)]const result = await service.handleEventBatch(batch2)expect(result.size).toBe(1)@@ -111,7 +114,7 @@ describe('MainLaneOverflowRedirect', () => {// First call: key not in RedismockRepository.batchCheck.mockResolvedValue(new Map([['token1:user1', false]]))- const batch1 = [createBatch('token1', 'user1', 1)]+ const batch1 = [createGroup('token1', 'user1', 1)]await service.handleEventBatch(batch1)// Reset mock@@ -119,7 +122,7 @@ describe('MainLaneOverflowRedirect', () => {mockRepository.batchCheck.mockResolvedValue(new Map([['token1:user1', true]]))// Second call: should use cache (null), not check repository again- const batch2 = [createBatch('token1', 'user1', 1)]+ const batch2 = [createGroup('token1', 'user1', 1)]await service.handleEventBatch(batch2)expect(mockRepository.batchCheck).not.toHaveBeenCalled()@@ -134,8 +137,8 @@ describe('MainLaneOverflowRedirect', () => {)const batch = [- createBatch('token1', 'user1', 5), // Below limit- createBatch('token1', 'user2', 15), // Exceeds limit+ createGroup('token1', 'user1', 5), // Below limit+ createGroup('token1', 'user2', 15), // Exceeds limit]const result = await service.handleEventBatch(batch)@@ -147,9 +150,9 @@ describe('MainLaneOverflowRedirect', () => {it('batches all keys in a single batchCheck call', async () => {const batch = [- createBatch('token1', 'user1', 1),- createBatch('token1', 'user2', 1),- createBatch('token2', 'user1', 1),+ createGroup('token1', 'user1', 1),+ createGroup('token1', 'user2', 1),+ createGroup('token2', 'user1', 1),]await service.handleEventBatch(batch)@@ -169,7 +172,7 @@ describe('MainLaneOverflowRedirect', () => {// Simulate repository fail-open by returning the default "not flagged" resultmockRepository.batchCheck.mockResolvedValue(new Map([['token1:user1', false]]))- const batch = [createBatch('token1', 'user1', 5)]+ const batch = [createGroup('token1', 'user1', 5)]const result = await service.handleEventBatch(batch)@@ -179,7 +182,7 @@ describe('MainLaneOverflowRedirect', () => {it('still redirects based on rate limit even when batchFlag is a no-op', async () => {// Even if batchFlag does nothing (e.g. repository fail-open), the local// rate limit decision still causes a redirect for this batch- const batch = [createBatch('token1', 'user1', 15)]+ const batch = [createGroup('token1', 'user1', 15)]const result = await service.handleEventBatch(batch)@@ -191,12 +194,12 @@ describe('MainLaneOverflowRedirect', () => {describe('rate limiting behavior', () => {it('rate limit state persists across batches', async () => {// First batch: consume 8 of 10 tokens- const batch1 = [createBatch('token1', 'user1', 8)]+ const batch1 = [createGroup('token1', 'user1', 8)]const result1 = await service.handleEventBatch(batch1)expect(result1.size).toBe(0)// Second batch: consume 3 more tokens (total 11, exceeds 10)- const batch2 = [createBatch('token1', 'user1', 3)]+ const batch2 = [createGroup('token1', 'user1', 3)]const result2 = await service.handleEventBatch(batch2)expect(result2.size).toBe(1)expect(result2.has('token1:user1')).toBe(true)@@ -204,17 +207,64 @@ describe('MainLaneOverflowRedirect', () => {it('different keys have independent rate limits', async () => {// Exhaust tokens for user1- const batch1 = [createBatch('token1', 'user1', 15)]+ const batch1 = [createGroup('token1', 'user1', 15)]await service.handleEventBatch(batch1)// user2 should still have tokens- const batch2 = [createBatch('token1', 'user2', 5)]+ const batch2 = [createGroup('token1', 'user2', 5)]const result = await service.handleEventBatch(batch2)expect(result.size).toBe(0)})})+ describe('merge event rate strategy', () => {+ const createMergeAwareService = (): MainLaneOverflowRedirect =>+ createService({+ strategies: [+ { ...eventRateStrategy(), bucketCapacity: 100, replenishRate: 1 },+ { ...mergeEventRateStrategy(), bucketCapacity: 3, replenishRate: 0.01 },+ ],+ })++ const createGroupWithEvents = (+ token: string,+ distinctId: string,+ eventNames: (string | undefined)[]+ ): OverflowEventGroup => ({+ key: { token, distinctId },+ headersPerEvent: eventNames.map((event) =>+ createTestEventHeaders({ token, distinct_id: distinctId, event })+ ),+ firstTimestamp: Date.now(),+ })++ it.each(['$identify', '$create_alias', '$merge_dangerously'])(+ 'redirects a key whose %s rate exceeds the merge bucket while under the event bucket',+ async (eventName) => {+ const mergeAwareService = createMergeAwareService()+ const batch = [createGroupWithEvents('token1', 'user1', Array(5).fill(eventName))]++ const result = await mergeAwareService.handleEventBatch(batch)++ expect(result.has('token1:user1')).toBe(true)+ }+ )++ it.each([['$pageview'], [undefined]])(+ 'does not count non-merge events (%s) against the merge bucket',+ async (eventName) => {+ const mergeAwareService = createMergeAwareService()+ // 50 events: over the merge bucket capacity (3) but under the event bucket (100)+ const batch = [createGroupWithEvents('token1', 'user1', Array(50).fill(eventName))]++ const result = await mergeAwareService.handleEventBatch(batch)++ expect(result.size).toBe(0)+ }+ )+ })+describe('healthCheck', () => {it('delegates to repository', async () => {const result = await service.healthCheck()@@ -228,7 +278,7 @@ describe('MainLaneOverflowRedirect', () => {it('clears local cache', async () => {// Populate cachemockRepository.batchCheck.mockResolvedValue(new Map([['token1:user1', true]]))- await service.handleEventBatch([createBatch('token1', 'user1', 1)])+ await service.handleEventBatch([createGroup('token1', 'user1', 1)])await service.shutdown()@@ -236,7 +286,7 @@ describe('MainLaneOverflowRedirect', () => {// Next call should check repository againmockRepository.batchCheck.mockClear()mockRepository.batchCheck.mockResolvedValue(new Map([['token1:user1', false]]))- await service.handleEventBatch([createBatch('token1', 'user1', 1)])+ await service.handleEventBatch([createGroup('token1', 'user1', 1)])expect(mockRepository.batchCheck).toHaveBeenCalled()})diff --git a/nodejs/src/ingestion/common/overflow-redirect/main-lane-overflow-redirect.ts b/nodejs/src/ingestion/common/overflow-redirect/main-lane-overflow-redirect.tsindex f5c48a75ff6f..29fde1487b75 100644--- a/nodejs/src/ingestion/common/overflow-redirect/main-lane-overflow-redirect.ts+++ b/nodejs/src/ingestion/common/overflow-redirect/main-lane-overflow-redirect.ts@@ -12,16 +12,17 @@ import {overflowRedirectRateLimitDecisions,overflowRedirectSourceEventsTotal,} from './metrics'-import { OverflowEventBatch, OverflowRedirectService } from './overflow-redirect-service'+import { OverflowEventGroup, OverflowRedirectService } from './overflow-redirect-service'import { OverflowRedisRepository, OverflowType, memberKey } from './overflow-redis-repository'+import { OverflowStrategyEntry } from './overflow-strategy'export interface MainLaneOverflowRedirectConfig {redisRepository: OverflowRedisRepositorylocalCacheTTLSeconds: number/** Max entries in the in-memory flagged/not-flagged cache before LRU eviction. */localCacheMaxSize?: number- bucketCapacity: number- replenishRate: number+ /** Overflow conditions to enforce; a key is redirected when any strategy's bucket is exhausted. */+ strategies: OverflowStrategyEntry[]/** Redis keyspace this service operates on. Fixed per pipeline. */overflowType: OverflowType}@@ -44,7 +45,11 @@ const DEFAULT_LOCAL_CACHE_MAX_SIZE = 1_000_000*/export class MainLaneOverflowRedirect implements OverflowRedirectService {private localCache: LRUCache<string, boolean>- private rateLimiter: MemoryRateLimiter+ private strategies: {+ label: string+ countTokens: OverflowStrategyEntry['countTokens']+ limiter: MemoryRateLimiter+ }[]private redisRepository: OverflowRedisRepositoryprivate overflowType: OverflowType@@ -54,7 +59,11 @@ export class MainLaneOverflowRedirect implements OverflowRedirectService {max: config.localCacheMaxSize ?? DEFAULT_LOCAL_CACHE_MAX_SIZE,ttl: config.localCacheTTLSeconds * 1000,})- this.rateLimiter = new MemoryRateLimiter(config.bucketCapacity, config.replenishRate)+ this.strategies = config.strategies.map((entry) => ({+ label: entry.label,+ countTokens: entry.countTokens,+ limiter: new MemoryRateLimiter(entry.bucketCapacity, entry.replenishRate),+ }))this.overflowType = config.overflowType}@@ -72,32 +81,32 @@ export class MainLaneOverflowRedirect implements OverflowRedirectService {this.localCache.set(key, value)}- async handleEventBatch(batch: OverflowEventBatch[]): Promise<Set<string>> {+ async handleEventBatch(batch: OverflowEventGroup[]): Promise<Set<string>> {const type = this.overflowTypeconst toRedirect = new Set<string>()const redirectSource = new Map<string, 'redis' | 'rate_limiter'>()- const needsRateLimitCheck: OverflowEventBatch[] = []+ const needsRateLimitCheck: OverflowEventGroup[] = []// Step 1: Check local cache- const needsRedisCheck: OverflowEventBatch[] = []+ const needsRedisCheck: OverflowEventGroup[] = []- for (const event of batch) {- const cacheKey = this.localCacheKey(type, event.key.token, event.key.distinctId)+ for (const group of batch) {+ const cacheKey = this.localCacheKey(type, group.key.token, group.key.distinctId)const cached = this.getCachedValue(cacheKey)if (cached === true) {// Already flagged (cached from previous Redis lookup) - redirect- const mKey = memberKey(event.key.token, event.key.distinctId)+ const mKey = memberKey(group.key.token, group.key.distinctId)toRedirect.add(mKey)redirectSource.set(mKey, 'redis')overflowRedirectCacheHitsTotal.labels(type, 'hit_flagged').inc()} else if (cached === false) {// Known not in Redis - check rate limit only- needsRateLimitCheck.push(event)+ needsRateLimitCheck.push(group)overflowRedirectCacheHitsTotal.labels(type, 'hit_not_flagged').inc()} else {// Cache miss - need to check Redis- needsRedisCheck.push(event)+ needsRedisCheck.push(group)overflowRedirectCacheHitsTotal.labels(type, 'miss').inc()}}@@ -109,9 +118,9 @@ export class MainLaneOverflowRedirect implements OverflowRedirectService {needsRedisCheck.map((e) => e.key))- for (const event of needsRedisCheck) {- const mKey = memberKey(event.key.token, event.key.distinctId)- const cacheKey = this.localCacheKey(type, event.key.token, event.key.distinctId)+ for (const group of needsRedisCheck) {+ const mKey = memberKey(group.key.token, group.key.distinctId)+ const cacheKey = this.localCacheKey(type, group.key.token, group.key.distinctId)if (redisResults.get(mKey)) {// Flagged in Redis - redirect@@ -121,7 +130,7 @@ export class MainLaneOverflowRedirect implements OverflowRedirectService {} else {// Not in Redis - cache false and check rate limitthis.setCachedValue(cacheKey, false)- needsRateLimitCheck.push(event)+ needsRateLimitCheck.push(group)}}}@@ -130,20 +139,36 @@ export class MainLaneOverflowRedirect implements OverflowRedirectService {overflowRedirectCacheSize.set(this.localCache.size)// Step 3: Check rate limiter for unflagged keys- const newlyFlagged: OverflowEventBatch[] = []+ const newlyFlagged: OverflowEventGroup[] = []++ for (const group of needsRateLimitCheck) {+ const rateLimitKey = memberKey(group.key.token, group.key.distinctId)++ // Consume from every strategy (no short-circuit) so buckets drain+ // consistently; any exhausted bucket flags the key.+ let allowed = true+ for (const { label, countTokens, limiter } of this.strategies) {+ let tokens = 0+ for (const headers of group.headersPerEvent) {+ tokens += countTokens(headers)+ }+ if (tokens === 0) {+ continue+ }- for (const event of needsRateLimitCheck) {- const rateLimitKey = memberKey(event.key.token, event.key.distinctId)- const allowed = this.rateLimiter.consume(rateLimitKey, event.eventCount, event.firstTimestamp)+ if (limiter.consume(rateLimitKey, tokens, group.firstTimestamp)) {+ overflowRedirectRateLimitDecisions.labels(type, label, 'allowed').inc()+ } else {+ allowed = false+ overflowRedirectRateLimitDecisions.labels(type, label, 'exceeded').inc()+ }+ }if (!allowed) {// Rate limit exceeded - needs to be flagged- newlyFlagged.push(event)+ newlyFlagged.push(group)toRedirect.add(rateLimitKey)redirectSource.set(rateLimitKey, 'rate_limiter')- overflowRedirectRateLimitDecisions.labels(type, 'exceeded').inc()- } else {- overflowRedirectRateLimitDecisions.labels(type, 'allowed').inc()}}@@ -151,8 +176,8 @@ export class MainLaneOverflowRedirect implements OverflowRedirectService {if (newlyFlagged.length > 0) {// Update local cache BEFORE Redis write to prevent race condition where// a subsequent batch could check the rate limiter again before Redis completes- for (const event of newlyFlagged) {- const cacheKey = this.localCacheKey(type, event.key.token, event.key.distinctId)+ for (const group of newlyFlagged) {+ const cacheKey = this.localCacheKey(type, group.key.token, group.key.distinctId)this.setCachedValue(cacheKey, true)}overflowRedirectCacheSize.set(this.localCache.size)@@ -172,16 +197,16 @@ export class MainLaneOverflowRedirect implements OverflowRedirectService {let redirectedEvents = 0let passedEvents = 0const eventsBySource = new Map<'redis' | 'rate_limiter', number>()- for (const event of batch) {- const mKey = memberKey(event.key.token, event.key.distinctId)+ for (const group of batch) {+ const mKey = memberKey(group.key.token, group.key.distinctId)if (toRedirect.has(mKey)) {- redirectedEvents += event.eventCount+ redirectedEvents += group.headersPerEvent.lengthconst source = redirectSource.get(mKey)if (source) {- eventsBySource.set(source, (eventsBySource.get(source) ?? 0) + event.eventCount)+ eventsBySource.set(source, (eventsBySource.get(source) ?? 0) + group.headersPerEvent.length)}} else {- passedEvents += event.eventCount+ passedEvents += group.headersPerEvent.length}}overflowRedirectEventsTotal.labels(type, 'redirected').inc(redirectedEvents)diff --git a/nodejs/src/ingestion/common/overflow-redirect/metrics.ts b/nodejs/src/ingestion/common/overflow-redirect/metrics.tsindex f3ff25ba4731..f6b7bd5c2239 100644--- a/nodejs/src/ingestion/common/overflow-redirect/metrics.ts+++ b/nodejs/src/ingestion/common/overflow-redirect/metrics.ts@@ -43,7 +43,8 @@ export const overflowRedirectCacheSize = new Gauge({export const overflowRedirectRateLimitDecisions = new Counter({name: 'overflow_redirect_rate_limit_decisions_total',help: 'Total number of rate limit decisions',- labelNames: ['type', 'decision'], // decision: 'allowed' | 'exceeded'+ // strategy: OverflowStrategy.label of the strategy that decided (e.g. 'event_rate')+ labelNames: ['type', 'strategy', 'decision'], // decision: 'allowed' | 'exceeded'})// Redirect source metrics - tracks WHERE the redirect decision came fromdiff --git a/nodejs/src/ingestion/common/overflow-redirect/overflow-lane-overflow-redirect.test.ts b/nodejs/src/ingestion/common/overflow-redirect/overflow-lane-overflow-redirect.test.tsindex 6753f6ec0c89..792823faeb1a 100644--- a/nodejs/src/ingestion/common/overflow-redirect/overflow-lane-overflow-redirect.test.ts+++ b/nodejs/src/ingestion/common/overflow-redirect/overflow-lane-overflow-redirect.test.ts@@ -1,7 +1,8 @@+import { createTestEventHeaders } from '~/tests/helpers/event-headers'import { HealthCheckResultError, HealthCheckResultOk } from '~/types'import { OverflowLaneOverflowRedirect } from './overflow-lane-overflow-redirect'-import { OverflowEventBatch } from './overflow-redirect-service'+import { OverflowEventGroup } from './overflow-redirect-service'import { OverflowRedisRepository } from './overflow-redis-repository'const createMockRepository = (): jest.Mocked<OverflowRedisRepository> => ({@@ -11,14 +12,16 @@ const createMockRepository = (): jest.Mocked<OverflowRedisRepository> => ({healthCheck: jest.fn().mockResolvedValue(new HealthCheckResultOk()),})-const createBatch = (+const createGroup = (token: string,distinctId: string,eventCount: number = 1,firstTimestamp: number = Date.now()-): OverflowEventBatch => ({+): OverflowEventGroup => ({key: { token, distinctId },- eventCount,+ headersPerEvent: Array.from({ length: eventCount }, () =>+ createTestEventHeaders({ token, distinct_id: distinctId })+ ),firstTimestamp,})@@ -36,7 +39,7 @@ describe('OverflowLaneOverflowRedirect', () => {describe('handleEventBatch', () => {it('always returns empty set (no redirects from overflow lane)', async () => {- const batch = [createBatch('token1', 'user1', 100), createBatch('token1', 'user2', 100)]+ const batch = [createGroup('token1', 'user1', 100), createGroup('token1', 'user2', 100)]const result = await service.handleEventBatch(batch)@@ -44,7 +47,7 @@ describe('OverflowLaneOverflowRedirect', () => {})it('refreshes TTL for all keys in batch', async () => {- const batch = [createBatch('token1', 'user1'), createBatch('token1', 'user2')]+ const batch = [createGroup('token1', 'user1'), createGroup('token1', 'user2')]await service.handleEventBatch(batch)@@ -60,7 +63,7 @@ describe('OverflowLaneOverflowRedirect', () => {overflowType: 'recordings',})- await recordingsService.handleEventBatch([createBatch('token1', 'session1')])+ await recordingsService.handleEventBatch([createGroup('token1', 'session1')])expect(mockRepository.batchRefreshTTL).toHaveBeenCalledWith('recordings', [{ token: 'token1', distinctId: 'session1' },@@ -76,9 +79,9 @@ describe('OverflowLaneOverflowRedirect', () => {it('sends all keys in a single batchRefreshTTL call', async () => {const batch = [- createBatch('token1', 'user1'),- createBatch('token1', 'user2'),- createBatch('token2', 'user1'),+ createGroup('token1', 'user1'),+ createGroup('token1', 'user2'),+ createGroup('token2', 'user1'),]await service.handleEventBatch(batch)@@ -97,7 +100,7 @@ describe('OverflowLaneOverflowRedirect', () => {// The repository layer handles Redis errors internally (fail-open)// From the service perspective, batchRefreshTTL completes without error// and the service still returns an empty set (no redirects from overflow lane)- const batch = [createBatch('token1', 'user1')]+ const batch = [createGroup('token1', 'user1')]const result = await service.handleEventBatch(batch)diff --git a/nodejs/src/ingestion/common/overflow-redirect/overflow-lane-overflow-redirect.ts b/nodejs/src/ingestion/common/overflow-redirect/overflow-lane-overflow-redirect.tsindex 56b24238798a..9c3e9070b6e2 100644--- a/nodejs/src/ingestion/common/overflow-redirect/overflow-lane-overflow-redirect.ts+++ b/nodejs/src/ingestion/common/overflow-redirect/overflow-lane-overflow-redirect.ts@@ -2,7 +2,7 @@ import { Component } from '~/ingestion/common/scopes'import { HealthCheckResult } from '~/types'import { overflowRedirectEventsTotal, overflowRedirectKeysTotal } from './metrics'-import { OverflowEventBatch, OverflowRedirectService } from './overflow-redirect-service'+import { OverflowEventGroup, OverflowRedirectService } from './overflow-redirect-service'import { OverflowRedisRepository, OverflowType } from './overflow-redis-repository'export interface OverflowLaneOverflowRedirectConfig {@@ -34,7 +34,7 @@ export class OverflowLaneOverflowRedirect implements OverflowRedirectService {this.overflowType = config.overflowType}- async handleEventBatch(batch: OverflowEventBatch[]): Promise<Set<string>> {+ async handleEventBatch(batch: OverflowEventGroup[]): Promise<Set<string>> {const type = this.overflowType// Refresh TTL for all keys in the batch@@ -49,7 +49,7 @@ export class OverflowLaneOverflowRedirect implements OverflowRedirectService {overflowRedirectKeysTotal.labels(type, 'passed').inc(batch.length)// Record event-level metrics - sum up all event counts- const totalEvents = batch.reduce((sum, event) => sum + event.eventCount, 0)+ const totalEvents = batch.reduce((sum, group) => sum + group.headersPerEvent.length, 0)overflowRedirectEventsTotal.labels(type, 'passed').inc(totalEvents)// Never redirect from overflow lane - return empty setdiff --git a/nodejs/src/ingestion/common/overflow-redirect/overflow-redirect-service.ts b/nodejs/src/ingestion/common/overflow-redirect/overflow-redirect-service.tsindex 72fcf5502545..bdc3c02c5113 100644--- a/nodejs/src/ingestion/common/overflow-redirect/overflow-redirect-service.ts+++ b/nodejs/src/ingestion/common/overflow-redirect/overflow-redirect-service.ts@@ -1,4 +1,4 @@-import { HealthCheckResult } from '~/types'+import { EventHeaders, HealthCheckResult } from '~/types'// Re-export OverflowType so consumers of the interface// don't need to know about the repository layer@@ -9,9 +9,10 @@ export interface OverflowEventKey {distinctId: string}-export interface OverflowEventBatch {+export interface OverflowEventGroup {key: OverflowEventKey- eventCount: number+ /** Headers of each event for this key in the batch; strategies count their tokens from these. */+ headersPerEvent: EventHeaders[]firstTimestamp: number}@@ -31,7 +32,7 @@ export interface OverflowRedirectService {** @returns Set of keys (token:distinctId) that should be redirected to overflow*/- handleEventBatch(batch: OverflowEventBatch[]): Promise<Set<string>>+ handleEventBatch(batch: OverflowEventGroup[]): Promise<Set<string>>/*** Health check for the servicediff --git a/nodejs/src/ingestion/common/overflow-redirect/overflow-strategy.test.ts b/nodejs/src/ingestion/common/overflow-redirect/overflow-strategy.test.tsnew file mode 100644index 000000000000..515bba83f958--- /dev/null+++ b/nodejs/src/ingestion/common/overflow-redirect/overflow-strategy.test.ts@@ -0,0 +1,48 @@+import { createTestEventHeaders } from '~/tests/helpers/event-headers'++import { createAnalyticsOverflowStrategies, eventRateStrategy, mergeEventRateStrategy } from './overflow-strategy'++describe('overflow strategies', () => {+ describe('eventRateStrategy', () => {+ it.each([['$pageview'], ['$identify'], [undefined]])('counts every event (%s) as one token', (event) => {+ expect(eventRateStrategy().countTokens(createTestEventHeaders({ event }))).toBe(1)+ })+ })++ describe('mergeEventRateStrategy', () => {+ it.each([+ ['$identify', 1],+ ['$create_alias', 1],+ ['$merge_dangerously', 1],+ ['$pageview', 0],+ ['identify', 0],+ ['$Identify', 0],+ [undefined, 0],+ ])('counts %s as %i tokens', (event, expected) => {+ expect(mergeEventRateStrategy().countTokens(createTestEventHeaders({ event }))).toBe(expected)+ })+ })++ describe('createAnalyticsOverflowStrategies', () => {+ const baseConfig = {+ eventBucketCapacity: 1000,+ eventReplenishRate: 1,+ mergeEventBucketCapacity: 50,+ mergeEventReplenishRate: 0.1,+ }++ it('includes the merge strategy when its capacity is positive', () => {+ const strategies = createAnalyticsOverflowStrategies(baseConfig)++ expect(strategies.map((s) => s.label)).toEqual(['event_rate', 'merge_event_rate'])+ })++ it('omits the merge strategy entirely when its capacity is 0', () => {+ // A 0-capacity bucket would deny everything, so the strategy must be+ // omitted, not included with capacity 0+ const strategies = createAnalyticsOverflowStrategies({ ...baseConfig, mergeEventBucketCapacity: 0 })++ expect(strategies.map((s) => s.label)).toEqual(['event_rate'])+ })+ })+})diff --git a/nodejs/src/ingestion/common/overflow-redirect/overflow-strategy.ts b/nodejs/src/ingestion/common/overflow-redirect/overflow-strategy.tsnew file mode 100644index 000000000000..2c844c79f0ac--- /dev/null+++ b/nodejs/src/ingestion/common/overflow-redirect/overflow-strategy.ts@@ -0,0 +1,73 @@+import { EventHeaders } from '~/types'++/**+ * A pluggable overflow condition for the main-lane overflow redirect.+ *+ * A strategy is a metrics label plus a pure token-counting function. All state+ * (the token buckets, keyed on token:distinct_id) is owned by the redirect+ * service, one bucket set per strategy. A key is redirected to overflow when+ * any strategy's bucket is exhausted.+ */+export interface OverflowStrategy {+ /** Metrics label, e.g. 'event_rate'. Renaming it renames the Prometheus series. */+ label: string+ /** Tokens this event consumes from the strategy's bucket; 0 = not counted. */+ countTokens: (headers: EventHeaders) => number+}++/** Pairs a strategy with the limits for its token buckets. */+export interface OverflowStrategyEntry extends OverflowStrategy {+ bucketCapacity: number+ replenishRate: number+}++/** Counts every event: the overall event-rate overflow condition. */+export const eventRateStrategy = (): OverflowStrategy => ({+ label: 'event_rate',+ countTokens: () => 1,+})++/** Events that can trigger a person merge - the expensive person-processing path. */+const MERGE_EVENT_NAMES = new Set(['$identify', '$create_alias', '$merge_dangerously'])++export function isMergeEvent(eventName: string | undefined): boolean {+ return eventName !== undefined && MERGE_EVENT_NAMES.has(eventName)+}++/**+ * Counts only person-merge events, so merge-heavy actors overflow at a+ * dedicated (much lower) rate than the overall event rate. Events without an+ * event name header are not counted (fail open).+ */+export const mergeEventRateStrategy = (): OverflowStrategy => ({+ label: 'merge_event_rate',+ countTokens: (headers) => (isMergeEvent(headers.event) ? 1 : 0),+})++/**+ * Strategy set for the analytics events pipeline: overall event rate, plus a+ * merge-event rate condition when enabled (a merge bucket capacity of 0+ * disables it - the strategy is omitted entirely rather than denying all).+ */+export function createAnalyticsOverflowStrategies(config: {+ eventBucketCapacity: number+ eventReplenishRate: number+ mergeEventBucketCapacity: number+ mergeEventReplenishRate: number+}): OverflowStrategyEntry[] {+ const strategies: OverflowStrategyEntry[] = [+ {+ ...eventRateStrategy(),+ bucketCapacity: config.eventBucketCapacity,+ replenishRate: config.eventReplenishRate,+ },+ ]+ if (config.mergeEventBucketCapacity > 0) {+ strategies.push({+ ...mergeEventRateStrategy(),+ bucketCapacity: config.mergeEventBucketCapacity,+ replenishRate: config.mergeEventReplenishRate,+ })+ }+ return strategies+}diff --git a/nodejs/src/ingestion/common/steps/event-preprocessing/overflow-lane-ttl-refresh-step.test.ts b/nodejs/src/ingestion/common/steps/event-preprocessing/overflow-lane-ttl-refresh-step.test.tsindex 50ba849facaa..ce66e24ce0dc 100644--- a/nodejs/src/ingestion/common/steps/event-preprocessing/overflow-lane-ttl-refresh-step.test.ts+++ b/nodejs/src/ingestion/common/steps/event-preprocessing/overflow-lane-ttl-refresh-step.test.ts@@ -47,8 +47,16 @@ describe('createOverflowLaneTTLRefreshStep', () => {await step(events)expect(service.handleEventBatch).toHaveBeenCalledWith([- { key: { token: 'token1', distinctId: 'user1' }, eventCount: 2, firstTimestamp: baseTime.getTime() },- { key: { token: 'token1', distinctId: 'user2' }, eventCount: 1, firstTimestamp: baseTime.getTime() },+ {+ key: { token: 'token1', distinctId: 'user1' },+ headersPerEvent: [events[0].headers, events[1].headers],+ firstTimestamp: baseTime.getTime(),+ },+ {+ key: { token: 'token1', distinctId: 'user2' },+ headersPerEvent: [events[2].headers],+ firstTimestamp: baseTime.getTime(),+ },])})diff --git a/nodejs/src/ingestion/common/steps/event-preprocessing/overflow-lane-ttl-refresh-step.ts b/nodejs/src/ingestion/common/steps/event-preprocessing/overflow-lane-ttl-refresh-step.tsindex 843af8d0c06c..8bb21b2fb418 100644--- a/nodejs/src/ingestion/common/steps/event-preprocessing/overflow-lane-ttl-refresh-step.ts+++ b/nodejs/src/ingestion/common/steps/event-preprocessing/overflow-lane-ttl-refresh-step.ts@@ -1,5 +1,5 @@import {- OverflowEventBatch,+ OverflowEventGroup,OverflowRedirectService,} from '~/ingestion/common/overflow-redirect/overflow-redirect-service'import { PipelineResult, ok } from '~/ingestion/framework/results'@@ -26,7 +26,10 @@ export function createOverflowLaneTTLRefreshStep<T extends OverflowLaneTTLRefres}// Group events by token:distinct_id for batch TTL refresh- const keyStats = new Map<string, { token: string; distinctId: string; count: number; firstTimestamp: number }>()+ const keyStats = new Map<+ string,+ { token: string; distinctId: string; headersPerEvent: EventHeaders[]; firstTimestamp: number }+ >()for (const { headers, event } of inputs) {const token = headers.token ?? ''@@ -36,23 +39,23 @@ export function createOverflowLaneTTLRefreshStep<T extends OverflowLaneTTLRefresconst existing = keyStats.get(eventKey)if (existing) {- existing.count+++ existing.headersPerEvent.push(headers)} else {- keyStats.set(eventKey, { token, distinctId, count: 1, firstTimestamp: timestamp })+ keyStats.set(eventKey, { token, distinctId, headersPerEvent: [headers], firstTimestamp: timestamp })}}- const batches: OverflowEventBatch[] = Array.from(keyStats.values()).map(- ({ token, distinctId, count, firstTimestamp }) => ({+ const groups: OverflowEventGroup[] = Array.from(keyStats.values()).map(+ ({ token, distinctId, headersPerEvent, firstTimestamp }) => ({key: { token, distinctId },- eventCount: count,+ headersPerEvent,firstTimestamp,}))// TTL refresh doesn't affect routing, so attach it as a pipeline side effect// instead of blocking the pipeline on a Redis write.- const refreshPromise = overflowRedirectService.handleEventBatch(batches)+ const refreshPromise = overflowRedirectService.handleEventBatch(groups)return Promise.resolve(inputs.map((input) => ok(input, [refreshPromise])))}diff --git a/nodejs/src/ingestion/common/steps/event-preprocessing/rate-limit-to-overflow-step.test.ts b/nodejs/src/ingestion/common/steps/event-preprocessing/rate-limit-to-overflow-step.test.tsindex 381c71f4a3f6..bae54138da42 100644--- a/nodejs/src/ingestion/common/steps/event-preprocessing/rate-limit-to-overflow-step.test.ts+++ b/nodejs/src/ingestion/common/steps/event-preprocessing/rate-limit-to-overflow-step.test.ts@@ -112,8 +112,16 @@ describe('createRateLimitToOverflowStep', () => {await step(events)expect(service.handleEventBatch).toHaveBeenCalledWith([- { key: { token: 'token1', distinctId: 'user1' }, eventCount: 2, firstTimestamp: baseTime.getTime() },- { key: { token: 'token2', distinctId: 'user2' }, eventCount: 1, firstTimestamp: baseTime.getTime() },+ {+ key: { token: 'token1', distinctId: 'user1' },+ headersPerEvent: [events[0].headers, events[1].headers],+ firstTimestamp: baseTime.getTime(),+ },+ {+ key: { token: 'token2', distinctId: 'user2' },+ headersPerEvent: [events[2].headers],+ firstTimestamp: baseTime.getTime(),+ },])})@@ -360,8 +368,14 @@ describe('createSkipCookielessRateLimitToOverflowStep', () => {expect(service.handleEventBatch).toHaveBeenCalledWith(expect.arrayContaining([- expect.objectContaining({ key: { token: 'token1', distinctId: 'user1' }, eventCount: 1 }),- expect.objectContaining({ key: { token: 'token1', distinctId: 'user2' }, eventCount: 1 }),+ expect.objectContaining({+ key: { token: 'token1', distinctId: 'user1' },+ headersPerEvent: [events[0].headers],+ }),+ expect.objectContaining({+ key: { token: 'token1', distinctId: 'user2' },+ headersPerEvent: [events[2].headers],+ }),]))const batches = (service.handleEventBatch as jest.Mock).mock.calls[0][0]diff --git a/nodejs/src/ingestion/common/steps/event-preprocessing/rate-limit-to-overflow-step.ts b/nodejs/src/ingestion/common/steps/event-preprocessing/rate-limit-to-overflow-step.tsindex ec7924893902..25bf58a1fe22 100644--- a/nodejs/src/ingestion/common/steps/event-preprocessing/rate-limit-to-overflow-step.ts+++ b/nodejs/src/ingestion/common/steps/event-preprocessing/rate-limit-to-overflow-step.ts@@ -1,7 +1,7 @@import { OVERFLOW_OUTPUT, OverflowOutput } from '~/common/outputs'import { COOKIELESS_SENTINEL_VALUE } from '~/ingestion/common/cookieless/cookieless-manager'import {- OverflowEventBatch,+ OverflowEventGroup,OverflowRedirectService,} from '~/ingestion/common/overflow-redirect/overflow-redirect-service'import { PipelineResult, ok, redirect } from '~/ingestion/framework/results'@@ -28,7 +28,10 @@ async function applyOverflowRedirect<T extends { headers: EventHeaders }>(}const perInputKeys: (string | null)[] = []- const keyStats = new Map<string, { token: string; distinctId: string; count: number; firstTimestamp: number }>()+ const keyStats = new Map<+ string,+ { token: string; distinctId: string; headersPerEvent: EventHeaders[]; firstTimestamp: number }+ >()for (const input of inputs) {const derived = deriveKey(input)@@ -43,9 +46,9 @@ async function applyOverflowRedirect<T extends { headers: EventHeaders }>(const timestamp = input.headers.now?.getTime() ?? Date.now()const existing = keyStats.get(eventKey)if (existing) {- existing.count+++ existing.headersPerEvent.push(input.headers)} else {- keyStats.set(eventKey, { ...derived, count: 1, firstTimestamp: timestamp })+ keyStats.set(eventKey, { ...derived, headersPerEvent: [input.headers], firstTimestamp: timestamp })}}@@ -53,14 +56,14 @@ async function applyOverflowRedirect<T extends { headers: EventHeaders }>(return inputs.map((input) => ok(input))}- const batches: OverflowEventBatch[] = Array.from(keyStats.values()).map(- ({ token, distinctId, count, firstTimestamp }) => ({+ const groups: OverflowEventGroup[] = Array.from(keyStats.values()).map(+ ({ token, distinctId, headersPerEvent, firstTimestamp }) => ({key: { token, distinctId },- eventCount: count,+ headersPerEvent,firstTimestamp,}))- const keysToRedirect = await overflowRedirectService.handleEventBatch(batches)+ const keysToRedirect = await overflowRedirectService.handleEventBatch(groups)return inputs.map((input, index) => {const eventKey = perInputKeys[index]diff --git a/nodejs/src/ingestion/config.ts b/nodejs/src/ingestion/config.tsindex a04606006d21..a539f75676c5 100644--- a/nodejs/src/ingestion/config.ts+++ b/nodejs/src/ingestion/config.ts@@ -173,6 +173,10 @@ export type IngestionConsumerConfig = {// Event overflow configEVENT_OVERFLOW_BUCKET_CAPACITY: numberEVENT_OVERFLOW_BUCKET_REPLENISH_RATE: number+ // Merge-event ($identify, $create_alias, $merge_dangerously) overflow rate,+ // per token:distinct_id. A capacity of 0 disables the condition.+ MERGE_EVENT_OVERFLOW_BUCKET_CAPACITY: number+ MERGE_EVENT_OVERFLOW_BUCKET_REPLENISH_RATE: number// Stateful overflow configINGESTION_STATEFUL_OVERFLOW_REDIS_TTL_SECONDS: number@@ -290,6 +294,8 @@ export function getDefaultIngestionConsumerConfig(): IngestionConsumerConfig {// Event overflow configEVENT_OVERFLOW_BUCKET_CAPACITY: 1000,EVENT_OVERFLOW_BUCKET_REPLENISH_RATE: 1.0,+ MERGE_EVENT_OVERFLOW_BUCKET_CAPACITY: 0,+ MERGE_EVENT_OVERFLOW_BUCKET_REPLENISH_RATE: 1.0,// Stateful overflow configINGESTION_STATEFUL_OVERFLOW_REDIS_TTL_SECONDS: 300,diff --git a/nodejs/src/ingestion/ingestion-consumer.test.ts b/nodejs/src/ingestion/ingestion-consumer.test.tsindex 8357f1cbdc70..e6b17da8091e 100644--- a/nodejs/src/ingestion/ingestion-consumer.test.ts+++ b/nodejs/src/ingestion/ingestion-consumer.test.ts@@ -302,7 +302,7 @@ describe('IngestionConsumer', () => {})it('should emit to overflow if token and distinct_id are overflowed', async () => {- ;(ingester['overflowRedirectService'] as any)['rateLimiter'].consume(+ ;(ingester['overflowRedirectService'] as any)['strategies'][0]['limiter'].consume(`${team.api_token}:overflow-distinct-id`,1000,now()diff --git a/nodejs/src/ingestion/ingestion-consumer.ts b/nodejs/src/ingestion/ingestion-consumer.tsindex 4503fc9fd82f..ed9cf262103b 100644--- a/nodejs/src/ingestion/ingestion-consumer.ts+++ b/nodejs/src/ingestion/ingestion-consumer.ts@@ -60,6 +60,7 @@ import { MainLaneOverflowRedirect } from './common/overflow-redirect/main-lane-oimport { OverflowLaneOverflowRedirect } from './common/overflow-redirect/overflow-lane-overflow-redirect'import { OverflowRedirectService } from './common/overflow-redirect/overflow-redirect-service'import { RedisOverflowRepository } from './common/overflow-redirect/overflow-redis-repository'+import { createAnalyticsOverflowStrategies } from './common/overflow-redirect/overflow-strategy'import { AiEventSubpipelineFactory } from './common/subpipelines/ai-subpipeline.contract'import { IngestionConsumerConfig, IngestionOutputsConfig } from './config'@@ -189,8 +190,12 @@ export class IngestionConsumer {this.overflowRedirectService = new MainLaneOverflowRedirect({redisRepository: overflowRedisRepository,localCacheTTLSeconds: this.config.INGESTION_STATEFUL_OVERFLOW_LOCAL_CACHE_TTL_SECONDS,- bucketCapacity: this.config.EVENT_OVERFLOW_BUCKET_CAPACITY,- replenishRate: this.config.EVENT_OVERFLOW_BUCKET_REPLENISH_RATE,+ strategies: createAnalyticsOverflowStrategies({+ eventBucketCapacity: this.config.EVENT_OVERFLOW_BUCKET_CAPACITY,+ eventReplenishRate: this.config.EVENT_OVERFLOW_BUCKET_REPLENISH_RATE,+ mergeEventBucketCapacity: this.config.MERGE_EVENT_OVERFLOW_BUCKET_CAPACITY,+ mergeEventReplenishRate: this.config.MERGE_EVENT_OVERFLOW_BUCKET_REPLENISH_RATE,+ }),overflowType: 'events',})}diff --git a/nodejs/src/ingestion/pipelines/ai/consumer.ts b/nodejs/src/ingestion/pipelines/ai/consumer.tsindex 5c98f0e44418..1fa15fbcf71e 100644--- a/nodejs/src/ingestion/pipelines/ai/consumer.ts+++ b/nodejs/src/ingestion/pipelines/ai/consumer.ts@@ -28,6 +28,7 @@ import { DisabledOverflowRedirectComponent } from '~/ingestion/common/overflow-rimport { MainLaneOverflowRedirectComponent } from '~/ingestion/common/overflow-redirect/main-lane-overflow-redirect'import { OverflowLaneOverflowRedirectComponent } from '~/ingestion/common/overflow-redirect/overflow-lane-overflow-redirect'import { RedisOverflowRepositoryComponent } from '~/ingestion/common/overflow-redirect/overflow-redis-repository'+import { eventRateStrategy } from '~/ingestion/common/overflow-redirect/overflow-strategy'import { Scope, extend } from '~/ingestion/common/scopes'import { PromiseSchedulerComponent } from '~/ingestion/common/utils/promise-scheduler'import { IngestionConsumerConfig, IngestionOutputsConfig } from '~/ingestion/config'@@ -120,8 +121,13 @@ export function createAiConsumer(config: AiConsumerConfig, sharedScope: AiShared? new MainLaneOverflowRedirectComponent({redisRepository: container.overflowRedisRepository,localCacheTTLSeconds: config.INGESTION_STATEFUL_OVERFLOW_LOCAL_CACHE_TTL_SECONDS,- bucketCapacity: config.EVENT_OVERFLOW_BUCKET_CAPACITY,- replenishRate: config.EVENT_OVERFLOW_BUCKET_REPLENISH_RATE,+ strategies: [+ {+ ...eventRateStrategy(),+ bucketCapacity: config.EVENT_OVERFLOW_BUCKET_CAPACITY,+ replenishRate: config.EVENT_OVERFLOW_BUCKET_REPLENISH_RATE,+ },+ ],overflowType: 'ai',}): new DisabledOverflowRedirectComponent()diff --git a/nodejs/src/ingestion/pipelines/errortracking/error-tracking-consumer.ts b/nodejs/src/ingestion/pipelines/errortracking/error-tracking-consumer.tsindex ac42d36fe5fa..c9a694d84da4 100644--- a/nodejs/src/ingestion/pipelines/errortracking/error-tracking-consumer.ts+++ b/nodejs/src/ingestion/pipelines/errortracking/error-tracking-consumer.ts@@ -20,6 +20,7 @@ import { MainLaneOverflowRedirect } from '~/ingestion/common/overflow-redirect/mimport { OverflowLaneOverflowRedirect } from '~/ingestion/common/overflow-redirect/overflow-lane-overflow-redirect'import { OverflowRedirectService } from '~/ingestion/common/overflow-redirect/overflow-redirect-service'import { RedisOverflowRepository } from '~/ingestion/common/overflow-redirect/overflow-redis-repository'+import { eventRateStrategy } from '~/ingestion/common/overflow-redirect/overflow-strategy'import { IngestionLane, IngestionOverflowMode } from '~/ingestion/config'import { TopHog } from '~/ingestion/framework/tophog'import { PluginEvent } from '~/plugin-scaffold'@@ -143,8 +144,13 @@ export class ErrorTrackingConsumer {this.overflowRedirectService = new MainLaneOverflowRedirect({redisRepository: overflowRedisRepository,localCacheTTLSeconds: config.statefulOverflowLocalCacheTTLSeconds,- bucketCapacity: config.overflowBucketCapacity,- replenishRate: config.overflowBucketReplenishRate,+ strategies: [+ {+ ...eventRateStrategy(),+ bucketCapacity: config.overflowBucketCapacity,+ replenishRate: config.overflowBucketReplenishRate,+ },+ ],overflowType: 'errortracking',})}diff --git a/nodejs/src/servers/ingestion-api-server.ts b/nodejs/src/servers/ingestion-api-server.tsindex 944ef27ed019..dd9f11c5274c 100644--- a/nodejs/src/servers/ingestion-api-server.ts+++ b/nodejs/src/servers/ingestion-api-server.ts@@ -70,6 +70,7 @@ import { MainLaneOverflowRedirect } from '../ingestion/common/overflow-redirect/import { OverflowLaneOverflowRedirect } from '../ingestion/common/overflow-redirect/overflow-lane-overflow-redirect'import { OverflowRedirectService } from '../ingestion/common/overflow-redirect/overflow-redirect-service'import { RedisOverflowRepository } from '../ingestion/common/overflow-redirect/overflow-redis-repository'+import { createAnalyticsOverflowStrategies } from '../ingestion/common/overflow-redirect/overflow-strategy'import {DatabaseConnectionConfig,IngestionConsumerConfig,@@ -323,8 +324,12 @@ export class IngestionApiServer implements NodeServer {overflowRedirectService = new MainLaneOverflowRedirect({redisRepository: overflowRedisRepository,localCacheTTLSeconds: this.config.INGESTION_STATEFUL_OVERFLOW_LOCAL_CACHE_TTL_SECONDS,- bucketCapacity: this.config.EVENT_OVERFLOW_BUCKET_CAPACITY,- replenishRate: this.config.EVENT_OVERFLOW_BUCKET_REPLENISH_RATE,+ strategies: createAnalyticsOverflowStrategies({+ eventBucketCapacity: this.config.EVENT_OVERFLOW_BUCKET_CAPACITY,+ eventReplenishRate: this.config.EVENT_OVERFLOW_BUCKET_REPLENISH_RATE,+ mergeEventBucketCapacity: this.config.MERGE_EVENT_OVERFLOW_BUCKET_CAPACITY,+ mergeEventReplenishRate: this.config.MERGE_EVENT_OVERFLOW_BUCKET_REPLENISH_RATE,+ }),overflowType: 'events',})}