-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(hydro_lang): initial website docs on core Hydro concepts
- Loading branch information
Showing
25 changed files
with
306 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
sidebar_position: 3 | ||
--- | ||
|
||
# Safety and Correctness | ||
Just like Rust's type system helps you avoid memory safety bugs, Hydro helps you ensure **distributed safety**. Hydro's type systems helps you avoid many kinds of distributed systems bugs, including: | ||
- Non-determinism due to message delays (which reorder arrival) or retries (which result in duplicates) | ||
- See [Live Collections / Eventual Determinism](./live-collections/determinism.md) | ||
- Using mismatched serialization and deserialization formats across services | ||
- See [Locations and Networking](./locations/index.md) | ||
- Misusing node identifiers across logically independent clusters of machines | ||
- See [Locations / Clusters](./locations/clusters.md) | ||
- Relying on non-determinstic clocks for batching events | ||
- See [Ticks and Atomicity / Batching and Emitting Streams](./ticks-atomicity/batching-and-emitting.md) | ||
|
||
These safety guarantees are surfaced through the Rust type system, so you can catch these bugs at compile time rather than in production. And when it is necessary to bypass these checks for advanced distributed logic, you can use the same `unsafe` keyword as in Rust as an escape hatch. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"label": "Live Collections", | ||
"position": 4, | ||
"link": { | ||
"type": "doc", | ||
"id": "hydro/live-collections/index" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
sidebar_position: 0 | ||
--- | ||
|
||
# Bounded and Unbounded Types | ||
Although live collections can be continually updated, some collection types also support **termination**, after which no additional changes can be made. For example, a live collection created by reading integers from an in-memory `Vec` will become terminated once all the elements of the `Vec` have been loaded. But other live collections, such as one being updated by the network, may never become terminated. | ||
|
||
In Hydro, certain APIs are restricted to only work on collections that are **guaranteed to terminate** (**bounded** collections). All live collections in Hydro have a type parameter (typically named `B`), which tracks whether the collection is bounded (has the type `Bounded`) or unbounded (has the type `Unbounded`). These types are used in the signature of many Hydro APIs to ensure that the API is only called on the appropriate type of collection. | ||
|
||
## Converting Boundedness | ||
In some cases, you may need to convert between bounded and unbounded collections. Converting from a bounded collection **to an unbounded collection** is always allowed and safe, since it relaxes the guarantees on the collection. This can be done by calling `.into()` on the collection. | ||
|
||
```rust,no_run | ||
# use hydro_lang::*; | ||
# use dfir_rs::futures::StreamExt; | ||
# let flow = FlowBuilder::new(); | ||
# let process = flow.process::<()>(); | ||
# let tick = process.tick(); | ||
# let numbers = process.source_iter(q!(vec![1, 2, 3, 4])); | ||
let input: Stream<_, _, Bounded> = // ... | ||
# unsafe { numbers.timestamped(&tick).tick_batch() }; | ||
let unbounded: Stream<_, _, Unbounded> = input.into(); | ||
``` | ||
|
||
```rust,no_run | ||
# use hydro_lang::*; | ||
# use dfir_rs::futures::StreamExt; | ||
# let flow = FlowBuilder::new(); | ||
# let process = flow.process::<()>(); | ||
# let tick = process.tick(); | ||
let input: Singleton<_, _, Bounded> = tick.singleton(q!(0)); | ||
let unbounded: Singleton<_, _, Unbounded> = input.into(); | ||
``` | ||
|
||
Converting from an unbounded collection **to a bounded collection**, however is more complex. This requires cutting off the unbounded collection at a specific point in time, which may not be possible to do deterministically. For example, the most common way to convert an unbounded `Stream` to a bounded one is to batch its elements non-deterministically using `.tick_batch()`. | ||
|
||
```rust,no_run | ||
# use hydro_lang::*; | ||
# use dfir_rs::futures::StreamExt; | ||
# let flow = FlowBuilder::new(); | ||
# let process = flow.process::<()>(); | ||
let unbounded_input = // ... | ||
# process.source_iter(q!(vec![1, 2, 3, 4])); | ||
let tick = process.tick(); | ||
let batch: Stream<_, _, Bounded> = unsafe { | ||
unbounded_input.timestamped(&tick).tick_batch() | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Live Collections | ||
Traditional programs (like those in Rust) typically manipulate **collections** of data elements, such as those stored in a `Vec` or `HashMap`. These collections are **fixed** in the sense that any transformations applied to them such as `map` are immediately executed on a snapshot of the collection. This means that the output will not be updated when the input collection is modified. | ||
|
||
In Hydro, programs instead work with **live collections** which are expected to dynamically change over time as new elements are added or removed (in response to API requests, streaming ingestion, etc). Applying a transformation like `map` to a live collection results in another live collection that will dynamically change over time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
sidebar_position: 3 | ||
--- | ||
|
||
# Singletons and Optionals | ||
:::caution | ||
|
||
The Hydro documentation is currently under active development! This page is a placeholder for future content. | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
sidebar_position: 2 | ||
--- | ||
|
||
# Streams | ||
:::caution | ||
|
||
The Hydro documentation is currently under active development! This page is a placeholder for future content. | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"label": "Locations and Networking", | ||
"position": 5, | ||
"link": { | ||
"type": "doc", | ||
"id": "hydro/locations/index" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
sidebar_position: 1 | ||
--- | ||
|
||
# Clusters | ||
:::caution | ||
|
||
The Hydro documentation is currently under active development! This page is a placeholder for future content. | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
sidebar_position: 2 | ||
--- | ||
|
||
# External Clients | ||
:::caution | ||
|
||
The Hydro documentation is currently under active development! This page is a placeholder for future content. | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Locations and Networking | ||
Hydro is a **global**, **distributed** programming model. This means that the data and computation in a Hydro program can be spread across multiple machines, data centers, and even continents. To achieve this, Hydro uses the concept of **locations** to keep track of _where_ data is stored and computation is executed. | ||
|
||
Each live collection type (`Stream`, `Singleton`, etc.) has a type parameter `L` which will always be a type that implements the `Location` trait (e.g. `Process` and `Cluster`, documented in this section). Most Hydro APIs that transform live collections will emit a new live collection with the same location type as the input, and APIs that consume multiple live collections will require them all to have the same location type. | ||
|
||
To create distributed programs, live collections can be sent over the network using a variety of APIs. For example, `Stream`s can be sent from a process to another process using `.send_bincode(&loc2)` (which uses [bincode](https://docs.rs/bincode/latest/bincode/) as a serialization format). The sections for each location type discuss the networking APIs in further detail. | ||
|
||
## Creating Locations | ||
Locations can be created by calling the appropriate method on the global `FlowBuilder` (e.g. `flow.process()` or `flow.cluster()`). These methods will return a handle to the location that can be used to create live collections and run computations. | ||
|
||
:::caution | ||
|
||
It is possible to create **different** locations that still have the same type, for example: | ||
|
||
```rust | ||
# use hydro_lang::*; | ||
let flow = FlowBuilder::new(); | ||
let process1: Process<()> = flow.process::<()>(); | ||
let process2: Process<()> = flow.process::<()>(); | ||
|
||
assert_ne!(process1, process2); | ||
# let _ = flow.compile_no_network::<deploy::MultiGraph>(); | ||
``` | ||
|
||
These locations will not be unified and may be deployed to separate machines. When deploying a Hydro program, additional runtime checks will be performed to ensure that input locations match. | ||
|
||
```rust | ||
# use hydro_lang::*; | ||
let flow = FlowBuilder::new(); | ||
let process1: Process<()> = flow.process::<()>(); | ||
let process2: Process<()> = flow.process::<()>(); | ||
|
||
# test_util::assert_panics_with_message(|| { | ||
process1.source_iter(q!([1, 2, 3])) | ||
.cross_product(process2.source_iter(q!([1, 2, 3]))); | ||
// PANIC: assertion `left == right` failed: locations do not match | ||
# }, "assertion `left == right` failed: locations do not match"); | ||
# let _ = flow.compile_no_network::<deploy::MultiGraph>(); | ||
``` | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
sidebar_position: 0 | ||
--- | ||
|
||
# Processes | ||
:::caution | ||
|
||
The Hydro documentation is currently under active development! This page is a placeholder for future content. | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"label": "Ticks and Atomicity", | ||
"position": 6, | ||
"link": { | ||
"type": "doc", | ||
"id": "hydro/ticks-atomicity/index" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
sidebar_position: 3 | ||
--- | ||
|
||
# Atomicity and Timestamps | ||
:::caution | ||
|
||
The Hydro documentation is currently under active development! This page is a placeholder for future content. | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
sidebar_position: 1 | ||
--- | ||
|
||
# Batching and Emitting Streams | ||
:::caution | ||
|
||
The Hydro documentation is currently under active development! This page is a placeholder for future content. | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
sidebar_position: 0 | ||
--- | ||
|
||
# The Tick Execution Model | ||
:::caution | ||
|
||
The Hydro documentation is currently under active development! This page is a placeholder for future content. | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Ticks and Atomicity | ||
By default, all live collections in Hydro are transformed **asynchronously**, which means that there may be arbitrary delays between when a live collection is updated and when downstream transformations see the updates. This is because Hydro is designed to work in a distributed setting where messages may be delayed. But for some programs, it is necessary to define local iterative loops where transformations are applied atomically; this is achieved with **ticks**. | ||
|
||
## Loops | ||
In some programs, you may want to process batches or snapshots of a live collection in an iterative manner. For example, in a map-reduce program, it may be helpful to compute aggregations on small local batches of data before sending those intermediate results to a reducer. | ||
|
||
To create such iterative loops, Hydro provides the concept of **ticks**. A **tick** captures the body of an infinite loop running locally to the machine (importantly, this means that ticks define a **logical time** which is not comparable across machines). Ticks are non-deterministically generated, so batching data into ticks is an **unsafe** operation that requires special attention. | ||
|
||
## Atomicity | ||
In other programs, it is necessary to define an atomic section where a set of transformations are guaranteed to be executed **all at once**. For example, in a transaction processing program, it is important that the transaction is applied **before** an acknowledgment is sent to the client. | ||
|
||
In Hydro, this can be achieved by placing the transaction and acknowledgment in the same atomic **tick**. Hydro guarantees that all the outputs of a tick will be computed before any are released. Importantly, atomic ticks cannot span several locations, since that would require a locking mechanism that has significant performance implications. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
sidebar_position: 2 | ||
--- | ||
|
||
# Stateful Loops | ||
:::caution | ||
|
||
The Hydro documentation is currently under active development! This page is a placeholder for future content. | ||
|
||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.