# Democratising Fare Storage at Scale Using Event Sourcing

[Grab](https://yomu.fyi/company/grab) · Sourabh Suman · Nov 23, 2020

**Type:** Problem & solution

## Summary

Grab's legacy system stored booking and fare details in a single relational table, creating a bloated booking entity that tracked only the latest fare state and hindered rapid feature iteration. To resolve scalability, stability, and debugging challenges across millions of daily bookings, the team developed Fare Storage using the Event Sourcing pattern. The new architecture persists all fare modification events chronologically in DynamoDB, backed by a cache for eventually consistent reads and message streaming for downstream processing. The platform employs optimistic locking with versioning to manage concurrent updates, enforces idempotency through client-generated transaction UUIDs, and delegates metadata serialization to an SDK to prevent storage API changes.

## Context

Storing booking and fare details within a single relational database table bloated Grab's booking entity, threatened scaling and stability across millions of daily bookings, made schema updates prohibitively expensive, and lacked an audit trail of fare modifications.

## Approach / What changed

Building a decoupled Fare LifeCycle service using Event Sourcing backed by DynamoDB, utilizing optimistic locking for concurrency control, client-generated transaction UUIDs for idempotent retries, and client SDK-side metadata serialization into raw bytes.

## Takeaways

- Optimistic locking using incremented version numbers prevents race conditions during concurrent fare updates while offloading fare recalculation logic to client services.
- Idempotent event processing is maintained by having the client SDK generate a unique transaction UUID per event, enabling the store to reject duplicate retry submissions.
- Serializing metadata into raw bytes at the client SDK layer allows product teams to introduce new fee breakdowns without deploying updates to the central storage service.

**Tags:** [Architecture](https://yomu.fyi/topic/architecture), [Go](https://yomu.fyi/topic/go), [Reliability](https://yomu.fyi/topic/reliability), [Scalability](https://yomu.fyi/topic/scalability)

[Read original post](https://engineering.grab.com/democratising-fare-storage-at-scale-using-event-sourcing)
