Skip to content

Commit ef4814c

Browse files
authored
Merge pull request #32 from ietf-wg-httpapi/mnot-patch-1
Editorial suggestions
2 parents fbe4581 + 1f353d0 commit ef4814c

File tree

1 file changed

+48
-57
lines changed

1 file changed

+48
-57
lines changed

draft-ietf-httpapi-idempotency-key-header.md

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,17 @@ informative:
3535

3636
--- abstract
3737

38-
The HTTP Idempotency-Key request header field can be used to carry idempotency key in order to make non-idempotent HTTP methods such as `POST` or `PATCH` fault-tolerant.
38+
The HTTP Idempotency-Key request header field can be used to make non-idempotent HTTP methods such as `POST` or `PATCH` fault-tolerant.
3939

4040
--- middle
4141

4242
# Introduction
4343

44-
Idempotence is the property of certain operations in mathematics and computer science whereby they can be applied multiple times without changing the result beyond the initial application. It does not matter if the operation is called only once, or 10s of times over.
44+
In mathematics and computer science, an idempotent operation is one that can be applied multiple times without changing the result beyond the initial application. It does not matter if the operation is called only once or tens of times over.
4545

46-
Idempotency is important in building a fault-tolerant HTTP API. An HTTP request method is considered `idempotent` if the intended effect on the server of multiple identical requests with that method is the same as the effect for a single such request. According to {{!RFC7231}}, HTTP methods `OPTIONS`, `HEAD`, `GET`, `PUT` and `DELETE` are idempotent while methods `POST` and `PATCH` are not.
46+
Idempotency is important in building fault-tolerant HTTP APIs. An HTTP request method is considered `idempotent` if the intended effect on the server of multiple identical requests with that method is the same as the effect for a single such request. Per {{!RFC9110}}, the methods `OPTIONS`, `HEAD`, `GET`, `PUT` and `DELETE` are idempotent while methods `POST` and `PATCH` are not.
4747

48-
Let's say a client of an HTTP API wants to create (or update) a resource using a `POST` method. Since `POST` is NOT an idempotent method, calling it multiple times can result in duplication or wrong updates. Consider a scenario where the client sent a `POST` request to the server, but it got a timeout. Following questions arise : Is the resource actually created (or updated)? Did the timeout occur during sending of the request, or when receiving of the response? Can the client safely retry the request, or does it need to figure out what happened in the first place? If `POST` had been an idempotent method, such questions may not arise. Client would safely retry a request until it actually gets a valid response from the server.
49-
50-
For many use cases of HTTP APIs, duplicated resources are a severe problem from a business perspective. For example, duplicate records for requests involving any kind of money transfer `MUST NOT` be allowed. In other cases, processing of duplicate webhook delivery is not expected.
48+
Let's say a client of an HTTP API wants to create (or update) a resource using a `POST` method. Repeating the request multiple times can result in duplication or incorrect updates. Consider a scenario where the client sent a `POST` request to the server, but the request timed out. The client does not know if the resource was created (or updated), because it does not know when the timeout occured from the server's perspective. Furthermore, the client does not know if it can safely retry the request.
5149

5250

5351
## Notational Conventions
@@ -56,43 +54,34 @@ For many use cases of HTTP APIs, duplicated resources are a severe problem from
5654

5755
This specification uses the Augmented Backus-Naur Form (ABNF) notation of {{!RFC5234}} and includes, by reference, the IMF-fixdate rule as defined in Section 7.1.1.1 of {{!RFC7231}}.
5856

59-
The term "resource" is to be interpreted as defined in Section 2 of {{!RFC7231}}, that is identified by an URI. The term "resource server" is to be interpreted as "origin server" as defined in Section 3 of {{!RFC7231}}.
57+
The term "resource" is to be interpreted as defined in Section 2 of {{!RFC7231}}, that is identified by an URI.
6058

6159
# The Idempotency-Key HTTP Request Header Field
6260

63-
An idempotency key is a unique value generated by the client which the resource server uses to recognize subsequent retries of the same request. The `Idempotency-Key` HTTP request header field carries this key.
64-
65-
61+
An idempotency key is a unique value generated by the client which the resource uses to recognize subsequent retries of the same request. The `Idempotency-Key` HTTP request header field carries this value.
6662

6763
## Syntax
6864

