Skip to content

Exam: record exam-result events in a transactional outbox - #31

Merged
mfarim merged 1 commit into
mainfrom
feat/exam-result-outbox
Nov 27, 2026
Merged

mfarim merged 1 commit into
mainfrom
feat/exam-result-outbox

Conversation

@mfarim

@mfarim mfarim commented Nov 27, 2026

Copy link
Copy Markdown
Owner

What

When an exam attempt's result becomes final, the backend records an exam.result_ready event so the student can be e-mailed. "Final" means fully auto-graded on submit, or the last essay graded by the teacher.

The event is written to a new outbox_events table in the same transaction as the grade. A committed grade therefore always has its event, and a rolled-back grade never does. OutboxRelay publishes pending rows in the background.

Details

  • Off by default (APP_NOTIFY_EXAM_RESULTS=false). No outbox beans and no relay are created, and resultReady() is a no-op. Existing deployments behave exactly as before.
  • Publishers:
    • log: for local development; the default when enabled.
    • pubsub: Google Cloud Pub/Sub over REST. It authenticates with the VM's service account through the metadata server, so no key file is needed.
  • Sent once: one event per attempt (unique event_type + aggregate_id). Re-grading an attempt does not send it again.
  • Safe with several instances: the relay locks rows with SKIP LOCKED. Failed publishes are retried up to app.outbox.max-attempts, and the last error is kept on the row.
  • Score visibility: the score is only included when the exam shows results to students (show_result).
  • V5__outbox_events.sql adds the table.
  • Frontend Nginx: /api and /ws are now proxied to BACKEND_UPSTREAM. The default is backend:8080, unchanged for Docker Compose. The same image also works on Cloud Run, where both containers share 127.0.0.1.

New settings

Variable Default
APP_NOTIFY_EXAM_RESULTS false Record result events
APP_OUTBOX_PUBLISHER log log or pubsub
APP_OUTBOX_PUBSUB_TOPIC – projects/<project>/topics/<topic>
APP_OUTBOX_RELAY_INTERVAL_MS 5000 Relay interval

Testing

  • ./mvnw clean test against PostgreSQL 16 and Redis 7: 66 tests, 0 failures. This includes new tests for OutboxRelay, PubSubRestPublisher, ExamResultEvents, and the ExamRunnerService hooks.
  • Flyway applies V1–V5 in order on a fresh database.
  • nginx -t passes with BACKEND_UPSTREAM=backend:8080 and 127.0.0.1:8080.

Deploy note

Back up the database first. V5 creates an empty table on backend start. With the defaults, nothing else changes.

When an attempt's result becomes final (fully auto-graded on submit, or when the
last essay is graded), an "exam.result_ready" event is written to outbox_events
in the same transaction as the grade. OutboxRelay publishes pending rows in the
background so the student can be e-mailed.

- Off by default (APP_NOTIFY_EXAM_RESULTS=false): no outbox beans, no relay,
  resultReady() is a no-op. Existing deployments behave as before.
- Publishers: "log" (local development, default) or "pubsub" (Google Cloud
  Pub/Sub over REST, authenticated with the VM's service account through the
  metadata server; no key file).
- One event per attempt (unique event_type + aggregate_id); later re-grades do
  not send it again. Rows are locked with SKIP LOCKED so several instances can
  run the relay. Failed publishes are retried up to app.outbox.max-attempts.
- The score is only included when the exam shows results to students.
- V5 migration adds the outbox_events table.

Frontend: the backend address Nginx proxies /api and /ws to is now
BACKEND_UPSTREAM (default backend:8080, unchanged for Docker Compose), so the
same image also works on Cloud Run where both containers share localhost.
@mfarim mfarim self-assigned this Nov 27, 2026
@mfarim mfarim added the enhancement New feature or request label Nov 27, 2026
@mfarim
mfarim merged commit d7d156d into main Nov 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant