Design
Requirements
-
minimal operational effort needed
-
Stateless for simple Fail-over
-
Stateless for horizontal scalability (for reading)
-
well-known data persistence layer for ease of operation
-
well-known data persistence layer to be future proof in the light of the german data protection laws (and yes, that’s not a trivial one)
-
fast enough when writing
-
fast for reading
-
simple (!) enough for teams with very different tools to be able to integrate with their chosen environment
-
excessive write performance (as in high speed trading)
-
full-blown Application Framework
Choices
Based on the aforementioned requirements, let us highlight some technical choices.
PostgreSQL for Persistence
Some Reasons for choosing PostgreSQL as persistence layer for the Events:
Serializability / Atomicity |
Both technical requirements are trivial when choosing a RDBMS, due to its ACID nature and the availability of Sequences. |
Familiarity |
Monitoring, Alerting, Backup, Point in time recovery, Authentication / Authorization, read-replication, fail-over, … All of those are properties of a good RDBMS and it is hard to find more mature solutions than the ones we can find there. |
Flexible Queries |
While Document datastores like MongoDB certainly have more to offer here, PostgreSQL is surprisingly good with JSON. FactCast uses GIN Indexes on JSONB Columns in order to find matching facts for subscriptions easily. |
Coordination |
With |
Read-Replicas |
Solved problem, that might help you with more than moderate traffic. While we would rather consider partitioning your Facts, in the first place, it might be a welcome 'last resort' when you have lots and lots of subscribers. |
Cloud-ready |
With AWS RDS for instance, it is rather trivial to setup and operate a PostgreSQL that satisfies the above needs. It is unlikely to find a respectable cloud platform without postgresql. |
gRPC
When it comes to raw performance, REST might not always be the best option. In order to offer a more compact transport, but yet stay platform neutral, FactCast also has a gRPC API. gRPC has a lot of implementations in languages like:
-
C++
-
Java
-
Python
-
Go
-
Ruby
-
C#
-
Node.js
-
Android Java
-
Objective C
-
and even PHP
Official documention: grpc.io
Spring Boot (Server)
Spring Boot is a simple Framework to quickly spin up Java Servers. The FactCast Server is implemented using Spring Boot as a container.
Spring (gRPC Client)
In order to make it easy to use the gRPC Client from java, the factcast-client-grpc module depends on Spring as well. This dependency is not exactly tight, so if there is a good reason to, you might want to implement a gRPC Client free of Spring dependencies. If so, let us know.
Limitations
Multi-Region Distribution with Primary/Primary Replication
FactCast is written (and works out of the box) for deployments that contain any number of FactCast Servers that <b>share one PostgreSQL database</b>. To be clear: the FactCast Server itself is horizontally scalable and capable of load-balancing and failover.
While this might sound like a major limitation, it actually hardly is due to several performance optimizations within the FactCast server, as well as the extensive scalability and failover options of today’s cloud offerings.
While there is no technical reason you cannot use FactCast in a multi-database scenario, you’ll have to give it a little thought. If you have doubts, feel free to contact us to discuss your situation.