HTTP 409 Conflict vs gRPC 6 ALREADY_EXISTS
HTTP 409 Conflict and gRPC ALREADY_EXISTS both handle resource conflicts, but HTTP 409 is broader. HTTP 409 covers any conflict with the current state of the resource (version mismatch, concurrent edit), while gRPC ALREADY_EXISTS specifically means a create operation failed because the entity already exists.
Descrição
The request conflicts with the current state of the server. Often due to concurrent modification or business rule violations.
Quando você o vê
When trying to create a resource that already exists, or updating a resource that was modified by another request.
Como corrigir
Refresh the resource state, resolve conflicts, and retry. Use ETags for optimistic concurrency.
Descrição
The entity that a client attempted to create already exists. For example, a file or directory that the RPC was supposed to create already exists.
Quando você o vê
A create operation failed because a resource with the same unique identifier or name already exists in the system.
Como corrigir
Use a different identifier, or switch to an upsert/update operation if overwriting is acceptable. Check for existing resources before creating.
Diferenças principais
HTTP 409 covers all conflicts: version mismatches, concurrent modifications, and duplicate creation.
gRPC ALREADY_EXISTS is narrower — it only means a create operation found a pre-existing entity.
For concurrent modification conflicts in gRPC, use ABORTED (code 10) instead of ALREADY_EXISTS.
HTTP 409 is often used with ETags for optimistic concurrency; gRPC uses version fields in protobuf messages.
gRPC separates concerns: ALREADY_EXISTS for creates, ABORTED for concurrent writes, FAILED_PRECONDITION for state issues.
Quando usar qual
Return HTTP 409 when a request conflicts with the current resource state — duplicate creation, version mismatch, or concurrent modification. Return gRPC ALREADY_EXISTS only when a create operation fails due to a pre-existing entity. In gRPC-to-HTTP gateways, map ALREADY_EXISTS to 409, but also map ABORTED to 409 for concurrent modification conflicts.