r/SpringBoot • u/bikesched • 11h ago
News I built a Spring Boot 4 starter for durable, PostgreSQL-backed background jobs (Apache 2.0, feedback welcome)
I needed background jobs in a Spring Boot app that survive restarts, retry with backoff and can wait for things like a payment webhook, without adding a broker or a separate service. I didn't find a library that fit, so I built bikesched. It's an early 0.x release and I'd like feedback from people who run Spring Boot in production.
With the starter and a DataSource, there's nothing to wire: no @Enable…, no builder code.
@Component
class OrderJobs {
@JobHandler(name = "fulfil-order")
public void fulfil(Job job, Order order) {
// runs once; a retried or resumed job gets the stored id back
String paymentId = job.step("create-payment", String.class,
step -> payments.create(order).id());
// the job suspends here without holding a thread until the webhook publishes the event
Payment payment = job.waitForEvent("await-payment", "payment-received", paymentId,
Payment.class).receive();
job.step("ship", () -> shipping.ship(order, payment));
}
@JobHandler(name = "purge-expired-sessions", schedule = "0 0 */6 * * *")
public void purgeExpiredSessions() { … }
}What the starter does:
- Finds
@JobHandlermethods on your beans, including@Transactionalproxies, and calls them through the proxy. scheduletakes Spring's six-field cron syntax or an ISO-8601 duration, so it can replace@Scheduledand runs once across all instances instead of on every one.- Schedules jobs inside your
@Transactionalmethod, so the job only exists if your transaction commits (outbox style). - Starts polling with the context and on shutdown releases unfinished jobs before the
DataSourcecloses, so another instance takes over. - Uses Boot's Jackson
ObjectMapperfor payloads and records Micrometer metrics when those modules are on the classpath. Every option is abikesched.*property.
Under the hood:
- Jobs are rows in plain PostgreSQL tables. Instances claim them with
SKIP LOCKEDand wake each other withLISTEN/NOTIFY. - Durable steps whose results survive retries, compensation for sagas, timeouts, idempotency keys, child jobs and sleeping for days without holding a thread.
- Crash recovery: jobs of a dead instance are picked up by another one.
- Java 21+, virtual threads. The core depends only on the PostgreSQL JDBC driver and SLF4J. There's also an optional admin UI and a test module that can skip time.
It's Apache 2.0, with no open-core or paid tier.
What I'd most like to hear: does the @JobHandler model feel natural next to @Scheduled and @Transactional, and what would stop you from using it?
Full disclosure: I'm the author, and it's also an experiment in building a library heavily with AI coding agents.
- Spring Boot docs: https://bikesched.org/docs/integrations/spring/
- GitHub: https://github.com/bikesched/bikesched
•
u/EirikurErnir 9h ago
This makes me think of ShedLock, what problems does this solve that that does not? :)
•
u/nian2326076 7h ago
bikesched addresses specific needs for background jobs in Spring Boot, especially those requiring durability and webhook handling. To gather feedback from production users, share your project on relevant developer forums or communities where experienced Spring Boot developers can offer insights. Additionally, you can use PracHub to practice interview questions that relate to Spring Boot and backend development, which can help enhance your skills as you work on bikesched.