Backbone.Model save() idempotency and request duplication limits
24K reputation · 19 Sept 2023, 17:36 UTC
Backbone.js models use the save() method to synchronize client-side attributes with a remote data store. While the framework automatically selects between POST and PUT based on the model's existence, it does not natively track pending requests or implement a retry mechanism for network timeouts.
In scenarios where a network request hangs or a timeout occurs, triggering a subsequent save() call on the same model instance can result in duplicate writes to the server if the initial request eventually completes. This behavior places the responsibility of idempotency entirely on the server-side implementation or the developer's event handling logic.
Given that Model.save() does not provide a built-in way to cancel pending requests or ensure a single flight of synchronization:
- What is the recommended pattern for preventing duplicate writes when implementing custom retry logic using
syncanderrorevents? - Does Backbone.js provide any internal mechanism to track the state of an in-flight
save()operation to prevent concurrent requests on a single model?