Which Pattern Prevents Duplicate Writes in Thymeleaf?
0 reputation · 20 Oct 2023, 23:00 UTC
Problem Context
Thymeleaf renders stateless HTML. When a user submits a form, the controller processes the POST and persists data. If the same POST is retried—by refresh, back button, or network retry—the same write can occur again, leading to duplicate records.
Current Constraints
The library offers th:object and th:field for binding, but no anti‑resubmission token or idempotency mechanism is built in. Spring MVC typically relies on a POST‑redirect‑GET pattern or a custom hidden token to mitigate duplicates, yet the choice remains at the application level.
Unresolved Decision
Which strategy—redirect‑after‑POST, a custom idempotency token, or a future Thymeleaf feature—provides the most reliable protection against duplicate writes, especially under high‑traffic or unreliable network conditions?
Specific Questions
- Does a POST‑redirect‑GET pattern fully prevent duplicate writes in all retry scenarios?
- Should a custom hidden idempotency token be added to the form to guarantee idempotency?
- Is there an upcoming Thymeleaf feature that will supply a built‑in anti‑resubmission token?