65+
`Idempotency-Key` is an Item Structured Header {{!RFC8941}}. Its value MUST be a String (Section 3.3.3 of {{!RFC8941}}).
6966

70-
`Idempotency-Key` is an Item Structured Header {{!RFC8941}}. Its value MUST be a String. Refer to Section 3.3.3 of {{!RFC8941}} for ABNF of `sf-string`:
7167

72-
Idempotency-Key = sf-string
68+
## Uniqueness of Idempotency Key
7369

70+
The idempotency key MUST be unique and MUST NOT be reused with another request with a different request payload.
7471

75-
Clients MUST NOT include more than one `Idempotency-Key` header field in the same request.
72+
Uniqueness of the key MUST be defined by the resource owner and MUST be implemented by the clients of the resource. It is RECOMMENDED that a UUID {{!RFC4122}} or a similar random identifier be used as an idempotency key.
7673

77-
The following example shows an idempotency key using `UUID` {{!RFC4122}}:
74+
The following example shows an idempotency key whose value is a UUID {{!RFC4122}}:
7875

7976
Idempotency-Key: "8e03978e-40d5-43e8-bc93-6894a57f9324"
8077

81-
82-
## Uniqueness of Idempotency Key
83-
84-
The idempotency key that is supplied as part of every `POST` request MUST be unique and MUST NOT be reused with another request with a different request payload.
85-
86-
Uniqueness of the key MUST be defined by the resource owner and MUST be implemented by the clients of the resource server. It is RECOMMENDED that `UUID` {{!RFC4122}} or a similar random identifier be used as an idempotency key.
87-
8878
## Idempotency Key Validity and Expiry
8979

90-
The resource MAY enforce time based idempotency keys, thus, be able to purge or delete a key upon its expiry. The resource server SHOULD define such expiration policy and publish it in the documentation.
91-
80+
The resource MAY require time based idempotency keys to be able to purge or delete a key upon its expiry. The resource SHOULD define such expiration policy and publish it in the documentation.
9281

9382
## Idempotency Fingerprint
9483

95-
An idempotency fingerprint MAY be used in conjunction with an idempotency key to determine the uniqueness of a request. Such a fingerprint is generated from request payload data by the resource server. An idempotency fingerprint generation algorithm MAY use one of the following or similar approaches to create a fingerprint.
84+
An idempotency fingerprint MAY be used in conjunction with an idempotency key to determine the uniqueness of a request. Such a fingerprint is generated from request payload data by the resource. An idempotency fingerprint generation algorithm MAY use one of the following or similar approaches to create a fingerprint.
9685

9786
* Checksum of the entire request payload.
9887
* Checksum of selected element(s) in the request payload.
@@ -103,48 +92,49 @@ An idempotency fingerprint MAY be used in conjunction with an idempotency key to
10392

10493
## Responsibilities
10594

106-
Client
95+
### Client
10796

108-
Clients of HTTP API requiring idempotency, SHOULD understand the idempotency related requirements as published by the server and use appropriate algorithm to generate idempotency keys.
97+
Clients of HTTP API requiring idempotency SHOULD understand the idempotency related requirements as published by the server and use appropriate algorithm to generate idempotency keys.
10998

110-
Clients MAY choose to send an Idempotency-Key field with any valid random sf-string to indicate the user's intent is to only perform this action once. Without a priori knowledge, a general client cannot assume the server will respect this request.
99+
Clients MAY choose to send an Idempotency-Key field with any valid value to indicate the user's intent is to only perform this action once. Without a priori knowledge, a general client cannot assume the server will respect this request.
111100

112-
For each request, client SHOULD
101+
For each request, a client SHOULD:
113102

114103
* Send a unique idempotency key in the HTTP `Idempotency-Key` request header field.
115104

116-
Resource Server
105+
### Resource
117106

118-
Resource server MUST publish idempotency related specification. This specification MUST include expiration related policy if applicable. Server is responsible for managing the lifecycle of the idempotency key.
107+
Resources MUST publish a idempotency related specification. This specification MUST include expiration related policy if applicable. A resource is responsible for managing the lifecycle of the idempotency key.
119108

120-
For each request, server SHOULD
109+
For each request, a server SHOULD:
121110

