Design JIRA (Issue Tracker)
medium 60 minTrack work as issues that move across a board under rules each team writes for itself.
See it run
Create, move, find and order issues, one hop at a time. Then two hands on one card, rules in a loop, and a search that is down.
Operations
Create an issue
One transaction makes the number, the issue, the history and the event. Everything slow comes later.
Step 1 of 10
Fill in the form
fields
summary, type
The browser checks required fields at once, for comfort. The server will check again.
Step 1: Fill in the form
def create(tenant, person, body): check_fields_and_rights(tenant, person, body) with db.transaction() as tx: n = tx.next_number(body.project) # row lock, rolls back too issue = tx.insert_issue(n, body, version=1) tx.insert_history(issue, "created") tx.insert_outbox("issue.created", issue.id) return 201, issue.key- Latency
- 100 to 200 ms
- Load
- part of 3,500 changes/s
Ask of each step: if we crash here, what does the world see?
In the real world
The same issue tracker doing real jobs. Pick one and step through it.
Noor and Max both saw version 3.
Step 1 of 4
Both ask
Noor wants Test, Max wants Done.
Step 1: Both ask
Common mistakes
The bugs interviewers watch for, with the fix beside each.
Check, then write without a version
criticalBoth people pass the check, and history shows a forbidden path.
Wrongif allowed(issue.status, to): db.set_status(id, to)Rightn = db.execute( "UPDATE issues SET status_id=%s, version=version+1" " WHERE id=%s AND version=%s", (to, id, seen))if n == 0: raise ConflictPermissions after the search
criticalThe total and the short page reveal hidden issues.
Wronghits = es.search(q)return [h for h in hits if may_see(h)], hits.totalRighthits = es.search(and_(scope(person), q))return hits, hits.totalA webhook inside the transaction
majorLocks are held while a foreign server thinks, and a rollback cannot unsend it.
Wrongwith db.transaction(): set_status(...) http.post(hook)Rightwith db.transaction(): set_status(...) outbox.add("webhook", hook)An index field for every custom field
majorElasticsearch limits an index to 1,000 fields by default.
Wrongdoc["cf_" + field.id] = valueRightdoc[slot_for(tenant, field)] = value # number_7Tenant as a courtesy
criticalOne forgotten clause shows another company's data.
WrongSELECT * FROM issues WHERE id = $1RightSELECT * FROM issuesWHERE tenant_id = $tenant AND id = $1-- and row-level security as a second fence
Interview tips
Lead with rules as data
- "The workflow is a graph in the database."
- Show one arrow with a condition.
- Say what happens on failure.
Numbers that decide
- 87,000 requests and 3,500 changes a second at peak.
- 7 TB, plus 7.3 TB of history a year.
- 1M open boards.
Anticipate failures
- Index down: work goes on.
- Kafka down: the outbox waits.
- Push lost: reload the board.
Protect tenants
- Tenant in every key.
- Scope inside the query.
- Budgets for rules and jobs.