151 points · by andriosr · 6y ago · 102 comments
I'm Rob and I want to share what I've built - a solid ledger behind simple API: https://decimals.app
The ledger is a key piece of any financial system and is easy to get the design wrong, resulting in troubles for making sure money movements are adding up.
I took a lot of inspiration from good designs from Square, Uber, and others for the scalability and security aspects. And on the usability side, I applied many concepts from the Ledger CLI, making it very easy to use.
I'm really happy I get to show this to you all, thank you for reading about it! Please let me know your thoughts and questions in the comments (The sample code on the landing page is not working, I'm fixing it).
[1] https://www.ledger-cli.org/
[2] https://www.youtube.com/watch?v=iN6mhI5hFt4
[3] https://developer.squareup.com/blog/books-an-immutable-doubl...
If anyone is wondering about this, the basic business challenge you have to solve is being in the right place at the right time. This kind of thing is very sticky once its in place, and most startups don't realize the complexity in the domain early enough for a stand-alone service to make sense to them.
I think as far as startups in this space go, the best path forward would be to nurture an open source project in the long term.
I ended up open sourcing my work after the pivot here: https://github.com/affiga/scaledger
Its internal, only our systems have access, each user/customer is auto created an account on signup, we hold the private keys encrypted with the user's password so we can't access the key itself, keeps track of everything with 100% consistency.
1s block mining and raft consensus settings so pretty much instant and low resource utilization...and massively scalable.
Sorry to say but if I am in any type of fintech, I would never ever outsource keeping track of my customer's account balances and source of truth.
"We really wanted to use a blockchain and it is the main reason why we build the company in the first place so we never questioned that choice".
If the product poster is using has that property, then perhaps is a reasonable choice.
Postgres does not have any ledger balancing primitives.
The same way Lyft would not even consider using Stripe in its first two years, considering how critical credit card data is for them.
I really like the design you have internally! I would love to hear more about it, can we talk?
Stripe's amazing service also comes at a substantial premium. For a high-volume thin-margin company like Lyft where every penny counts, per transaction fees at 2.9%+ are killers. Furthermore, large companies prefer to own the raw card data themselves as the interchange rates for card not present debit cards is different than card not present credit cards. Once you hit a certain amount of scale this .15% difference is substantial.
(edit: I missed that parent comment was about trust in a 3-person startup, but point is still somewhat valid)
Have no idea if there's a market for this (I'm certainly not a customer), but something none of these libraries are set up to do is convert these balances to erc-20 tokens. The combo of a SaaS with a simple API like this and a trusted mint to sync balances to erc-20 tokens could be interesting.
What a schlep.
I’m curious, do you store currency values as decimal dollars or integral cents?
// Transfer $10 from Alice to Bob
decimals.transactions.create({
from_account: 'Alice',
to_account: 'Bob',
currency: 'usd',
amount: 1000
})They can represent anything you want, cents, mils, and so on.
Personally, never liked the apps that used integers for what in the real/human world are decimals. I understand (sort of) why they are used from a tech perspective. But ultimately, tech is used by humans.
At some point, in tech you are going to have to create an abstraction at some layer. The upper the layer, the more the abstraction should resemble what humans see as "normal".
Did you know all numbers are stored in "registries" in the computer memory. Is a registry a number? NO! It's just bits.
At what point can you actually treat a "variable" as an actual "decimal"?
How does a storage system actually save a decimal number? Not sure, and up to some point I don't care, as long as I know the accuracy and trade-offs I'm getting.
I guess my point is, using integers sets to represent a decimal number is okay if it is coping with the lower layers' limits. If a lower layer already provides a proper solution, then there is no need to provide the same.
But ultimately, abstractions are what matter and what has allowed us to progress. All you need to know about an abstraction is its limits and compromises.
2 point decimals can usually be accurate but given enough operations, you can sometimes get a weird floating error and rounding / clamping is discouraged in banking.
In your code sample, you use from: 'Alice' but list transactions for some kind of complicated balance ID. Where did that ID come from?
When you first use a given currency on an Account, a Balance is created along with its id.
The ID comes from the list of balances of the Alice Account.
Also, shouldn't decimals.transactions.create be asynchronous?
You get the most value when you do more transactions, so that's why we don't charge for that, we don't want companies limiting what they to with Decimals to save money.
Also important to note is that this is not one more layer in the payment cake taking a percentage of your revenue, the pricing is based on API usage, with no relation to your revenue.
Only note is that the runkit environment doesn't seem to be working. "Error: Cannot find module 'decimals'"
From past experiences, on a reasonably big company (>100 engineers) that needs to do these money movements checks, it would save at least 3 engineers from support/evolution and not counting the development time for a good ledger.
On the cost side, the goal is to charge on average 1/10 of what you currently spend, so cost is actually a feature. I'm working on a self-hosted version for some customers that are asking for it, but not due to reliability of HTTP over the internet, I would love to hear more about this. Can we chat?
1. How do you handle / plan to handle multi-currency accounts? (normalize to single currency vs. Selinger's approach https://www.mscs.dal.ca/~selinger/accounting/tutorial.html) 2. What tech did you use to build all this? db/languages etc.
The API is currency agnostic, so one account can have many balances from multiple currencies attached to it. However, you can't do transactions cross currencies at the moment. You can do it on your side, and use the API to store the result, both normalized and Selinger are doable. I definitely plan to add this at some point, thanks for the reference, it's great!
On the tech side, the service is written in Go, and the database is DynamoDB, everything runs on AWS right now. I'm planning to add support for Cassandra and MongoDB, as some enterprise customers want to run it inside their datacenters.
In addition to the problem @joshuakelly mentioned, I think one of the challenges here will be to gain trust. Asking someone else to keep track of your books is a pretty tall ask. How does it affect a given company's auditing? What about SOC Compliance etc? I would suggest you try to address some of these things.
Best!
> Hi!
I run a startup trying to make it easier to create systems that store transactions and balances.
I found your contact searching the stargazers of the php Money lib: https://github.com/moneyphp/money
Are you using it?
The project is in the early stages, I have nothing to sell. I need help to make sure I will build something useful.
-- Rob.
Most SQL ledgers are just a table of transactions. What happens when you have an error/typo in a transaction? SQL databases will ensure that your error gets safely committed to disk, with zero built in machinery to detect what double entry knows to be an error in the data.
(I don't know if OP actually solves that problem in their service, but this is the key idea in double entry.)
Cheers.
I'm using DynamoDB, but any no-SQL database will do the work (currently working on Cassandra and MongoDB connectors to enable self-hosting for enterprise customers)
On the implementation side, it's a mix of both: I'm using the conditional insert/optimistic locking of no-SQL and modeled the ledger to be a hash-chain at the application layer. The design is actually simple, and it scales indefinitely.
Besides that, I'm using DynamoDB streams to build roll-ups of the transactions and make sure that all transactions are always balancing to zero in real-time.
Are you actually seeing demand for on-prem hosting? Serious demand such that you would lose the sale from a customer you cannot live without? Completely different support model and neither Cassandra and especially Mongo are anywhere near Dynamo.
I also have seen plenty of cases where balance to zero only at end of day is feasible, but real time is a good way of picking the right customers. My completely unsolicited advice- do the same with the DB, stay away from customers who say they need prem. But I'm just a schmo on the internet. Very best of luck to you!
You can of course- and people do all the time- encode those kinds of "business rules" into application code, or into database code like triggers, but:
1) the abstraction level you are operating at in the double entry domain is around balanced accounts. Having a "ledger database" that provides that kind of abstraction to your application so that you are not solving for balancing transactions all over the place in application code is very important. Important for the same reason that using a SQL database saves you from having to worry about two phase commit and transaction logs and so forth in your application code when saving sensitive data. The guarantees a SQL database offers are lower level than what one needs in a ledger database.
2) to your point of "at scale"- at scale a double entry system often accepts some kinds of unbalanced transactions, and then has workflows to support various kinds of reconciliation. A lot of this reconciliation is time based- every bank to this day at least does reconciliation at the end of each business day with "close of business" batch processing jobs. Some can also do it intraday. At scale means a lot of additional actual "business rule" complexity.
Hope that helps?
These rules are not expressible in what SQL databases consider to be field-level constraints. They can be expressed in triggers, but doing that is the path of pain.
Let me know what you think. Thanks!
I think maybe you should do a detailed blog post comparing the difference with the default course of action developers take when they need to record transactions with the benefits decimals provide.
At a loans company I worked at before, we just used a transactions table and generated accounting reports using SQL.
I've signed up for early access and tried replying to your emails but I am unable to reply to your decimals app email address, I get mail failut. Please reach out with another email, could really use this.
collin at waystocap
- Next to nothing in terms of expense graphs.
- Terrible API for polling for alerts based on reports.
- Saving custom reports not really a thing.
- Mobile app is hot garbage.
- Bank feeds drop a lot.
- My accounting firm not a fan.
- One light blue skin forever, like being relegated to a blue hell.
- Integrates with things like Zapier & Integromat, but not deeply.
- Parsing JSON reporting via Integromat is pure pain.
One thing that is in the roadmap is to bring data from Xero so that you can interact with it in Decimals. It should give you a much better API, and we make sure it's going to get synced in the background. Let me know if this is something you might be interested in getting early access.
Immutability of transactions is obviously a fundamental necessity and coupling this with GraphQL seems like a great fit.