*rqlite* is a distributed system that provides a replicated SQLite database. rqlite is written in [Go](http://golang.org/) and uses [Raft](http://raftconsensus.github.io/) to achieve consensus across all the instances of the SQLite databases. rqlite ensures that every change made to the database is made to a majority of databases, or none-at-all.
[SQLite](http://www.sqlite.org/) is a "self-contained, serverless, zero-configuration, transactional SQL database engine". The entire database is contained within a single file on disk, making working with it very straightforward. Many people have experience with it, and it's been a natural choice for adding relational-database functionality to many systems. However, SQLite isn't replicated, which means it can become a single point of failure if used to store metadata about cluster of manchines. While it is possible to continually copy the SQLite file to a backup server everytime it is changed, this file-copy must not take place while the database is being accessed.
This starts a rqlite server listening on localhost, port 4001. This single node is automatically becomes the leader. To see all available command-line options, execute:
rqlite exposes an HTTP API allowing the database to modified and queried. Modifications go through the Raft log, ensuring only changes committed by a quorom of Raft servers are actually executed against the SQLite database. Queries do not go through the Raft log, since they do not change the state of the database, and therefore do not need to be captured in the log.
### Writing Data
To write data to the database, you must create at least 1 table.
curl -XPOST localhost:4001/db -d 'CREATE TABLE foo (id integer not null primary key, name text)'
To insert an entry into the database, execute a second command:
curl -XPOST localhost:4001/db?pretty -d 'INSERT INTO foo(name) VALUES("fiona")'
The use of the URL param `pretty` is optional, and results in pretty-printed JSON responses.
#### Transactions
Transactions are supported. For example, to execute two statements within a transaction, separate them with a newline and add `transaction` to the URL like so:
Depending on your machine, individual INSERT performance could be anything from 1 operation per second to more than 10 operations per second. However, by using transactions, throughput will increase significantly, often by 2 orders or magnitude. This speed-up is due to the way SQLite works.
An Admin API exists, which dumps some basic diagnostic and statistical information. Assuming rqlite is started with default settings, the endpoints are available like so:
curl localhost:4001/diagnostics?pretty
curl localhost:4001/statistics?pretty
The use of the URL param `pretty` is optional, and results in pretty-printed JSON responses.
This project uses the [go-raft](https://github.com/goraft/raft) implementation of the Raft consensus protocol, and was inspired by the raftd reference implementation. I also borrowed some ideas from [etcd](https://github.com/coreos/etcd).