Skip to content

Commit 6532875

Browse files
committed
docs: database design philosophies
1 parent cd42309 commit 6532875

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

DATABASE.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# One Database, many services
2+
3+
Often when a microservices architecture is assembled, each service has its own state (which
4+
manifests itself as a database for each service). I've worked on a couple different projects where
5+
this architecture has prevailed and it's made tracing the effect of a given request on a system
6+
really difficult.
7+
8+
In Backstroke, the database is treated like any other service. As few services are given database
9+
access as possible, and unidirectional data flow is enforced whenever possible to minimize the
10+
bugs related to the system's shared mutable state.
11+
12+
Currently, only two bits of code have database access - the `server` service and the
13+
`operation-dispatcher` job.
14+
15+
The `server` service handles all of the CRUD operations for links and link operations. CRUD
16+
intrinsically requires some sort of persistence layer in order to store the state of the resource
17+
being acted upon. Most importantly, this is the only service that writes to the database.
18+
19+
The `operation-dispatcher` job handles automatic link updates. Once every ten minutes, it checks to
20+
make sure that a link is up to date, and if it isn't, it will dispatch a new link operation into the
21+
link queue.
22+
23+
## What about redis?
24+
The Backstroke system does have one common bit of shared state: they all communicate with each other
25+
using Redis. However, two important characteristics have been carefully designed around to minimize
26+
any problem that this shared state would have:
27+
28+
1. Redis is used as a temporary cache to hold all items in the link operation queue, and to store
29+
the response of link operations. These are both ephemeral values and expire after 24 hours. If redis
30+
were cleared and all services restarted, the system would loose no permanant data.
31+
32+
2. Outside of the queue, Redis is used as an append-only data source where everything expires. This
33+
was purposely chosen to attempt to eliminate potential sources for race conditions and other
34+
nasty, hard to detect bugs. The queue is managed by rsmq, an external queueing system, which helps
35+
to make this data storage mechanism safer.
36+
37+
# Database Schema
38+
(coming soon)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This repository documents how sub-systems within Backstroke interact to perform
55
- [Redis: How the worker accepts jobs and provides status updates](REDIS.md)
66
- [Operation Dispatcher: How do links automatically update?](OPERATION_DISPATCHER.md)
77
- [Request Tracing: How to follow a request through the entire system via its request id](REQUEST_TRACING.md)
8-
- Database: General philosophies and a database schema
8+
- [Database: General philosophies and a database schema](DATABASE.md)
99
- Dashboard: How users log into the dashboard and update links
1010

1111
![services](https://user-images.githubusercontent.com/1704236/33268089-d718e718-d349-11e7-9baa-75d86d05604b.png)

0 commit comments

Comments
 (0)