3 ms·
I was wondering as well. How does that work with eventual consistency? Shouldn’t there be double bookkeeping so you don’t generate money out of the air?
by weitzj 6y ago
I was wondering as well. How does that work with eventual consistency? Shouldn’t there be double bookkeeping so you don’t generate money out of the air?
- weitzj 6y agoAlso it seems like the amount is of type number. Ideally you would calculate in Dollarcents or Eurocents (I.e. solely use integers) like 100 Eurocents equal 1€ So you do not have any rounding involved Also if a request comes in twice there are no requestids involved. Therefore it might be possible to generate another transaction it seems. There are great blog posts from Stripe engineers about these request ids to make requests idempotent with Postgres databases. I highly recommend reading them.
- kondro 6y agoNot sure about how Clojure treats numbers, but in DynamoDB these are treated as Decimals and don’t have floating-point rounding errors.
- tappio 6y agoDoes it allow to save values with floating point imprecision such as 1.000000001? I don't think the issue is never in the database but the service that uses the API to send values. If such value is allowed, it will cause headache and errors when the consumers of the API make mistakes. I think the general practice is to store them in integers, just for the sake of being foolproof.
- andriosr 6y agoYep. Integers they are: https://news.ycombinator.com/item?id=24435148 https://news.ycombinator.com/item?id=24435148
- kondro 6y agoYou pass “numbers” to DynamoDB as strings defined with the type N. As long as you aren’t using a floating point initially, DDB isn’t going to add any floating point imprecision itself.
- andriosr 6y agoTwo great points. The amounts are actually integer, the same pattern used by Stripe and others. See it here: https://github.com/decimals/sequence/blob/master/src/decimals/specs.clj#L10 https://github.com/decimals/sequence/blob/master/src/decimal... I'm working on enabling idempotent requests, should come out next week. I'm using the same pattern used by Stripe as well (big fan). An optional `x-request-id` header that will ensure only once processing if present. This is very important to enable consistency over the network with other services using the ledger.
- andriosr 6y agoIt maintains double-entry consistency of balances with DynamoDB. I uses DynamoDB (or any No-SQL) conditional puts. You can think of it as a update + where of SQL databases. But infinitely more scalable and available. Here is a piece I wrote about how it's achieved: https://decimals.substack.com/p/things-i-wish-i-knew-before-building https://decimals.substack.com/p/things-i-wish-i-knew-before-....
- zrail 6y agoIs DynamoDB baked into the product or could new adapters be written to use different key/value stores? Things like leveldb for local-only ledgers or even an adapter on top of PostgreSQL's jsonb field might be useful.
- andriosr 6y agoIt was designed to support multiple DBs. Adding a new adapter should be pretty easy. I will add the first for Datomic in the coming weeks. This should pave the way for the next ones (I will add some docs on this). I really believe on it supporting many DBs.
- andriosr 6y agojust created an issue on Github to keep track of this :)