System Design Handbook · llms.txt
A personal finance tracker pulls every purchase from your bank and card accounts into one place. Say you link your checking account and two credit cards. The next morning the app shows that you spent $412 on food this month, that $1,800 went to rent, and that you are at 85% of your $500 food budget with ten days to go. You never typed in a single purchase.
Mint was the best-known app of this kind. It started in 2006 and Intuit bought it in 2009. In late 2023, Intuit announced that it would close Mint and moved its users to Credit Karma, another Intuit product. Mint shut down on March 23, 2024. Coverage at the time noted that Credit Karma did not offer Mint's monthly and per-category budgets. The design problem outlived the product, and apps like it still need the same parts.
It's a good interview question because the hard parts are unusual. Most of the data comes from thousands of banks outside your system. The system writes far more than it reads, since people buy things every day but open a budgeting app much less often. And it holds the keys to people's bank accounts.
This chapter follows the four steps from The system design interview, step by step: use cases and numbers, a high-level design, the core components in detail, and then scaling.
We'll scope the problem to these use cases:
These are made-up inputs for the exercise. None of them come from Mint or any other real product.
First, how big is one transaction? Count only the fields we need to analyze spending:
user_id: 8 bytescreated_at (when the purchase happened): 5 bytesseller: 32 bytesamount: 5 bytesA month has about 30 × 86,400 = 2,592,000 seconds, or roughly 2.6 million. Handy conversions:
Now the numbers:
What these numbers tell us. The system is write-heavy and bursty: most writes land during the nightly update. Reads are light, about 200 a second, and a cache can absorb most of them. The transactions table is the thing to plan for, because it grows by 250 GB of payload a month and will outgrow a single database within a few years. The seller map is tiny, so every worker can keep a copy in memory. And extraction spends most of its time waiting on banks, so it needs many concurrent workers more than it needs fast ones.
We could store information about the 10 million users in a relational database. Accounts belong to users, transactions belong to accounts, and budgets belong to users. These are clear relationships with foreign keys, and 30 million accounts is small. The SQL or NoSQL question is worth raising, but relational is the natural start here.
The flow:
accounts table in the SQL Database.The interesting question is what "the new account" contains. There are two ways an app can get at someone's bank data.
The old way: store the user's bank login. The user types their online-banking username and password into the app. The app saves them, logs in to the bank's website as the user, and copies the transactions off the page. This is called screen scraping. A table for it looks like this:
CREATE TABLE accounts (
id BIGINT NOT NULL AUTO_INCREMENT,
user_id BIGINT NOT NULL,
created_at DATETIME NOT NULL,
last_update DATETIME NOT NULL,
account_url VARCHAR(255) NOT NULL, -- the bank's login page
account_login VARCHAR(32) NOT NULL,
account_password_encrypted VARBINARY(256) NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (user_id) REFERENCES users(id)
);
Notice the password column. For your own users' passwords you store a slow, salted hash, because you only ever need to check a password, never read it back (see Storing passwords). A bank password is different. The extractor has to type it into the bank's login form every day, so the app must be able to recover it. A hash can't be reversed, so a design that stores account_password_hash cannot work. The password has to be stored encrypted, and that means anyone who gets both the database and the key gets millions of bank logins. Mint's early design worked this way, and in 2010 critics pointed out that it stored bank logins in a form that could be decrypted.
The modern way: an aggregator and a token. The user never gives the app their bank password. Instead:
public_token.access_token that stands for this one bank login. Plaid calls a bank login an Item. One Item can cover several accounts, such as checking and savings at the same bank.Mint itself moved this way. In January 2017, Chase and Intuit announced a deal under which Intuit products such as Mint would get Chase data through a token, "without requiring customers to give Intuit their Chase user name and password". The US Consumer Financial Protection Bureau (CFPB) pushed the whole industry in the same direction. Its Personal Financial Data Rights rule, finalized in October 2024 under section 1033 of the Consumer Financial Protection Act of 2010, requires banks to share a customer's data with apps the customer authorizes, free of charge, and aims to move the industry away from screen scraping. It also limits third parties to using the data for the product the customer asked for. The rule's future is unsettled. The CFPB began reconsidering it in August 2025, and as of April 2026 a federal court in Kentucky had blocked its enforcement while that happens. Check the CFPB's page for the current status. Either way, tokens are the design to choose.
Our accounts table, using an aggregator:
CREATE TABLE accounts (
id BIGINT NOT NULL AUTO_INCREMENT,
user_id BIGINT NOT NULL,
created_at DATETIME NOT NULL,
last_update DATETIME NULL,
institution_name VARCHAR(64) NOT NULL,
aggregator_item_id VARCHAR(64) NOT NULL,
access_token_enc VARBINARY(512) NOT NULL, -- encrypted access token
token_key_id VARCHAR(64) NOT NULL, -- which data key encrypted it
sync_cursor VARCHAR(256) NULL, -- where the last fetch stopped
status VARCHAR(16) NOT NULL, -- active, needs_reauth, revoked
PRIMARY KEY (id),
FOREIGN KEY (user_id) REFERENCES users(id)
);
We'll create an index on id, user_id and created_at. An index turns a lookup into a search through a sorted tree, which takes logarithmic time, instead of a scan of the whole table. A small, frequently used index also stays in memory. In the classic latency table, reading 1 MB sequentially from memory takes about 250 microseconds, from an SSD about 4 times longer, and from a spinning disk about 80 times longer.
The token is the most sensitive thing in the system, so protect it in layers:
token_key_id records which data key to ask the KMS to unwrap.revoked, and delete the token.We'll use a public REST API. Linking an account:
POST /api/v1/accounts
Authorization: Bearer <session token>
Content-Type: application/json
{ "public_token": "public-production-3f2a..." }
HTTP/1.1 201 Created
Content-Type: application/json
{
"account_id": 81234,
"institution": "Example Bank",
"status": "active",
"first_sync": "queued"
}
The user's ID comes from the session, never from the request body, so nobody can link an account to someone else's profile. The old screen-scraping version of this call sent account_url, account_login and account_password in the body instead, which is exactly what we want to avoid.
Between our own services we could use RPC, such as gRPC. Internal calls are many, small and between services we control, which is where RPC is at its best. The comparison of RPC and REST covers the trade-off.
Once the account is saved, the service fetches its transactions.
We extract transactions from an account in three cases:
Data flow:
202 Accepted. Extracting transactions can take a while, so we do it asynchronously with a queue. The cost is extra moving parts: a queue to run, retries, and jobs that may run twice.transactions table in the SQL Database with the categorized transactions.monthly_spending table. The Budget Service uses the Notification Service to tell users they are nearing or have exceeded a budget.A few details make this pipeline correct in practice:
/transactions/sync endpoint returns a next_cursor with each page. You store it (our sync_cursor column) and pass it back next time to get only the changes since then: added, modified and removed transactions. Plaid also sends a SYNC_UPDATES_AVAILABLE webhook when new data is ready, and its documentation says it checks banks for updates one to four times a day depending on the institution. So "update daily" can be driven by webhooks, with the scheduler as a safety net.(account_id, external_id), then insert with "insert or update". Running a job twice then leaves the table the same, which is what idempotent workers means.needs_reauth, stop retrying, and ask the user to reconnect. Send other failures through retries and a dead-letter queue.The transactions table:
CREATE TABLE transactions (
id BIGINT NOT NULL AUTO_INCREMENT,
user_id BIGINT NOT NULL,
account_id BIGINT NOT NULL,
external_id VARCHAR(64) NOT NULL, -- the bank's ID for this transaction
created_at DATETIME NOT NULL, -- when the purchase happened
seller VARCHAR(32) NOT NULL,
amount DECIMAL(12,2) NOT NULL,
category VARCHAR(32) NOT NULL,
category_source VARCHAR(8) NOT NULL, -- seed, crowd, user or none
PRIMARY KEY (id),
UNIQUE (account_id, external_id),
FOREIGN KEY (user_id) REFERENCES users(id)
);
Three choices here are worth saying out loud:
id is a BIGINT. A 32-bit signed INT tops out at about 2.1 billion. At 5 billion new rows a month it would overflow in under two weeks.amount has an explicit scale. In MySQL, a bare DECIMAL means DECIMAL(10,0), which has no digits after the decimal point and would silently round $43.10 to $43. Money needs DECIMAL(12,2), or an integer count of cents. Never use floating point for money.category_source records where the category came from.We'll create an index on id, user_id and created_at. The most common query is "this user's transactions this month", so a composite index on (user_id, created_at) serves it best.
The monthly_spending table holds one total per user, month and category:
CREATE TABLE monthly_spending (
user_id BIGINT NOT NULL,
month_year DATE NOT NULL, -- first day of the month
category VARCHAR(32) NOT NULL,
amount DECIMAL(12,2) NOT NULL,
PRIMARY KEY (user_id, month_year, category),
FOREIGN KEY (user_id) REFERENCES users(id)
);
A surrogate id column with separate indexes on id and user_id would also work. The composite primary key is simpler: it's the exact lookup the app makes, it keeps one user's rows together on disk, and it makes "insert or update the total" a single statement.
The Category Service answers one question: given a seller, which category? The seller string on a transaction comes from the bank, and it's messy. The same coffee shop can show up as SQ *BLUE BOTTLE 0423 one day and BLUE BOTTLE COFFEE OAKLAND CA the next. So the first step is to normalize it: uppercase it, strip payment-processor prefixes, store numbers and city names, and map the result to a canonical seller.
Then look the seller up, in this order:
The crowd count needs care. Keeping a heap per seller would let you peek at the top category in O(1), but every new vote changes a count inside the heap, and re-sorting it costs O(log n). There's a simpler structure. Votes only ever go up, so keep a counter per seller and remember the current leader. When a vote comes in, bump the count and compare it with the leader's count. Both the update and the lookup are O(1).
from collections import Counter, defaultdict
from enum import Enum
class Category(Enum):
HOUSING = "housing"
FOOD = "food"
GAS = "gas"
SHOPPING = "shopping"
UNCATEGORIZED = "uncategorized"
SEED = {
"EXXON": Category.GAS,
"SHELL": Category.GAS,
"TARGET": Category.SHOPPING,
"SAFEWAY": Category.FOOD,
# ... the 50,000 most common sellers
}
class CrowdVotes:
"""Counts users' manual overrides per seller and tracks the leader."""
def __init__(self, min_votes=25):
self.min_votes = min_votes
self.counts = defaultdict(Counter) # seller -> Counter of categories
self.leader = {} # seller -> category with most votes
def record(self, seller, category):
counts = self.counts[seller]
counts[category] += 1
current = self.leader.get(seller)
if current is None or counts[category] > counts[current]:
self.leader[seller] = category
def top(self, seller):
category = self.leader.get(seller)
if category and self.counts[seller][category] >= self.min_votes:
return category
return None
class Categorizer:
def __init__(self, seed, crowd, user_rules):
self.seed = seed
self.crowd = crowd
self.user_rules = user_rules # (user_id, seller) -> Category
def categorize(self, user_id, raw_seller):
"""Return (category, source) for one transaction."""
seller = normalize(raw_seller)
if (user_id, seller) in self.user_rules:
return self.user_rules[(user_id, seller)], "user"
if seller in self.seed:
return self.seed[seller], "seed"
crowd_pick = self.crowd.top(seller)
if crowd_pick:
return crowd_pick, "crowd"
return Category.UNCATEGORIZED, "none"
def normalize(raw_seller):
"""'SQ *SHELL OIL 5741' -> 'SHELL'. Real code uses a lookup of aliases."""
...
min_votes stops one user's odd choice from changing the category for everyone. The crowd's answer applies to new transactions only. Transactions that already have a category keep it, which matches the "no automatic re-categorization" use case: a user's past months should not shift under them because other users voted.
When a user changes a transaction's category, three things happen:
category = 'food', category_source = 'user'.monthly_spending for that month, since money just moved from one category to another.PATCH /api/v1/transactions/99812
Content-Type: application/json
{ "category": "food", "apply_to_seller": true }
"apply_to_seller": true also saves a rule for this user, so future purchases from the same seller land in Food too.
Start with a generic budget template that splits income across categories, with different splits for different income tiers. Someone earning $3,000 a month might get a template that puts more into housing and less into shopping than someone earning $12,000. The user's income can come from their profile or from the paychecks the app sees arriving.
The template saves storage. The budget is a function of income, so we don't need to store the 100 million budget items from step 1. We store only the categories a user has changed, in a budget_overrides table:
CREATE TABLE budget_overrides (
user_id BIGINT NOT NULL,
category VARCHAR(32) NOT NULL,
amount DECIMAL(12,2) NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY (user_id, category),
FOREIGN KEY (user_id) REFERENCES users(id)
);
If one user in five overrides three categories, that's 2 million × 3 = 6 million rows instead of 100 million.
from decimal import Decimal
# Share of monthly income per category, by income tier. Illustrative numbers.
TEMPLATES = [
(Decimal("4000"), {Category.HOUSING: Decimal("0.35"), Category.FOOD: Decimal("0.15"),
Category.GAS: Decimal("0.06"), Category.SHOPPING: Decimal("0.08")}),
(Decimal("10000"), {Category.HOUSING: Decimal("0.30"), Category.FOOD: Decimal("0.12"),
Category.GAS: Decimal("0.05"), Category.SHOPPING: Decimal("0.10")}),
(None, {Category.HOUSING: Decimal("0.25"), Category.FOOD: Decimal("0.10"),
Category.GAS: Decimal("0.03"), Category.SHOPPING: Decimal("0.12")}),
]
def template_for(monthly_income):
for upper_limit, shares in TEMPLATES:
if upper_limit is None or monthly_income < upper_limit:
return shares
def budget_for(monthly_income, overrides):
"""overrides: {Category: Decimal} loaded from budget_overrides."""
budget = {
category: (monthly_income * share).quantize(Decimal("1"))
for category, share in template_for(monthly_income).items()
}
budget.update(overrides) # the user's own numbers win
return budget
Setting a budget by hand is one call:
PUT /api/v1/budgets/food
Content-Type: application/json
{ "amount": "450.00" }
The Budget Service keeps monthly_spending up to date. There are two ways to compute it.
Option 1: SQL. Run a query on the transactions table:
SELECT user_id, category, SUM(amount)
FROM transactions
WHERE created_at >= '2026-10-01' AND created_at < '2026-11-01'
GROUP BY user_id, category;
The result has far fewer rows than the input, since each user has many transactions a month. But at 5 billion rows a month, a query like this competes with the nightly writes on the same database. A cheaper variant is to update totals as each batch of transactions arrives: "add $43.10 to (user 42, October, Food)".
Option 2: MapReduce on the raw files. The extractor already writes raw transactions to the object store as log files. A MapReduce job reads those files in parallel across many machines. Its map step turns each line into a key and a value. A shuffle groups equal keys together. Its reduce step combines each group's values. (The batch processing chapter explains the model in depth.) Here, one job can:
Running this analysis on the files instead of the database takes a large load off the database. If a user changes a category, the Budget Service can re-run the analysis for that user and month.
The log file is tab-separated, one transaction per line. We add the transaction ID so the job can apply per-transaction overrides:
user_id transaction_id timestamp seller amount
A sketch of the job, with a tiny local driver that plays the part of the cluster:
from collections import defaultdict
from decimal import Decimal
def mapper(line, categorizer, txn_overrides, month):
"""One log line in, at most one ((user, month, category), amount) pair out.
'42\t9001\t2026-10-03T18:22:05\tSAFEWAY #1234\t43.10'
-> (('42', '2026-10', 'food'), Decimal('43.10'))
"""
user_id, txn_id, timestamp, seller, amount = line.rstrip("\n").split("\t")
if timestamp[:7] != month:
return # only the month we're totalling
category = txn_overrides.get(txn_id) # the user's manual choice wins
if category is None:
category, _source = categorizer.categorize(user_id, seller)
yield (user_id, month, category.value), Decimal(amount)
def reducer(key, amounts):
"""(('42', '2026-10', 'food'), [43.10, 12.50]) -> total 55.60"""
yield key, sum(amounts, Decimal("0"))
def run_locally(lines, categorizer, txn_overrides, month):
groups = defaultdict(list) # the shuffle: collect values by key
for line in lines:
for key, amount in mapper(line, categorizer, txn_overrides, month):
groups[key].append(amount)
for key in sorted(groups):
yield from reducer(key, groups[key])
Two details matter. The amounts are parsed as Decimal, because adding strings or floats gives wrong totals. And txn_overrides is the set of manual overrides for that month. It is small enough to send to every mapper, so a user's choice is respected even though the raw file still holds the bank's original data.
After the totals are written, the Budget Service compares each one with the user's budget. If spending has crossed 80% or 100%, it asks the Notification Service to send an alert. A job may run several times a day and may be retried, so the service must not send the same alert twice. Record each alert sent with a key of (user_id, month, category, threshold) and send only if inserting that key succeeds.
THRESHOLDS = (Decimal("0.8"), Decimal("1.0"))
def check_budget(user_id, month, category, spent, limit, alerts_sent, notify):
for threshold in THRESHOLDS:
key = (user_id, month, category, threshold)
if spent >= limit * threshold and key not in alerts_sent:
alerts_sent.add(key) # in production: INSERT with a unique key
notify(user_id, category, spent, limit, threshold)
Budget alerts don't need to be instant, so they go through the Notification Service's queue. That service handles delivery, retries and the user's channel preferences. Design a notification system covers it in depth.
Don't jump straight from the first design to the final one. Scaling is a loop: benchmark with a load test, profile to find the bottleneck, fix it while weighing the alternatives, and repeat. Design a system that scales to millions of users on AWS walks through that loop one step at a time. Here we look at what the step-1 numbers predict, and at what each added component costs. Internal load balancers between services are left out of the diagrams to reduce clutter.
The scaled system has two halves. The first serves users:
The second does the background work:
From step 1:
DNS points the app's domain at the load balancer. Static files, such as the app's JavaScript, CSS and images, are stored in an object store such as Amazon S3 and cached on a CDN. The CDN serves them from servers near the user, so those requests never reach our web servers. The cost is another service to pay for and a delay before changed files reach every CDN location.
A load balancer spreads requests across several web servers, and the web servers spread them across several Read API and Accounts API servers. If one server fails, the others carry on, which serves the high-availability use case. Keep the API servers stateless, with sessions in the shared memory cache, so any server can handle any request. The cost is that the load balancer itself must be redundant, usually as an active-passive pair, or it becomes the new single point of failure. Load balancing covers the trade-offs of scaling out.
This use case is new in this step. When a user opens the app, they see their spending by category for this month and their recent transactions. Those are the hottest reads, and they change at most a few times a day, after each update. So we put user sessions, per-category totals and recent transactions in a Memory Cache such as Redis or Memcached.
This is cache-aside. It suits this workload: reads are uneven, with spikes on the first of the month and after payday, and the cache absorbs them. The cost is staleness. When the extractor writes new transactions for a user, it should delete that user's cached summary, so the next read rebuilds it. When to update the cache compares cache-aside with write-through, write-behind and refresh-ahead.
Add read replicas: copies of the database that receive every write from the primary and serve reads. With most reads answered by the cache, a couple of replicas should handle the cache misses, as long as replicating the heavy nightly writes doesn't leave them far behind. The primary has a standby that takes over if it fails (fail-over).
The cost of replicas is replication lag. A user who changes a category and immediately reloads might see the old category if the read goes to a replica that hasn't caught up. For a few seconds after a user's own write, send that user's reads to the primary (reading your own writes).
The MapReduce jobs and monthly totals are analytical work: they scan many rows and add them up. That workload differs from the app's small reads and writes (the batch chapter explains OLTP versus OLAP). Instead of keeping monthly_spending in the main SQL database, we could keep it in a separate Analytics Database built on a data warehouse such as Amazon Redshift or Google BigQuery. The cost is another system and a copy of the data that's a little behind. The read API can still serve a user's totals from the cache.
Most reads are about the current month. So we might keep only the most recent month or few months of transactions in the SQL database, and keep older ones in the data warehouse or the Object Store. An object store such as Amazon S3 handles 250 GB of new data a month easily, and it costs far less per gigabyte than database storage. The cost: a user who scrolls back a year now hits a slower path, and the app needs a clear rule about which store holds which months.
2,000 writes a second on average, and several times that at peak, might be too much for a single SQL primary. Several SQL scaling patterns help:
transactions table across several databases by user_id. Every query in this app is about one user, so each query goes to one shard, and one user's rows stay together. Sharding by date would send all of tonight's writes to the same shard. Watch for a few users with huge volumes, and split hot shards when they appear.user_id on each transaction is already a small example: it saves joining through accounts for every "my transactions" query.We should also consider moving transactions to a NoSQL database. A wide-column store such as Cassandra, keyed by user_id and sorted by created_at, is built for a heavy, steady stream of writes and for "this user's recent rows" queries. The cost is weaker transactions and no ad hoc joins, which this table rarely needs anyway. See NoSQL databases.
The extraction workers are the other big consumer of capacity. They spend most of their time waiting on banks, so they scale by adding more workers or more concurrent fetches per worker. Sizing workers with Little's Law gives the method: about 2,800 fetches in flight at peak.
Each of these changes fixes one bottleneck and moves the pressure somewhere else. Keep benchmarking, profiling and fixing. Scaling is an iterative process.
Storing bank credentials or using tokens. Screen scraping with stored passwords works with any bank that has a website, but it makes your database a vault of bank logins, it breaks whenever a bank redesigns its login page, and it's the practice the CFPB's rule aims to end. An aggregator with OAuth tokens means the user logs in at the bank, access can be revoked without changing the bank password, and you never see the password. The cost is a dependency on the aggregator, and paying for it. Pick tokens, and protect them with encryption at rest and least privilege.
Precomputing totals or computing them on read. Computing "spending by category" on each page view would mean summing a user's month of transactions every time. That's 5 billion ÷ 10 million = 500 rows for an average user by the end of the month, read on every page view, during spikes too. Precomputing into monthly_spending makes reads trivial, at the cost of keeping the totals correct when categories change. Since reads are rare and writes are frequent, it's tempting to compute on read. The deciding factor is the budget alerts: they need the totals after every update anyway, so precompute.
SQL aggregation, MapReduce or running totals. A SQL GROUP BY is simplest and fine at small scale. MapReduce on the raw files moves the work off the database and can recompute any month from scratch. Updating running totals as each batch lands is the cheapest but drifts if any update is lost or applied twice. A good answer combines them: running totals for freshness, plus a nightly batch recompute that corrects any drift. The batch job has to be idempotent, overwriting totals instead of adding to them.
A budget template or stored budgets. Storing all 100 million budget items is simple and makes every budget a row you can query. The template stores only overrides, about 6 million rows under our guess, but every budget lookup has to compute the template first. Since the computation is a few multiplications, the template wins.
How categories are learned. A seed map plus crowd votes is easy to explain and to debug. A machine-learning classifier on seller names, amounts and times would handle sellers with no votes, but it's harder to explain when it's wrong. Aggregators also return their own categories: Plaid's personal_finance_category field is filled for a typical 95% of transactions. You might start with that and let users and crowd votes refine it. Whichever you choose, keep the rule that a category, once set, doesn't change on its own.
Daily batch or real time. Daily updates and slow alerts let us batch work and skip inactive users. For "alert within a minute of the purchase", you'd feed aggregator webhooks into a streaming pipeline that updates running totals, which costs more to run.
Four hours is 4 × 3,600 = 14,400 seconds. 30,000,000 ÷ 14,400 ≈ 2,080 jobs a second. By Little's Law, the number in flight is the arrival rate times the time each one takes: 2,080 × 2 s ≈ 4,200 concurrent fetches.
That's mostly waiting on the network, so it's a job for many lightweight concurrent requests. But 4,200 concurrent calls may exceed what the aggregator allows. Check the rate limits before committing, and point out that refreshing inactive users costs money for data nobody looks at.
The transaction row gets category = 'food' and category_source = 'user'. The Category Service records a vote that Shell is Food. One vote is far below min_votes, so Shell stays Gas for everyone else, and nobody's past transactions change. The Budget Service recomputes this user's totals for that month: Gas goes down by $60 and Food goes up by $60. It may then send a Food alert if that pushed Food over 80%. Finally, the cached summary for this user is deleted, so the next page load shows the new numbers. If the read goes to a replica, it should go to the primary for a few seconds so the user sees their own change.
A hash is one-way. It's the right way to store your own users' passwords, because you only need to check them. The extractor needs the bank password itself, to log in to the bank every day, so a hash is useless. The only way to make screen scraping work is to store the password encrypted, and then a breach of the database and the key leaks bank logins for millions of people.
The better fix is to avoid holding the password at all. Connect through an aggregator with OAuth, store only the access token, encrypt it with keys held in a KMS, and let only the extractor decrypt it.
The extractor inserted rows without any way to tell that it had already inserted them. A retried job fetched the same transactions and inserted them again. The fix is to store the bank's own transaction ID with a unique constraint on (account_id, external_id), and to write with "insert or update". Then a repeated job changes nothing.
The monthly totals need the same care. If the Budget Service adds each batch to a running total, a retry adds it twice. Either recompute the month's total from the transactions, which gives the same answer however many times it runs, or record which batches were already applied.
The budget check probably runs after every update, and maybe again on retries. Each run sees spending above 80% and sends an alert. The check needs memory of what it already sent. Record each alert with a unique key of (user_id, month, category, threshold), and send only when inserting that key succeeds. The insert and the send can still be split by a crash, so the Notification Service should also drop duplicates by the same key.
DECIMAL has no digits after the decimal point.Previous: Design a real-time gaming leaderboard · Next: Design a payment system and gateway