122111
* Identify idempotency key from the HTTP `Idempotency-Key` request header field.
123112
* Generate idempotency fingerprint if required.
124-
* Check for idempotency considering various scenarios including the ones described in section below.
113+
* Enforce idempotency (see below)
125114

126115

127-
## Idempotency Enforcement Scenarios
116+
## Idempotency Enforcement
128117

129118
* First time request (idempotency key and fingerprint has not been seen)
130119

131-
The resource server SHOULD process the request normally and respond with an appropriate response and status code.
120+
The resource SHOULD process the request normally and respond with an appropriate response and status code.
132121

133122
* Duplicate request (idempotency key and fingerprint has been seen)
134123

135124
Retry
136125

137-
The request was retried after the original request completed. The resource server SHOULD respond with the result of the previously completed operation, success or an error. See Error Scenarios for details on errors.
126+
The request was retried after the original request completed. The resource SHOULD respond with the result of the previously completed operation, success or an error. See Error Scenarios for details on errors.
138127

139128
Concurrent Request
140129

141-
The request was retried before the original request completed. The resource server SHOULD respond with a resource conflict error. See Error Scenarios for details.
130+
The request was retried before the original request completed. The resource SHOULD respond with a resource conflict error. See Error Scenarios for details.
142131

143132

144-
## Error Scenarios
133+
## Error Handling
145134

146-
If the `Idempotency-Key` request header is missing for a documented idempotent operation requiring this header, the resource server SHOULD reply with an HTTP `400` status code with body containing a link pointing to relevant documentation. Following examples shows an error response describing the problem using {{!RFC7807}}.
135+
If the `Idempotency-Key` request header is missing for a documented idempotent operation requiring this header, the resource SHOULD reply with an HTTP `400` status code with body containing a link pointing to relevant documentation. Following examples shows an error response describing the problem using {{!RFC7807}}.
147136

137+
~~~ http-message
148138
HTTP/1.1 400 Bad Request
149139
Content-Type: application/problem+json
150140
Content-Language: en
@@ -154,16 +144,19 @@ If the `Idempotency-Key` request header is missing for a documented idempotent o
154144
"detail": "This operation is idempotent and it requires correct
155145
usage of Idempotency Key.",
156146
}
147+
~~~
157148

158149
Alternately, using the HTTP header `Link`, the client can be informed about the error as shown below.
159150

151+
~~~ http-message
160152
HTTP/1.1 400 Bad Request
161153
Link: <https://developer.example.com/idempotency>;
162154
rel="describedby"; type="text/html"
155+
~~~
163156

164-
If there is an attempt to reuse an idempotency key with a different request payload, the resource server SHOULD reply with a HTTP `422` status code with body containing a link pointing to relevant documentation. The status code `422` is defined in Section 11.2 of {{!RFC4918}}.
165-
157+
If there is an attempt to reuse an idempotency key with a different request payload, the resource SHOULD reply with a HTTP `422` status code with body containing a link pointing to relevant documentation. The status code `422` is defined in Section 11.2 of {{!RFC4918}}.
166158

159+
~~~ http-message
167160
HTTP/1.1 422 Unprocessable Content
168161
Content-Type: application/problem+json
169162
Content-Language: en
@@ -174,17 +167,19 @@ If there is an attempt to reuse an idempotency key with a different request payl
174167
correct usage of Idempotency Key. Idempotency Key MUST not be
175168
reused across different payloads of this operation.",
176169
}
177-
170+
~~~
178171

179172
The server can also inform the client by using the HTTP header `Link` as shown below.
180173

174+
~~~ http-message
181175
HTTP/1.1 422 Unprocessable Content
182176
Link: <https://developer.example.com/idempotency>;
183177
rel="describedby"; type="text/html"
178+
~~~
184179

185-
If the request is retried, while the original request is still being processed, the resource server SHOULD reply with an HTTP `409` status code with body containing problem description.
186-
180+
If the request is retried, while the original request is still being processed, the resource SHOULD reply with an HTTP `409` status code with body containing problem description.
187181

182+
~~~ http-message
188183
HTTP/1.1 409 Conflict
189184
Content-Type: application/problem+json
190185
Content-Language: en
@@ -194,16 +189,19 @@ If the request is retried, while the original request is still being processed,
194189
"detail": "A request with the same Idempotency-Key for the
195190
same operation is being processed or is outstanding.",
196191
}
192+
~~~
197193

