---
title: "Building Balances II: High-throughput writes"
description: "Async balance updates for high-throughput workloads such as ledger migrations and marketplace payouts."
canonical: "https://fragment.dev/blog/building-balances-high-throughput-writes"
date: "Jun 4, 2025"
---

# Building Balances II: High-throughput writes

Date: Jun 4, 2025
Author: Vignesh Vaidyanathan
Position: Software Engineer

Source: https://fragment.dev/blog/building-balances-high-throughput-writes

[Documentation index](https://fragment.dev/llms.txt)

<a id="building-balances-high-throughput-writes"></a>

To ensure balances are up-to-date, Fragment seamlessly scales to support high-throughput workloads like ledger migrations, marketplace payouts, and batch payment processing.

This is the second post in a three-part series about the Fragment balance system. The [first post](https://fragment.dev/blog/building-balances-low-latency-reads.md) describes how the data model allows for efficient updates and low-latency reads. This post describes the architecture of async balance updates.

<a id="event-sourced-architecture"></a>

## Event-sourced Architecture

Fragment's balance system is event-driven. When a Ledger Entry is posted using the API, it's written to DynamoDB, pushed to a change data capture (CDC) stream, and replicated to an event bus. The balance system consumes these events to update async balances.

[Visual: high-throughput-event-bus. View on the HTML page.](https://fragment.dev/blog/building-balances-high-throughput-writes?mode=human)

This is implemented using AWS [DynamoDB Streams](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Streams.html), [EventBridge](https://aws.amazon.com/eventbridge/), and [SQS](https://aws.amazon.com/sqs/).

<a id="latest-balance"></a>

## Latest Balance

To increase throughput, Fragment calculates the latest balance of eventually consistent Ledger Accounts in batches.

[Visual: low-throughput-updates. View on the HTML page.](https://fragment.dev/blog/building-balances-high-throughput-writes?mode=human)

If processed individually, each event introduces latency and the probability of conflicting with DynamoDB's concurrency control mechanisms.

[Visual: high-throughput-updates. View on the HTML page.](https://fragment.dev/blog/building-balances-high-throughput-writes?mode=human)

With batching, the balance effects of multiple Ledger Entries can be coalesced into a single database update.

<a id="historical-balances"></a>

## Historical Balances

As described in the [previous post](https://fragment.dev/blog/building-balances-low-latency-reads.md), historical balances are stored as balance deltas at the hour, day, month, and year granularities.

[Visual: historical-balance-structure. View on the HTML page.](https://fragment.dev/blog/building-balances-high-throughput-writes?mode=human)

To increase throughput while maintaining deltas at different granularities, the balance deltas are calculated from most to least granular: hours, then days, months, and years.

[Visual: historical-balance-coalescing. View on the HTML page.](https://fragment.dev/blog/building-balances-high-throughput-writes?mode=human)

These additional layers of coalescing reduce the total number of writes, increasing write throughput.

<a id="performance"></a>

## Performance

To provide constant-time reads for any Ledger Account in the hierarchy requires pre-computing historical and hierarchical balances.

With 4 granularity levels, an average hierarchy depth of 5, and 4 lines per Ledger Entry, a typical Ledger Entry triggers 80 balance updates. At 10k Ledger Entries per second, the eventually consistent balance system has a p95 staleness of 10 seconds.

If building mission-critical financial infrastructure powering the next generation of financial products excites you, [we're hiring](https://fragment.dev/careers.md).

[Try for free](https://dashboard.fragment.dev/login)
