AlgoViz

Design JIRA (Issue Tracker)

medium 60 min

Track 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

Our systemBrowserGatewayIssue svcPostgreSQLissue, outboxKafkaWorkersindex, mail, hooks

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

Our systemNoorsaw version 3Maxsaw version 3Issue svcPostgreSQLPROJ-7

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

    critical

    Both people pass the check, and history shows a forbidden path.

    Wrong
    if allowed(issue.status, to):    db.set_status(id, to)
    Right
    n = db.execute(  "UPDATE issues SET status_id=%s, version=version+1"  " WHERE id=%s AND version=%s", (to, id, seen))if n == 0: raise Conflict
  • Permissions after the search

    critical

    The total and the short page reveal hidden issues.

    Wrong
    hits = es.search(q)return [h for h in hits if may_see(h)], hits.total
    Right
    hits = es.search(and_(scope(person), q))return hits, hits.total
  • A webhook inside the transaction

    major

    Locks are held while a foreign server thinks, and a rollback cannot unsend it.

    Wrong
    with db.transaction():    set_status(...)    http.post(hook)
    Right
    with db.transaction():    set_status(...)    outbox.add("webhook", hook)
  • An index field for every custom field

    major

    Elasticsearch limits an index to 1,000 fields by default.

    Wrong
    doc["cf_" + field.id] = value
    Right
    doc[slot_for(tenant, field)] = value  # number_7
  • Tenant as a courtesy

    critical

    One forgotten clause shows another company's data.

    Wrong
    SELECT * FROM issues WHERE id = $1
    Right
    SELECT * 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.