Flakes
This lesson will cover the infrastructure of a Fluree ledger, including flakes, blocks, and triples. This background information is extremely helpful for gaining an intuitive understanding of Fluree. This first lesson will focus on flakes.
Before starting this lesson, it is useful to have completed Querying Basics or to have a basic understanding of Fluree and collections and predicates.
Subject-Predicate-Object
Fluree uses a standard structure for data called an RDF triple. Triples are made up of a subject, predicate, and object.
Subject
Every single item in a Fluree ledger is a subject, and whenever a new subject is created, it is automatically assigned a unique, unchangeable numeric id. i.e. 12345.
Predicate
Predicates are features of those subjects. i.e. "Full Name".
Object
Objects are the values of the predicates. i.e. "Jane Doe".
The resulting triple would therefore be: 12345. Full Name. Jane Doe.
That same subject, 12345, might have a lot of different triples:
Subject | Predicate | Object |
---|---|---|
12345 | Birthday | 1/30/85 |
12345 | Hair Color | Red |
12345 | Fav Nums | 7 |
12345 | Fav Nums | 28 |
As you can see above, some of those triples might even have the same predicate, i.e. a person might have more than one favorite number, so they could have two or more triples that list their favorite numbers.
Flakes and a Concept of Time
Because Fluree has a concept of time, we need to extend the standard RDF triple. In Fluree, our triples are actually five-tuples, and we call them flakes. Flakes are assertions of a fact at a given point in time. They are made up of:
- Subject
- Predicate
- Object
- Time - the moment at which a fact is asserted.
- Operation - true/false - whether we are asserting or retracting a fact.
For example:
Subject | Predicate | Object | Time | Operation |
---|---|---|---|---|
12345 | Hair Color | Red | 1/1/2019 | true |
12345 | Birthday | 1/30/85 | 1/1/2019 | true |
12345 | Fav Nums | 7 | 1/1/2019 | true |
12345 | Full Name | Jane Doe | 1/1/2019 | true |
12345 | Fav Nums | 28 | 1/1/2019 | true |
So, from January 1, 2019 and onwards, 12345's full name was Jane Doe, hair color was red, birthday was Jan. 30, and favorite numbers were 7 and 28. At any point in the future, Jane might change her hair color to brown and add a new favorite number.
Subject | Predicate | Object | Time | Operation |
---|---|---|---|---|
12345 | Hair Color | Red | 1/1/2019 | true |
12345 | Birthday | 1/30/85 | 1/1/2019 | true |
12345 | Fav Nums | 7 | 1/1/2019 | true |
12345 | Full Name | Jane Doe | 1/1/2019 | true |
12345 | Fav Nums | 28 | 1/1/2019 | true |
12345 | Hair Color | Red | 2/1/2019 | false |
12345 | Hair Color | Brown | 2/1/2019 | true |
12345 | Fav Nums | 101 | 2/1/2019 | true |
We can see that, as of 2/1/2019, 12345 retracts the statement that her hair is red, and asserts that her hair is brown. Additionally, we will always be able to go back in the database, and see what color Jane's hair was during January.
Notice that when Jane got a new favorite number, we didn't retract any of her old favorite numbers. Between 1/1/2019 and 1/31/2019, Jane's favorite numbers were 7 and 28. From 2/1/2019 on, her favorite numbers were 7, 28, and 101.