198194
Or, alternately using the HTTP header `Link` pointing to the relevant documentation
199195

196+
~~~ http-message
200197
HTTP/1.1 409 Conflict
201198
Link: <https://developer.example.com/idempotency>;
202199
rel="describedby"; type="text/html"
200+
~~~
203201

204-
Error scenarios above describe the status of failed idempotent requests after the resource server prcocesses them. Clients MUST correct the requests (with the exception of 409 where no correction is required) before performing a retry operation, or the the resource server MUST fail the request and return one of the above errors.
202+
Error scenarios above describe the status of failed idempotent requests after the resource prcocesses them. Clients MUST correct the requests (with the exception of 409 where no correction is required) before performing a retry operation, or the the resource MUST fail the request and return one of the above errors.
205203

206-
For other 4xx/5xx errors, such as 401, 403, 500, 502, 503, 504, 429, or any other HTTP error code that is not listed here, the client SHOULD act appropriately by following the resource server's documentation.
204+
For other 4xx/5xx errors, such as 401, 403, 500, 502, 503, 504, 429, or any other HTTP error code that is not listed here, the client SHOULD act appropriately by following the resource's documentation.
207205

208206

209207
# IANA Considerations
@@ -335,16 +333,16 @@ Organization: WebEngage
335333
This section is meant to inform developers, information providers,
336334
and users of known security concerns specific to the idempotency keys.
337335

338-
Resource servers that do not implement strong idempotency keys, such as UUIDs, or have appropriate controls to validate the idempotency keys, could be victim to various forms of security attacks from malicious clients:
336+
Resources that do not implement strong idempotency keys, such as UUIDs, or have appropriate controls to validate the idempotency keys, could be victim to various forms of security attacks from malicious clients:
339337

340-
* Injection attacks-When the resource server does not validate the idempotency key in the client request and performs a idempotent cache lookup, there can be security attacks (primarily in the form of injection), compromising the server.
338+
* Injection attacks - When the resources does not validate the idempotency key in the client request and performs a idempotent cache lookup, there can be security attacks (primarily in the form of injection), compromising the server.
341339
* Data leaks-When an idempotency implementation allows low entropy keys, attackers MAY determine other keys and use them to fetch existing idempotent cache entries, belonging to other clients.
342340

343-
To prevent such situations, the specification recommends the following best practices for idempotency key implementation in the resource server.
341+
To prevent such situations, the specification recommends the following best practices for idempotency key implementation in the resource.
344342

345343
* Establish a fixed format for the idempotency key and publish the key’s specification.
346344
* Always validate the key as per its published specification before processing any request.
347-
* On the resource server, implement a unique composite key as the idempotent cache lookup key. For example, a composite key MAY be implemented by combining the idempotency key sent by the client with other client specific attributes known only to the resource server.
345+
* On the resource, implement a unique composite key as the idempotent cache lookup key. For example, a composite key MAY be implemented by combining the idempotency key sent by the client with other client specific attributes known only to the resource.
348346

349347

350348
# Examples
@@ -353,20 +351,13 @@ The first example shows an idempotency-key header field with key value using UUI
353351

354352
Idempotency-Key: "8e03978e-40d5-43e8-bc93-6894a57f9324"
355353

356-
Second example shows an idempotency-key header field with key value using some random string generator:
354+
Second example shows an idempotency-key header field with key value using a random string generator:
357355

358356
Idempotency-Key: "clkyoesmbgybucifusbbtdsbohtyuuwz"
359357

360358

361359
--- back
362360

363-
# Imported ABNF
364-
365-
The following core rules are included by reference, as defined in Appendix B.1 of {{!RFC5234}}: ALPHA (letters), CR (carriage return), CRLF (CR LF), CTL (controls), DIGIT (decimal 0-9), DQUOTE (double quote), HEXDIG (hexadecimal 0-9/A-F/a-f), LF (line feed), OCTET (any 8-bit sequence of data), SP (space), and VCHAR (any visible US-ASCII character).
366-
367-
The rules below are defined in {{!RFC7230}}:
368-
369-
obs-text = <obs-text, see [RFC7230], Section 3.2.6>
370361

371362
# Acknowledgments
372363
{:numbered="false"}

0 commit comments

Comments
 (0)