Milvus Storage-Compute Separation Series-3: Storage-Compute Dual Writing
First published on Medium
Preface
Continuing from the previous article, let’s return to the issue of real-time visibility of data. The target mechanism in Milvus actually only solves part of the problem, namely making data that has already been written to disk visible through the target advancement mechanism. This mechanism is similar to the “flush” feature in Lucene, where only flushed data can be queried, and unflushed data cannot be queried. This approach is not a significant issue in share-nothing architectures; for example, Elasticsearch fully accepts Lucene’s flush mechanism, providing “near real-time” queries by setting the flush interval to 1 second, making newly written data visible after 1 second. However, for architectures like Milvus, which involve storage-compute separation and cloud-native principles, if newly written data must go through the process of writing to object storage and then downloading before it can be queried, achieving “near real-time” becomes challenging. Even ignoring the issue of small files caused by a too short flush interval, the delay caused by this upload-download process alone cannot achieve “near real-time.” This article will explore how Milvus addresses the problem of making the latest data visible in real-time.
Sync and Unsynced Data
Storage-Compute Dual Reading
Dual reading means that both storage nodes and compute nodes perform queries and then merge the results. As shown in the diagram below, there is no intersection between the hot data on the storage nodes and the synced data on the compute nodes. The query is split into two paths, where it queries the hot data and synced data separately, resulting in hot_result and synced_result, which are then merged and returned to the client. The advantage of this approach is that there is no redundant data, following the “compute follows data” style. However, the downside is that storage nodes may be affected by the computational load.
2. Storage-Compute Dual Writing
And dual writing means that the same data is written to both storage nodes and compute nodes. As shown in the diagram above, when a query occurs, the query only needs to be sent to the compute nodes to obtain the complete data. The advantage of dual writing is that storage nodes do not have to bear the computational load, but the downside is data redundancy, which can create significant memory pressure.
Milvus’s Storage-Compute Dual Writing Mechanism
In summary, whether it’s dual writing or dual reading, both require significant additional resources and complexity to meet the real-time data requirements under a storage-compute separation architecture. Milvus chooses dual writing for this problem. The main reason is that the computational workload for vector queries is substantial, and CPU resources are limited, while the CPU demands for storage nodes are relatively low. Therefore, if storage nodes were tasked with real-time computation, there could be severe contention for CPU resources, especially when CPU resources are insufficient and under heavy pressure. Moreover, when resource allocation is high but query pressure is not enough, it’s not easy to scale back to save resources. Hence, adopting dual writing, accepting some data redundancy leading to memory consumption, allows computational demands and resources to be concentrated on compute nodes, achieving better scalability. This approach is more advisable for cloud-native database architectures.
As shown in the diagram above, the entire process of storage-compute dual writing is as follows:
- Proxy appends insert messages to the message queue (typically Pulsar or Kafka).
- QueryNodes and DataNodes consume the data from the message queue, generating identical growing segments. At this point, queries point to the GrowingSegment and sealedSegment on the QueryNode, and the latest inserted data is also queryable.
- DataNodes periodically sync the growing segments to object storage.
- Metadata of the synced segments is synchronized to etcd.
- MixCoord watches the etcd key and notifies QueryNodes to load the latest sealed segment when a new sealed segment is detected.
- QueryNodes load the latest sealed segment, at which point the original growing segment is no longer valuable.
- The original growing segment on the QueryNode is released.
In summary, this article started with the requirement for real-time visibility of the latest data and introduced Milvus’s solution for ensuring real-time queryability through storage-compute dual writing and the entire dual writing process.
— MrPresent-Han



