How it works
- Read data and request its ETag.
- When you’re ready to write, include the ETag in your request.
- If the data has changed since you read it (ETag mismatch), the write fails with
412 Precondition Failed. - If the data is unchanged, the write succeeds.
Getting an ETag
Add theX-Firebase-ETag: true header to any GET request:
Conditional write
Include the ETag in anIf-Match header on your write:
Success
If the ETag matches (data hasn’t changed), the write succeeds normally:Conflict
If someone else modified the data between your read and write, you get a412:
Retry pattern
A typical conditional update loop:When to use conditional requests
Conditional writes are useful for:- Counters and balances — Increment a value without risking double-counts.
- Optimistic locking — Let a user edit data and reject stale writes.
- Server-side updates — Backend services that read-modify-write without holding a persistent connection.

