You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/best-practices/api.md
+3-27Lines changed: 3 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,13 +3,14 @@ title = "API Best Practices"
3
3
weight = 100
4
4
description = "A future-proof API is surprisingly hard to get right. The suggestions in this document make trade-offs to favor long-term, bug-free evolution."
5
5
type = "docs"
6
+
aliases = "/programming-guides/api"
6
7
+++
7
8
8
9
Updated for proto3. Patches welcome!
9
10
10
11
This doc is a complement to
11
-
[Proto Best Practices](/programming-guides/dos-donts).
12
-
It's not a prescription for Java/C++/Go and other APIs.
12
+
[Proto Best Practices](/best-practices/dos-donts). It's
13
+
not a prescription for Java/C++/Go and other APIs.
13
14
14
15
If you see a proto straying from these guidelines in a code review, point the
15
16
author to this topic and help spread the word.
@@ -730,31 +731,6 @@ your service name, even if it is defined inside a specific package. For example,
730
731
a service named `Watcher` is likely to cause problems; something like
731
732
`MyProjectWatcher` would be better.
732
733
733
-
## Ensure Every RPC Specifies and Enforces a (Permissive) Deadline {#every-rpc-deadline}
734
-
735
-
By default, an RPC does not have a timeout. Since a request may tie up backend
736
-
resources that are only released on completion, setting a default deadline that
737
-
allows all well-behaving requests to finish is a good defensive practice. Not
738
-
enforcing one has in the past caused
739
-
severe problems for major services . RPC clients
740
-
should still set a deadline on outgoing RPCs and will typically do so by default
741
-
when they use standard frameworks. A deadline may and typically will be
742
-
overwritten by a shorter deadline attached to a request.
743
-
744
-
Setting the `deadline` option clearly communicates the RPC
745
-
deadline to your clients, and is respected and enforced by standard frameworks:
746
-
747
-
```proto
748
-
rpc Foo(FooRequest) returns (FooResponse) {
749
-
option deadline = x; // there is no globally good default
750
-
}
751
-
```
752
-
753
-
Choosing a deadline value will especially impact how your system acts under
754
-
load. For existing services, it is critical to evaluate existing client behavior
755
-
before enforcing new deadlines to avoid breaking clients (consult SRE). In some
756
-
cases, it may not be possible to enforce a shorter deadline after the fact.
757
-
758
734
## Bound Request and Response Sizes {#bound-req-res-sizes}
0 commit comments