2. Overview
- What’s NoSQL?
- Distributed DB basics
- FaunaDB
- Fauna Query Language (FQL)
- Demo!
- Questions
3. NoSQL
- AKA Not Only SQL
- Common usecases: real-time, big data
- K-V, document store, graph…
- Generally scale horizontally
- Store data based on its access patterns, in contrast to relational
4. NoSQL compromises
- Many do not provide ACID guarantees
- BASE (basically available, soft state, eventually consistent) guarantees
- Consistency (in the CAP sense) usually loses out, though not always
- PACELC!
5. Distributed system consensus
How can we reach agreement across nodes, given that they may fail or become
unreachable?
- Paxos
- Google Spanner, Neo4J
- Raft
- Consul, FaunaDB
Consensus algorithms formally proven (TLA+)
7. Calvin transactional protocol
- 2012 paper by Thomson et al
- Transaction scheduling and data replication layer
- Separate ordering transactions from executing transactions
- Deterministic ordering -> execute transactions in parallel across replicas
- Linear scaling, no single point of failure
- Clock skew doesn’t matter, so no need for atomic clocks (Spanner)
8. Calvin transactional protocol
However, there’s a price!
- Transactions can’t happen interactively
- Transactions must be pure
- Minimum latency as transaction window must finish
9. FaunaDB
- Multiple paradigm NoSQL (document, relational, graph)
- Each transaction is a single query expression
- ACID guarantees, snapshot isolation to strict serializability
- Serverless (generally) pricing model
- Used by nVidia, Nextdoor & others
10. FaunaDB Transactions
- Uses Calvin + Raft
- Coordinator node chooses a snapshot time with which to make read
requests.
- If there are writes, a commit phase starts. Reads include last update
timestamps -> optimistic lock acquisitions.
- Read timestamps + writes committed to transaction log.
- Transaction resolution in parallel across data partitions.
- A transaction is committed and durable if no concurrent write to any read
values has occurred.
11. Fauna Query Language (FQL)
In SQL terms:
Schema ~=> Database
Table ~=> Class
Row ~=> Instance
12. Fauna Query Language (FQL)
Can do the usual things like creating a database (schema) and class (table)
CreateDatabase({name: "employees"})
CreateClass({name: "office"})
Note that class structures are not defined at create time!
13. Fauna Query Language (FQL)
If all members of a class should share a property, we can add an index.
CreateIndex({
name: "office_by_id",
source: Class("office"),
terms: [{ field: [ "data", "id" ] }],
unique: true
})
14. Fauna Query Language (FQL)
We can also use lambda functions inside an FQL expression
Map(Arr("MCR","LON","NYC"),
Lambda("office_id",
Create(Class("office"), {data: "id", Var("office_id")})))
This will create three offices for us.
15. Fauna Query Language (FQL)
Plus other ‘traditional’ programming concepts like:
- Let-bindings
- If statements
- Filter/map/foreach/take
Expressive enough to capture business logic in a database transaction.
16. FaunaDB Demo
- Start a local cluster (can use cloud too)
- fauna shell to interact with it