fluree / server

Fluree Server - Operates Fluree in consensus, fault-tolerant, redundant
12 stars 1 forks source link

Fluree Server

Creating and updating ledgers must be done by a service that not only has the rights to update them, but is also responsible for the current ledger state and persisting updates to storage.

While this can be done using just Fluree's db library (using, for example, IPFS for persistent storage), for an environment that will have many clients, like an app with many users, it is typical to want dedicated server(s) to handle consistent transaction ordering, communicating out ledger updates, redundancy, and other "server" features that would be expected for a reliable, scalable, and fault-tolerant environment.

Fluree Server provides these features. It can be run stand-alone, in conjunction with Fluree's db library, or as a cluster of servers providing scale and/or distributed consensus, or all of the above. You can start with a single server while in development, then add more servers once ready to scale.

Fluree Server can be run as either a consensus-participating node processing transactions/updates, or as query-only server that scales out query processing horizontally, and to the edge if desired. Fluree Server can have any number of consensus-participating nodes that together reliably maintain ledger updates for any number of ledgers.

Note that Fluree's db library, which can be included directly into your application, can also process queries which not only provides further scale, but can wrap a distributed database with your custom functionality at in-memory speeds. Your app can benefit from timely, fast, and simple information lookups/queries, eliminating the need to make remote db calls.

Designing a Fluree Server network

Fluree Server runs as either a consensus participating node + query server, or as a query-only server depending on the startup configuration. While a single server can be run as both a consensus participating node and a query server, it lacks fault-tolerance and redundancy (if using local storage, vs cloud/IPFS storage).

Three connected Fluree Servers running consensus is the recommended minimum for a production environment, which will provide fault-tolerance and redundancy allowing any single server to fail with zero downtime. Three servers also provide scale, as any of them can serve query results and transaction processing will be split amongst them for different ledgers being maintained.

For additional query scale, you'd typically start adding one or more query-only servers that connect to the consensus servers. Query servers are ephemeral, are great for containerization and auto-scaling. They can also be deployed at the edge for performance. Query-only servers accumulate ledger index data in-memory (up to your configured max memory) and garbage collect the least recently used data once the memory allocated is full. The in-memory index data allows for fast query processing at the edge.

When using query-only servers, you'd typically have your clients/apps connect to them instead of directly to the consensus servers. Transactions received by the query-only servers are forwarded to the consensus servers for processing, and they utilize a CQRS pattern to communicate ledger updates back to the connected clients. For private ledgers, it would be typical to put the consensus servers in a private network, and have the query-only servers in a public network such that no clients could connect directly to the consensus servers.

For added redundancy, scale, fault-tolerance, or to accommodate a number of decentralized participants in a network you can run more than 3 consensus servers. The failure formula 2f+1=n applies, where f is the number of servers that can fail with the network still being able to reach consensus, and n is the total number of servers in the network. So, for example, if you wanted to allow for 2 failures while still maintaining consensus and uptime, you'd need 5 servers (2*2+1=5). If you wanted to allow for 3 server failures, you'd need 7 servers (2*3+1=7). As you'll note, the number of servers is always an odd number as >50% of the network must be "alive", and therefore while an even number of servers is allowed, it is not recommended.

Usage

Settings

Configuration is handled through environment variables, with defaults provided via resources/config.edn file. See the Fluree docs for more information.

The most common environment variables to set would include:

Features

Development

Dependencies

Run make prepare to compile the required dependencies to enable Clojure development.

Code linting

Git hooks