Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Document basic backoff protocol. #323

Merged
merged 3 commits into from Nov 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 44 additions & 4 deletions docs/api.md
Expand Up @@ -43,7 +43,7 @@ To simplify error handling for the client, the type of error is indicated both b
```js
{
"code": 400, // matches the HTTP status code
"errno": 107, // stable application level error number
"errno": 107, // stable application-level error number
"error": "Bad Request", // string description of the error type
"message": "the value of salt is not allowed to be undefined",
"info": "https://docs.dev.lcip.og/errors/1234" // link to more info on the error
Expand All @@ -68,13 +68,15 @@ The currently-defined error responses are:
* status code 401, errno 115: invalid authentication nonce
* status code 411, errno 112: content-length header was not provided
* status code 413, errno 113: request body too large
* status code 429, errno 114: client has sent too many requests (see backoff protocol)
* status code 503, errno 201: service temporarily unavailable to due high load (see backoff protocol)
* status code 429, errno 114: client has sent too many requests (see [backoff protocol](#backoff-protocol))
* status code 503, errno 201: service temporarily unavailable to due high load (see [backoff protocol](#backoff-protocol))
* any status code, errno 999: unknown error

The follow error responses include additional parameters:

* errno 111: a `serverTime` parameter giving the current server time in seconds.
* errno 114: a `retryAfter` parameter indicating how long the client should wait before re-trying.
* errno 201: a `retryAfter` parameter indicating how long the client should wait before re-trying.


## Responses from Intermediary Servers
Expand Down Expand Up @@ -1312,7 +1314,45 @@ There are no standard failure modes for this endpoint.
* GOTO "Attach a new device"


# Client Backoff Protocol
# Backoff Protocol

During periods of heavy load, the auth server may request that clients enter a "backoff" state in which they avoid making further requests.

If the server is under too much load to handle the client's request, it will return a `503 Service Unavailable` HTTP response. The response will include `Retry-After` header giving the number of seconds that the client should wait before issuing any further requests. It will also include a [JSON error response](#response-format) with `errno` of 201, and with a `retryAfter` field that matches the value in the `Retry-After` header. For example, the following response would indicate that the server could not process the request and the client should avoid sending additional requests for 30 seconds:

```
HTTP/1.1 503 Service Unavailable
Retry-After: 30
Content-Type: application/json

{
"code": 503,
"errno": 201,
"error": "Service Unavailable",
"message": "The server is experiencing heavy load, please try again shortly",
"info": "https://github.com/mozilla/fxa-auth-server/blob/master/docs/api.md#response-format",
"retryAfter": 30
}
```

The `Retry-After` value is included in both the headers and body so that clients can choose to handle it at the most appropriate level of abstraction for their environment.

If an individual client is found to be issuing too many requests in quick succession, the server may return a `429 Too Many Requests` response. This is similar to the `503 Service Unavailable` response but indicates that the problem originates from the client's behavior, rather than the server. The response will include `Retry-After` header giving the number of seconds that the client should wait before issuing any further requests. It will also include a [JSON error response](#response-format) with `errno` of 114, and with a `retryAfter` field that matches the value in the `Retry-After` header. For example:

```
HTTP/1.1 429 Too Many Requests
Retry-After: 30
Content-Type: application/json

{
"code": 429,
"errno": 114,
"error": "Too Many Requests",
"message": "This client has sent too many requests",
"info": "https://github.com/mozilla/fxa-auth-server/blob/master/docs/api.md#response-format",
"retryAfter": 30
}
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the section for 429s?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's right here, there's just no example. I'll add one :-)


# Reference Client
Expand Down
6 changes: 4 additions & 2 deletions error.js
Expand Up @@ -199,15 +199,17 @@ Boom.tooManyRequests = function () {
return Boom.wrap({
code: 429,
errno: 114,
message: 'Client has sent too many requests'
message: 'Client has sent too many requests',
retryAfter: 30
})
}

Boom.serviceUnavailable = function () {
return Boom.wrap({
code: 503,
errno: 201,
message: 'Service unavailable'
message: 'Service unavailable',
retryAfter: 30
})
}

Expand Down