Backend / Distributed Systems
Distributed Job Scheduler
A Spring Boot service for scheduling and executing background jobs with durable PostgreSQL state, Redis coordination, worker heartbeats, retries, and failure tracking.
Repository evidence: pom.xml, schema.sql, controllers, repositories, worker services, tests, Docker Compose, Micrometer, and Spring Security.
Engineering snapshot
What the repository demonstrates
- Durable job and execution records
- Redis queue and coordination services
- Worker polling, heartbeats, retry, and permanent-failure paths
- JWT authentication, BCrypt, roles, and audit logs
- Micrometer counters, gauges, timers, and Actuator exposure
01
The problem
A background-job system cannot rely on a process-local timer once more than one worker can execute jobs. It needs durable job state, a way to claim due work, worker liveness signals, and explicit handling for retryable versus permanent failure. The repository implements those concerns without claiming a measured production SLA.
02
Engineering requirements
Functional
- Register and authenticate users.
- Create, list, inspect, update, and delete jobs.
- Poll and execute scheduled jobs.
- Track executions, worker nodes, failed jobs, and retry actions.
- Expose job status and metrics endpoints.
Non-functional
- Durable state through PostgreSQL.
- Coordination and queue support through Redis.
- Stateless JWT-based request authentication.
- Recoverable worker execution with heartbeat and retry behavior.
- Testable service boundaries and observable counters/timers.
03
System architecture
The repository contains a Spring Boot API, JPA repositories over PostgreSQL, Redis queue/lock services, scheduled polling, worker execution, and security/observability infrastructure. The source does not surface Kubernetes manifests or a GitHub Actions workflow, so those are not shown as implemented here.
04
Request and data flow
- 01A client authenticates through the auth controller and receives a JWT.
- 02The client creates or inspects a job through the job controller.
- 03Job state is persisted through JPA repositories and the SQL schema.
- 04Polling/worker services identify executable work and coordinate access through Redis and repository locking.
- 05The worker emits heartbeat and execution state, then records success, retry, or permanent failure.
- 06Metrics and audit records expose operational state to API consumers.
05
Key engineering decisions
PostgreSQL for durable job state
Why: Jobs, executions, workers, and audit records have relational relationships and need durable queries.
Trade-off: Relational durability adds schema and transaction management compared with keeping all state in Redis.
Redis for coordination and queue support
Why: Shared worker coordination cannot depend on local process memory when multiple workers participate.
Trade-off: Correctness now depends on explicit Redis availability and lock/queue boundaries.
Repository locking plus worker coordination
Why: Due-job selection and ownership need protection from concurrent workers.
Trade-off: Pessimistic locking can reduce contention at the cost of blocking and transaction complexity.
JWT and stateless Spring Security
Why: Requests can be authenticated without server-side session storage.
Trade-off: Token revocation and rotation require deliberate policy beyond basic token verification.
06
Deep technical challenge
Problem
The hardest problem is separating durable job ownership from execution so a worker can fail without silently losing the job.
Why the naive approach fails
A naive implementation would poll rows and immediately execute them in memory. Two workers could select the same row, or a crashed worker could leave no durable indication of what happened.
Implemented solution
The repository combines PostgreSQL job/execution state, repository locking, Redis coordination, worker heartbeats, retry paths, and permanent-failure tracking. The exact lock lifecycle should still be verified against a live deployment before promising exactly-once execution.
Edge cases
Redis outage, a worker dying after claiming work, heartbeat expiry during a long task, duplicate retry requests, and database transaction failure remain important scenarios to test.
07
Database and API design
The repository includes an explicit SQL schema and JPA entities for User, Job, JobExecution, WorkerNode, and AuditLog. JobRepository exposes due-job and locking-oriented queries. Redis is used for transient coordination rather than replacing the durable relational model.
| Method | Endpoint | Purpose | Auth |
|---|---|---|---|
| POST | /auth/register | Create a user account. | Public |
| POST | /auth/login | Authenticate and issue a JWT. | Public |
| POST | /jobs | Create a scheduled job. | JWT |
| GET | /jobs/status | Inspect job status. | JWT |
| GET | /jobs/metrics | Read job metrics. | JWT |
| POST | /jobs/retry/{jobId} | Request retry of a failed job. | JWT / role checks |
08
Security
Implemented
- JWT authentication and a JWT filter/provider.
- BCrypt password hashing.
- Stateless Spring Security configuration and role checks.
- Audit log entity and service paths.
Potential improvements
- Document token expiry/revocation policy.
- Add explicit rate limiting and abuse controls if the API is exposed publicly.
- Run integration security tests with Docker-enabled dependencies.
09
Failure handling
Evidence
- Worker success, retry, and permanent-failure paths.
- Heartbeat and worker status tracking.
- Failed-job listing and retry endpoint.
- Conditional Testcontainers integration coverage when Docker is available.
Remaining scenarios
- Redis/database outage behavior is not demonstrated by a deployed failure test.
- Exactly-once versus at-least-once execution semantics should be documented.
- Stale lock cleanup and long-running job timeout policy need explicit verification.
10
Performance, scalability, and observability
Performance and scalability
- Repository queries include due-job and locking-oriented access paths.
- Micrometer counters, gauges, and timers provide instrumentation points.
- No formal benchmark was included in the repository evidence reviewed.
- Horizontal worker scaling is a design consideration, not a measured deployment result.
Observability
- Micrometer counters, gauges, and timers.
- Spring Actuator/Prometheus exposure.
- Audit logs and worker state.
- Future: add dashboards, trace correlation, and alert thresholds around queue depth, stale workers, and retry rate.
11
Testing and code quality
- JUnit 5 and Mockito unit tests cover JWT, polling, and worker success/retry/permanent-failure behavior.
- A Testcontainers test provisions PostgreSQL and Redis; it conditionally skips when Docker is unavailable.
- The repository walkthrough reports a Maven test run, but skipped integration tests should not be presented as full integration coverage.
12
DevOps and deployment
- Docker Compose is present for local multi-service setup.
- No Kubernetes manifests or GitHub Actions workflow were surfaced in the audited repository.
- Environment-specific production deployment should be treated as future work unless separately verified.
13
Engineering trade-offs
Redis coordination versus database-only polling: faster shared coordination, but another dependency.
Pessimistic locking versus optimistic updates: simpler ownership semantics, but possible contention.
JWT statelessness versus server sessions: easier horizontal request routing, harder revocation.
Docker Compose versus a managed orchestrator: reproducible local setup, but limited production evidence.
14
What I would improve next
Short term
- Document execution semantics and lock lifecycle.
- Add failure-injection tests for Redis, database, and worker crashes.
- Add a reproducible Docker-enabled integration test command.
Medium term
- Add CI workflow for unit and integration tests.
- Add dashboards and alerts for worker liveness, retries, and queue depth.
- Define idempotency behavior for job handlers.
Production scale
- Evaluate durable queue semantics and backpressure.
- Separate scheduler and worker scaling policies.
- Add distributed tracing and deployment runbooks.
15
Key learnings
- Durable scheduling state must be separate from the process that executes work.
- Worker liveness is a data model concern, not only a logging concern.
- Retry behavior needs a terminal state so failures do not become infinite loops.
- Integration tests are only evidence when the external dependencies actually run.
16
Interview questions
- How does the system prevent two workers from claiming the same job?
- What happens if a worker crashes after claiming work?
- Why keep job state in PostgreSQL and coordination in Redis?
- What execution guarantee does the implementation provide?
- How would you test a stale heartbeat?
- How would you scale workers independently from the API?
- What metrics indicate retry storms?
- How would you make job handlers idempotent?
Why this project matters
Recruiter-facing summary
This project gives a hiring manager concrete evidence of backend fundamentals around durable state, concurrency, worker coordination, security, testing, and operational instrumentation. Its strongest story is not a claimed throughput number; it is the explicit treatment of failure and ownership in a background-work system.