Two workers prepare a customer report and upload it to the same object key. The first upload succeeds, then the slower worker replaces it with an older result. A separate read-before-write check may have shown no object to either worker, so both believed that creating the report was safe. The check and the write were separate operations.
Conditional writes let an application attach an expected-state condition to the storage operation itself. They are useful for create-once artifacts and controlled replacements, but they still need a conflict policy, permissions, and reconciliation after uncertain responses. An object-store precondition solves one concurrency boundary; it does not automatically coordinate the entire SaaS workflow.
Decide whether the operation creates or replaces
Write two separate contracts. Create only if this key has no current object is different from Replace only if the current object is the version I reviewed. Give these operations distinct application names and avoid a generic upload helper that silently chooses overwrite behavior for every caller.
For a hypothetical report service, an immutable run artifact might use a key derived from the report run identity. A small current-report pointer might be replaceable after checking its expected state. Keeping those responsibilities separate can simplify recovery: the completed artifact remains stable while the pointer update decides which artifact customers should see.
Use the documented precondition
Amazon’s S3 conditional-write guide describes If-None-Match for preventing creation over an existing key and If-Match for comparing the current object’s ETag before replacement. It also documents operation-specific permissions and concurrent-write behavior. Confirm support in the exact API and SDK path used by the application, including multipart completion when relevant.
Treat the ETag as the comparison token returned for the object, not as a universal promise about a locally computed file checksum. Preserve its value correctly through your SDK. Keep a separate content checksum or manifest when the workflow needs to verify bytes. These identifiers serve different purposes and should not be collapsed into a field called version without a clear definition.
Bind the condition to a business operation
Record the tenant, artifact identity, object key, expected state, and intended operation before issuing the write. A condition on the wrong key is still the wrong operation. Derive keys from validated application data, and check authorization independently of whether the key currently exists.
If the user reviewed a report revision, bind the replacement attempt to that reviewed revision. Do not refresh the ETag automatically and retry a replacement merely to make the request succeed. Doing so can turn a conflict detector into a loop that overwrites newer work while preserving the appearance of concurrency protection.
Give conflicts a deliberate outcome
A failed precondition means that the expected state no longer holds. Read the current object metadata or application record and decide what happened. Another worker may have completed the same operation, a newer revision may be present, or the key may belong to a different intended artifact. Those cases deserve different outcomes.
For identical completed work, the application may return the existing receipt after verifying identity. For a newer revision, it may preserve the attempted artifact under a separate immutable key and ask the authorized user to review the difference. For an unexpected owner or scope, stop and investigate. Blind overwrite should not be the default recovery from a condition that was added to prevent overwriting.
Reconcile uncertain network responses
When the connection fails after sending a request, distinguish No response from Write failed. The service may have stored the object even though the client did not receive confirmation. Before retrying, inspect the live outcome using the operation identity and stored metadata. A retry that receives a precondition failure may be evidence that the original attempt succeeded.
Design a receipt that connects the application operation to the object key and verified artifact. If the key exists, verify that it belongs to the same intended operation before treating it as success. Matching a filename alone is weak evidence, especially when names are reused across customers or daily report runs.
Keep database state and storage state reconcilable
A successful object write and a database update are separate events. If the object is stored but the application crashes before marking the report ready, the customer may see a perpetual processing state. If the database is marked ready before the object is verified, the download can point to incomplete or missing work.
Use an explicit workflow such as preparing, object verified, and ready. Record enough information for a reconciliation worker to inspect incomplete operations without creating duplicate artifacts. Make that worker use the same identity and conflict rules as the original writer. Recovery code should not bypass the preconditions simply because it runs outside the normal request path.
Review versioned buckets and cleanup rules
Versioning changes recovery possibilities, but it does not eliminate the need for a write contract. Review how the chosen condition applies to the current object and how delete markers affect the intended operation in your bucket configuration. Keep retention and cleanup policies aligned with the application’s recovery requirements.
Do not delete a disputed artifact immediately when a pointer update fails. It may be needed to explain a conflict or complete reconciliation. Conversely, do not leave abandoned multipart uploads or unreferenced artifacts forever. Define a bounded cleanup process that checks ownership and age, distinguishes unfinished work from failed work, and records what it removes.
Test with competing writers
Run two workers against the same intended key with different payloads and the same expected state. Verify that the final outcome follows the documented conflict policy and that both workers report honest results. Then repeat with an interrupted response, a deleted object, a stale comparison token, and an application crash between storage and database updates.
Include tenant separation and permission failures in the matrix. Inspect the stored object and application receipt, not only the HTTP status returned to the caller. The acceptance criterion is that the customer gets the intended artifact and that a losing or uncertain writer cannot silently claim success for different bytes.
Keep automation within the same contract
AI-generated reports and automated document transformations are ordinary writers from the storage system’s perspective. Give them the same operation identities, preconditions, and review requirements as other workers. A model-generated filename or inferred version label should not decide which customer artifact may be replaced.
Conclusion
S3 conditional writes are effective when the application clearly defines creation, replacement, and conflict recovery. Bind each condition to the correct business operation, reconcile uncertain responses, and keep database and object states explainable. Verify competing writers and failure paths so that preventing an overwrite also leads to a useful, trustworthy customer outcome.