r/SpringBoot • u/A_little_anarchy • Mar 18 '26
Discussion Would you switch from ShedLock to a scheduler that survives pod crashes and prevents GC split-brain?
Working on a distributed scheduler for Spring Boot that solves two problems ShedLock cannot.
Problem 1 - GC split-brain. ShedLock uses TTL locks. If your pod hits a long GC pause, the lock expires, another pod takes over, first pod wakes up and both run simultaneously. Both writes accepted. Data corrupt. This is a documented limitation, ShedLock’s maintainer has confirmed it cannot be fixed within the current design.
Problem 2 - No crash recovery. Pod dies halfway through processing 10,000 invoices. Next run starts from invoice 1. Duplicate charges, lost work. For weekly jobs that means waiting a full week.
The fix is fencing tokens - every write must present the current lock token, stale writes are rejected at the database level - combined with per-item checkpointing. Pod crashes at invoice 5,000, the replacement pod resumes from invoice 5,001, not from the beginning.
Have you hit either of these problems in production? And would you actually use something like this, or is making your jobs idempotent good enough for your use case? Honest answers only, trying to understand if this solves a real problem before I publish anything.
4
u/CptGia Mar 19 '26
GC pauses are usually measured in milliseconds. How short is your TTL? Is it feasible to increase it?
You could also change GC to ZGC for shorter pauses.
2
u/mr_Jackpots85 Mar 18 '26
I was thinking about these problems. For problem number 1, I was pondering if a quorum might be helpful, like how Redis Sentinel works with master node failover.
For problem no. 2 idempotency was enough for me. Bit I can see value in long running jobs that you cant afford to restart.
1
u/Krangerich Mar 20 '26
There is a simple scheduling solution; maybe it's a fit for your use case. Have a look a this video from the Spring IO 2024: https://www.youtube.com/watch?v=ghpljMg8Ecc
1
u/gizmogwai Mar 30 '26
AFAICT, JobRunr already solves these issues.
Also, if you want finer control on your progress mechanism, you should probably use Spring Batch instead of rolling your own scheduler.