3 ms·
Also 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
by weitzj 6y ago
Also 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.