Task
I designed and launched the backend of a personal finance tracker with accounts, categories, transactions, budgets and summaries. The app reached 100K+ sign-ups.
I designed and launched the backend of a personal finance tracker with accounts, categories, transactions, budgets and summaries. The app reached 100K+ sign-ups.
Two problems came up as the app grew. A transfer between a user's own accounts was counted as an expense on one account and income on the other, and the transaction feed read too many rows as the history got longer.
Counting a transfer as spending and income inflated the turnover and showed income that did not exist. The feed query paged with a growing offset, so every next page cost more.
I made a transfer its own entity with two linked sides, written in one PostgreSQL transaction. For different currencies it keeps both amounts and the rate used, and a repeated request with the same key does not create a second transfer. For the feed I first tried a cache, but clearing it after edits made things harder. I read the query with EXPLAIN ANALYZE, the PostgreSQL tool that shows how a query runs, added a composite index, moved to cursor paging by date and id, and removed the cache.
A rollback when the second record fails, a retry after a timeout, a category change near the month boundary, the order on equal timestamps, the ownership of transactions and the query plan on a filled database.
Balance and statistics no longer drift because of money moving between accounts, and a long history loads predictably.