ByteByteGo 2024年08月20日
Trillions of Indexes: How Uber’s LedgerStore Supports Such Massive Scale
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

Uber LedgerStore 是 Uber 为管理金融交易数据而定制的存储解决方案,旨在处理海量数据并确保数据完整性。LedgerStore 支持三种主要类型的索引:强一致性索引、最终一致性索引和时间范围索引,以满足不同场景下的数据访问需求。本文将深入探讨 Uber 如何实现 LedgerStore 的索引架构,以及他们如何将数万亿条 Ledger 数据从 DynamoDB 迁移到 LedgerStore。

🤔 **强一致性索引**:提供即时读写保证,适用于需要实时数据一致性的场景,例如信用卡授权流程。Uber 使用两阶段提交方法来构建强一致性索引,确保数据的一致性和可靠性。 这种索引类型的关键在于它能确保在任何时刻,读取到的数据都是最新的,并且与写入的数据一致。这对于金融交易来说至关重要,因为任何延迟或不一致都可能导致错误的交易结果。Uber 在实现强一致性索引时,采用了两阶段提交方法,将写入操作分为两个阶段:首先写入索引意图,然后写入实际数据。只有当这两个阶段都成功完成,索引才算被提交。这种方法确保了数据的完整性和一致性。

⏳ **最终一致性索引**:适用于对实时一致性要求不高的场景,例如支付历史记录展示。Uber 使用 Docstore 的物化视图功能来实现最终一致性索引,通过异步更新来提高性能和可用性。 这种索引类型适用于对数据一致性要求不太高的场景,例如用户查看支付历史记录。在这种情况下,即使索引数据略微滞后,也不会影响用户体验。Uber 利用 Docstore 的物化视图功能来实现最终一致性索引,通过异步更新的方式,在提高性能和可用性的同时,也能保证最终的数据一致性。

⏱️ **时间范围索引**:用于高效查询特定时间范围内的数据,例如将旧数据卸载到冷存储或封存数据以符合合规性要求。Uber 使用 Docstore 的单表设计和分区策略来实现时间范围索引,并采用排序数据存储和并行扫描的方式来提高查询效率。 时间范围索引是 LedgerStore 中一个重要的组成部分,它可以帮助用户快速检索特定时间段内的交易数据。Uber 之前使用 DynamoDB 的双表设计来实现时间范围索引,但这种方法在操作上比较复杂。因此,他们将 LedgerStore 迁移到 Docstore,并采用了更简单高效的单表设计和分区策略。这种设计能够确保数据的均匀分布,避免热点分区和写入限制。此外,他们还采用了排序数据存储和并行扫描的方式,进一步提高了查询效率。

🔄 **索引生命周期管理**:负责索引的设计、修改和退役,确保数据完整性和一致性。Uber 使用状态机来管理索引的生命周期,确保每个步骤都正确完成,并维护数据完整性。 索引生命周期管理是 LedgerStore 架构中不可或缺的一部分,它负责管理索引的整个生命周期,包括创建、更新和删除。Uber 使用状态机来管理索引的生命周期,确保每个步骤都按照预定的流程进行,并进行必要的验证,以确保数据完整性和一致性。

📊 **历史索引数据回填**:当定义新的索引或修改现有索引时,需要将历史索引数据回填到新索引中,确保数据完整性和一致性。Uber 使用分布式任务框架来处理历史索引数据回填,并通过并行处理和错误处理机制来提高效率和可靠性。 当定义新的索引或修改现有索引时,需要将历史数据回填到新索引中,以确保数据的一致性。Uber 使用分布式任务框架来处理历史索引数据回填,并通过并行处理和错误处理机制来提高效率和可靠性。

🚀 **迁移过程**:Uber 将数万亿条 Ledger 数据从 DynamoDB 迁移到 LedgerStore,并使用分阶段迁移策略来减少对业务的影响。他们使用数据复制工具和数据验证工具来确保迁移过程顺利进行。 Uber 将数万亿条 Ledger 数据从 DynamoDB 迁移到 LedgerStore,为了确保迁移过程顺利进行,他们采用了分阶段迁移策略,并使用数据复制工具和数据验证工具来确保数据的完整性和一致性。

📊 **性能优化**:Uber 对 LedgerStore 的索引架构进行了优化,以提高查询性能和减少资源消耗。他们使用缓存、压缩和索引优化技术来提高效率。 Uber 为了提高 LedgerStore 的性能,对索引架构进行了优化,包括使用缓存、压缩和索引优化技术,以提高查询速度和减少资源消耗。

