Skip to content

Graduation screening worker

Last updated

Key facts

Role
Backend Developer
Organisation
Universitas Terbuka
Stack
Go, PostgreSQL
Scale
Thousands of students per study program, every graduation period
Status
In progress
  • Go
  • PostgreSQL

Context

Universitas Terbuka’s graduation screening service evaluates thousands of students per study program every graduation period.

It runs on the national university platform serving 800K+ students. The current version uses cron workers on a database job queue; it is being redesigned as a Go worker on a Postgres-backed queue.

Problem

  • Screening a whole study program inside an API request runs into timeouts.
  • Screening depends on legacy PHP grading servers, so calls to them need bounded concurrency and timeouts.
  • Reads from a replica can lag behind the primary, which is not acceptable for graduation decisions.

Approach

The first version moved screening out of the request path into cron workers on a database job queue, avoiding API timeouts.

The redesign as a Go worker on a Postgres-backed queue adds:

  • Atomic batch claiming. Workers claim batches of jobs atomically, so no batch is processed by two workers.
  • Per-student fan-out. A batch is split into one unit of work per student.
  • Lease-based recovery. Claimed work carries a lease; if a worker stops, the work becomes claimable again once the lease expires.
  • Retries with backoff. Failed work is retried with backoff.
  • Resumable batches. Interrupted batches resume without reprocessing.

Architecture

// workers die; jobs come back. failures retry with backoffDoneFailedLease
  • Queue: Postgres-backed job queue.
  • Worker: Go service that claims batches and fans out per student.
  • Grading: legacy PHP grading servers, called with per-host concurrency limits and timeouts.
  • Reads: decision-critical reads go to the primary database.

Key decisions & trade-offs

  • Postgres as the queue. Postgres was already part of the platform, so a Postgres-backed queue adds no new infrastructure to run, and jobs are claimed in the same transactions as the data they work on, so there is no separate broker to keep consistent with the database. The trade-off is that queue load lands on the same database.
  • Per-host concurrency limits and timeouts. Each legacy PHP grading server gets its own limit and timeout, so one slow server does not stall the rest. The trade-off is that total throughput is capped by those limits.
  • Primary reads for decisions. Decision-critical reads are routed to the primary to avoid replica lag, trading extra load on the primary for consistent results.
  • Leases over locks held for the whole job. A lease expires on its own, so work claimed by a worker that stopped becomes claimable again without anyone releasing it, and no long-running transaction holds locks while a batch runs.

Result

  • Job claiming and lease behavior are covered by integration tests running in GitLab CI.
  • The Go redesign is in progress.

Results will be added once the redesign ships.