Context
ProductEventHub is the analytics path I redesigned in 2026 for the learner platform's web app, widgets and React Native app. I designed it and wrote most of it.
The problem
Analytics events went through redux-style middleware that watched app actions. The events were untyped, and some were lost or duplicated. Mobile batches carried no auth token, so they failed with about 200k auth errors a day.
The downstream data store partitions by the legacy event format, so any change to the wire format would shift data.
What I did
I audited every event producer first and wrote a migration plan.
I replaced middleware interception with explicit, typed emits for 8 event families. Payment and enrollment events get critical priority.
I built one durable outbox, backed by MMKV on mobile and IndexedDB on web, with retry and isolation for poison events.
I made token refresh single-flight with one retry, and fixed the token source on mobile.
I deleted the old analytics service and middleware once every producer had moved.
Key decision
I kept the legacy wire format byte-for-byte, including its known bugs. That way no downstream partition shifted during the migration.
The cost is deliberate technical debt carried forward. I judged that safer than a format change mixed into an architecture change, and I can fix the format separately later.
Result
About 200k auth failures a day are gone. Cleaning up the wire path recovered 122 sign-up and login events an hour. Web and mobile now share 1 emit path.
Another fix: the events host is resolved at call time, so dev and preview builds stopped sending to production.
What I learned
I would again audit before migrating and pin the output format with tests. I would also have added monitoring on batch failures from day one, since the tokenless bug ran for the whole earlier period unseen.
Stack
- TypeScript
- React Native
- MMKV
- IndexedDB
- JWT refresh
- Vitest