📈 **可扩展性**:LedgerStore 的索引架构可扩展性强,能够适应 Uber 业务的快速增长。他们使用分布式存储和分布式处理技术来实现可扩展性。 LedgerStore 的索引架构可扩展性强,能够适应 Uber 业务的快速增长。他们使用分布式存储和分布式处理技术来实现可扩展性。

Try Fully Managed Apache Airflow and get certified for FREE (Sponsored)

Run Airflow without the hassle and management complexity. Take Astro (the fully managed Airflow solution) for a test drive today and unlock a suite of features designed to simplify, optimize, and scale your data pipelines. For a limited time, new sign ups will receive a complimentary Airflow Fundamentals Certification exam (normally $150).

Get Started —>


Disclaimer: The details in this post have been derived from the Uber Engineering Blog. All credit for the technical details goes to the Uber engineering team. The links to the original articles are present in the references section at the end of the post. We’ve attempted to analyze the details and provide our input about them. If you find any inaccuracies or omissions, please leave a comment, and we will do our best to fix them.

Ledgers are the source of truth of any financial event. By their very nature, ledgers are immutable. Also, we usually want to access data stored in these ledgers in various combinations.

With billions of trips and deliveries, Uber performs tens of billions of financial transactions. Merchants, riders, and customers are involved in these financial transactions. Money flows from the ones spending to the ones earning. 

To manage this mountain of financial transaction data, the LedgerStore is an extremely critical storage solution for Uber. The myriad access patterns for the data stored in LedgerStore also create the need for a huge number of indexes.

In this post, we’ll look at how Uber implemented the indexing architecture for LedgerStore to handle trillions of indexes and how they migrated a trillion entries of Uber’s Ledger Data from DynamoDB to LedgerStore.

What is LedgerStore?

LedgerStore is Uber’s custom-built storage solution for managing financial transactions. Think of it as a giant, super-secure digital ledger book that keeps track of every financial event at Uber, from ride payments to food delivery charges.

What makes LedgerStore special is its ability to handle an enormous amount of data. We’re talking about trillions of entries.

Two main features supported by LedgerStore are:

Ultimately, LedgerStore helps Uber manage its financial data more effectively, reducing costs compared to previous solutions.

Types of Indexes

LedgerStore supports three main types of indexes:

Let’s look at each of them in more detail.

Strongly Consistent Indexes

These indexes provide immediate read-your-write guarantees, crucial for scenarios like credit card authorization flows. For example, when a rider starts an Uber trip, a credit card hold is placed, which must be immediately visible to prevent duplicate charges.

See the diagram below that shows the credit-card payment flow for an Uber trip supported by strongly consistent indexes.

If the index is not strongly consistent, the hold may take a while to be visible upon reading. This can result in duplicate charges on the user’s credit card.

Strongly consistent indexes at Uber are built using the two-phase commit approach. Here’s how this approach works in the write path and read path.

1 - The Write Path

The write path consists of the following steps:

The diagram below shows this entire process.

There is one special case to consider here: if the index intent write succeeds, but the record write fails, the index intent has to be rolled back to prevent the accumulation of unused intents. This part is handled during the read path.

2 - The Read Path

The below steps happen during the read path:

The diagram below shows the process steps in more detail.


Reserve Your Seat Now! | Upcoming Cohort on Aug 26th, 2024 (Sponsored) 

Build confidence without getting lost in technical jargon.

This cohort is designed to help you build a foundational understanding of software applications. You won’t just memorize a bunch of terms - you’ll actually understand how software products are designed and deployed to handle millions of users.

And our community will be here to give you the support, guidance, and accountability you’ll need to finally stick with it.

After only 4 weeks, you’ll look back and think.. “WOW! I can’t believe I did that.”

Now imagine if you could:

✅ Master technical concepts without getting lost in an internet maze.

✅ Stop asking engineers to dumb down concepts when talking to you.

✅ Predict risks, anticipate issues, and avoid endless back-and-forth.

✅ Improve your communication with engineers, users, and technical stakeholders.

Grab your spot now with an exclusive 25% off discount for ByteByteGo Readers. See you there!

Register Now!


Eventually Consistent Indexes

These indexes are designed for scenarios where real-time consistency is not critical, and a slight delay in index updates is acceptable. They offer better performance and availability at the cost of immediate consistency.

