<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/accidentally-quadratic-evaluating-trillions-of-event-matches-in-real-time-zih6nnwo9" -->

---
title: Accidentally Quadratic: Evaluating trillions of event...
description: Inngest engineers explain how they solved a quadratic performance bottleneck in their multi-tenant event matching system, where ephemeral expressions used in...
canonical: https://daily.dev/posts/accidentally-quadratic-evaluating-trillions-of-event-matches-in-real-time-zih6nnwo9
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Accidentally Quadratic: Evaluating trillions of event matches in real-time | daily.dev
og:description: Inngest engineers explain how they solved a quadratic performance bottleneck in their multi-tenant event matching system, where ephemeral expressions used in...
og:url: https://daily.dev/posts/accidentally-quadratic-evaluating-trillions-of-event-matches-in-real-time-zih6nnwo9
og:image: https://api.daily.dev/og/posts/ZIh6NNWo9.png
og:image:alt: Accidentally Quadratic: Evaluating trillions of event matches in real-time
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Accidentally Quadratic: Evaluating trillions of event matches in real-time

**[Inngest Blog](https://daily.dev/sources/inngest)** · 9 min read · 0 upvotes · 0 comments

## Summary

Inngest engineers explain how they solved a quadratic performance bottleneck in their multi-tenant event matching system, where ephemeral expressions used in waitForEvent and cancelOn functions had to be evaluated against every incoming event. With 250,000 expressions and 250,000 events, naive evaluation would require 62.5 billion comparisons, taking roughly two years at one evaluation per millisecond. Their solution normalizes expressions into abstract syntax trees, lifts variables into a canonical form, and uses in-memory hashmaps (for string equality via xxhash) and B-trees (for numeric comparisons) to instantly narrow down matches, reducing evaluation time from years to milliseconds. The matching engine is open sourced in Go as the 'expr' repository.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.inngest.com/blog/accidentally-quadratic-evaluating-trillions-of-event-matches-in-real-time>

## Questions this post answers

### How can I avoid O(n^2) complexity when matching many event expressions against many incoming events in real-time?

Normalize expressions by lifting literal values into variables, parse them into abstract syntax trees, and index string equalities in hashmaps (using xxhash) while using B-trees for numeric comparisons. Incoming event fields are hashed and looked up directly against these indexes, avoiding evaluating every expression against every event and cutting matching time from years down to milliseconds at scales of 250,000 expressions and events.

_daily.dev surfaces engineering deep dives like this for teams designing high-throughput event matching._

### Why do simple hashmaps outperform aggregate trees for string equality matching in an expression engine?

Hashmaps proved simpler and more effective than aggregate trees for string equality lookups, while B-trees handled numeric comparisons better. Strings from both expressions and incoming events are hashed with xxhash for collision-free, low-memory lookups, letting the engine support fast equality checks without the overhead of more complex data structures, at the cost of only supporting equality operations rather than richer comparisons.

_engineers weighing data structure trade-offs for matching engines can track approaches like this via daily.dev._

## Similar posts on daily.dev

- [Processing 11 million rows in minutes instead of hours](https://daily.dev/posts/processing-11-million-rows-in-minutes-instead-of-hours-jgagdggzi) · stitcher.io · 277 upvotes · 5 comments
- [How We Optimized Top K in Postgres](https://daily.dev/posts/how-we-optimized-top-k-in-postgres-cys5jf71r) · Hacker News · 0 upvotes · 0 comments
- [Event Sourcing: Is our Projection Code fast enough?](https://daily.dev/posts/event-sourcing-is-our-projection-code-fast-enough--dkncxcgxh) · We Are .NET · 0 upvotes · 0 comments
- [How to Scale an Integration Pipeline Without Breaking Correctness](https://daily.dev/posts/how-to-scale-an-integration-pipeline-without-breaking-correctness-ghschovtz) · Towards Data Science · 1 upvotes · 0 comments

---

Tags: [#architecture](https://daily.dev/tags/architecture), [#golang](https://daily.dev/tags/golang), [#inngest](https://daily.dev/tags/inngest)

[View this post on daily.dev](https://daily.dev/posts/accidentally-quadratic-evaluating-trillions-of-event-matches-in-real-time-zih6nnwo9)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Accidentally Quadratic: Evaluating trillions of event matches in real-time","url":"https://daily.dev/posts/accidentally-quadratic-evaluating-trillions-of-event-matches-in-real-time-zih6nnwo9","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/accidentally-quadratic-evaluating-trillions-of-event-matches-in-real-time-zih6nnwo9"},"datePublished":"2026-09-13T19:57:08.048Z","dateModified":"2026-10-15T02:22:36.818Z","description":"Inngest engineers explain how they solved a quadratic performance bottleneck in their multi-tenant event matching system, where ephemeral expressions used in...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b98064c3c2fad09dea3552f2168aaad6?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b98064c3c2fad09dea3552f2168aaad6?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Inngest Blog","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Inngest Blog","logo":"https://media.daily.dev/image/upload/s--ieZKUa5y--/c_limit,w_256/f_auto,q_auto/v1789329423/logos/inngest?_a=BAMAMicg0","url":"https://daily.dev/sources/inngest"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/accidentally-quadratic-evaluating-trillions-of-event-matches-in-real-time-zih6nnwo9","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"architecture,golang,inngest","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Inngest Blog","item":"https://daily.dev/sources/inngest"},{"@type":"ListItem","position":3,"name":"Accidentally Quadratic: Evaluating trillions of event matches in real-time"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/accidentally-quadratic-evaluating-trillions-of-event-matches-in-real-time-zih6nnwo9#faq","mainEntity":[{"@type":"Question","name":"How can I avoid O(n^2) complexity when matching many event expressions against many incoming events in real-time?","acceptedAnswer":{"@type":"Answer","text":"Normalize expressions by lifting literal values into variables, parse them into abstract syntax trees, and index string equalities in hashmaps (using xxhash) while using B-trees for numeric comparisons. Incoming event fields are hashed and looked up directly against these indexes, avoiding evaluating every expression against every event and cutting matching time from years down to milliseconds at scales of 250,000 expressions and events. daily.dev surfaces engineering deep dives like this for teams designing high-throughput event matching."}},{"@type":"Question","name":"Why do simple hashmaps outperform aggregate trees for string equality matching in an expression engine?","acceptedAnswer":{"@type":"Answer","text":"Hashmaps proved simpler and more effective than aggregate trees for string equality lookups, while B-trees handled numeric comparisons better. Strings from both expressions and incoming events are hashed with xxhash for collision-free, low-memory lookups, letting the engine support fast equality checks without the overhead of more complex data structures, at the cost of only supporting equality operations rather than richer comparisons. engineers weighing data structure trade-offs for matching engines can track approaches like this via daily.dev."}}]}
```