From a technical implementation point of view, the eventually consistent indexes are generated using the Materialized Views feature of Uber’s Docstore. 

Materialized views are pre-computed result sets stored as a table, based on a query against the base table(s). The materialized view is updated asynchronously when the base table changes.

When a write occurs to the main data store, it doesn’t immediately update the index. Instead, a separate process periodically scans for changes and updates the materialized view. The consistency window is configurable and determines how frequently the background process runs to update the indexes.

In Uber’s case, the Payment History Display screen uses the eventually consistent indexes.

Time-range Indexes

Time-range indexes are a crucial component of LedgerStore, designed to query data within specific time ranges efficiently.

These indexes are important for operations like offloading older ledger data to cold storage or sealing data for compliance purposes. The main characteristic of these indexes is their ability to handle deterministic time-range batch queries that are significantly larger in scope compared to other index types.

Earlier, the time-range indexes were implemented using a dual-table design approach in DynamoDB. However, it was operationally complex.

The migration of LedgerStore to Uber’s Docstore paved the path for a simpler implementation of the time-range index. Here’s a detailed look at the Docstore implementation for the time-range indexes:

For clarity, consider a query to fetch all ledger entries between “2024-08-09 10:00:00” and “2024-08-09 10:30:00”. The query would be broken down into three 10-minute scans:

Each of these scans would be executed across all shards in parallel. The results would then be merged and sorted to provide the final result set.

The diagram below shows the overall process:

Index Lifecycle Management

Index lifecycle management is another component of LedgerStore’s architecture that handles the design, modification, and decommissioning of indexes.

Let’s look at the main parts of the index lifecycle management system.

Index Lifecycle State Machine

This component orchestrates the entire lifecycle of an index:

The state machine ensures that each step is completed correctly before moving to the next, maintaining data integrity throughout the process.

The diagram below shows all the steps:

Historical Index Data Backfill

When new indexes are defined or existing ones are modified, it’s essential to backfill historical data to ensure completeness.

The historical index data backfill component performs the following tasks:

Index Validation

After indexes are backfilled, they need to be verified for completeness. This is done through an offline job that:

From a technical point of view, the component uses a time-window approach i.e. computing checksums for every 1-hour block of data. Even if a single entry is missed, the aggregate checksum for that time window will lead to a mismatch. 

For example, If checksums are computed for 1-hour blocks, and an entry from 2:30 PM is missing, the checksum for the 2:00 PM - 3:00 PM block will not match.

Migration of Uber’s Payment Data to LedgerStore

Now that we have understood about LedgerStore’s indexing architecture and capabilities, let’s look at the massive migration of Uber’s payment data to LedgerStore.

Uber’s payment platform, Gulfstream, was initially launched in 2017 using Amazon DynamoDB for storage. However, as Uber’s operations grew, this setup became increasingly expensive and complex. 

By 2021, Gulfstream was using a combination of three storage systems:

The primary reasons for migrating to LedgerStore were as follows:

The migration was a massive undertaking. Some statistics are as follows:

For reference, storing this data on typical 1 TB hard drives requires a total of 1200 hard drives just for the compressed data.

Checks

One of the key goals of the migration was to ensure that the backfill was correct and acceptable. Also, the current traffic requirements needed to be fulfilled.

Key validation methods adopted were as follows:

1 - Shadow Validation

This ensured that the new LedgerStore system could handle current traffic patterns without disruption.

Here’s how it worked:

2 - Offline Validation

While shadow validation was effective for current traffic patterns, it couldn’t provide strong guarantees about rarely-accessed historical data. This is where offline validation came into play. 

Here’s how it worked:

Backfill Issues

The process of migrating Uber’s massive ledger data from DynamoDB to LedgerStore involved several backfill challenges that had to be solved:

Conclusion

The impact of Uber’s ledger data migration to LedgerStore has been amazing, with over 2 trillion unique indexes successfully transferred without a single data inconsistency detected in over six months of production use. 

This migration, involving 1.2 PB of compressed data and over 1 trillion entries, showcases Uber’s ability to handle massive-scale data operations without disrupting critical financial processes. It also provides great learning points for the readers.

The cost savings from this migration have been substantial, with estimated yearly savings exceeding $6 million due to reduced spend on DynamoDB. Performance improvements have been notable, with LedgerStore offering shorter indexing lag and better network latency due to its on-premise deployment within Uber’s data centers.

References:

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Uber LedgerStore 索引架构 金融交易 数据管理
相关文章