Quick revision
The short answer
Overnight the NAT gateway forgot the idle connection, but the client still believed it was open, so the first morning calls were written into a dead flow and waited on TCP retransmissions until their deadlines expired. The 10-second keepalive fixed the idleness but broke the server's rules: grpc-java servers by default accept pings no more often than every 5 minutes, and none at all on a connection with no calls, so they answered with GOAWAY ENHANCE_YOUR_CALM, too_many_pings. Configure both sides together, for example the server permits pings every minute even without calls and the client pings every 2 to 4 minutes with a 20-second timeout, or let the server close idle connections before 350 seconds, and always use deadlines and retries on UNAVAILABLE.
What to remember
In this answer, we saw that the NAT silently removed idle flows after 350 seconds, so the first morning calls went into a dead connection and hung on TCP retransmissions until their deadlines. A 10-second keepalive violated grpc-java's default policy, pings no more often than 5 minutes and none without calls, and got GOAWAY too_many_pings. The fix is to configure both sides together, with the server permitting idle pings every minute and the client pinging every 2 to 4 minutes with a 20-second timeout, or to close idle connections on the server before 350 seconds, backed by deadlines and retries on UNAVAILABLE.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Overnight the NAT gateway forgot the idle connection, but the client still believed it was open, so the first morning calls were written into a dead flow and waited on TCP retransmissions until their deadlines expired. The 10-second keepalive fixed the idleness but broke the server's rules: grpc-java servers by default accept pings no more often than every 5 minutes, and none at all on a connection with no calls, so they answered with GOAWAY ENHANCE_YOUR_CALM, too_many_pings. Configure both sides together, for example the server permits pings every minute even without calls and the client pings every 2 to 4 minutes with a 20-second timeout, or let the server close idle connections before 350 seconds, and always use deadlines and retries on UNAVAILABLE.
Why this question is asked
This pair of problems shows up whenever gRPC crosses a NAT, a firewall or a cloud load balancer with an idle timeout, and the obvious first fix creates the second problem. Interviewers ask it to see whether we understand that keepalive is a contract between client and server, not a client setting. In this answer, we will see why the morning calls hung, why the server rejected the pings, then configure keepalive on both sides, look at the alternative of closing idle connections, and finish with deadlines and retries.
1A Quick Recap: NAT Gateways Keep State
A NAT gateway translates private addresses to a public one. For every TCP connection passing through it, it keeps a mapping in a table, and to save memory it removes mappings that have been idle for a while; for this cloud NAT gateway, 350 seconds. It does this silently. Neither the client nor the server is told, so both still believe the TCP connection is open.
gRPC keeps long-lived connections on purpose, so a channel that carries no calls overnight sits idle for hours, far longer than 350 seconds.
2Why the First Morning Calls Hung
In the morning, the client sends its first call on the existing connection. The packets reach the NAT gateway, which has no mapping and drops them, or the server's answer cannot get back. The client's TCP stack sees no acknowledgement and retransmits, waiting longer each time, as TCP is designed to do. It can keep retrying for many minutes before it declares the connection dead. Meanwhile, the gRPC call waits for a response that never comes and fails only when its deadline expires, with DEADLINE_EXCEEDED. Every call sent on that connection does the same.
6 messages in order. Play them, or step through them one at a time.
Neither end is told that the NAT removed the flow.
So the problem is not the network being down; it is a connection that both ends think is alive but that the middle has forgotten. Two things are needed: keep the connection from looking idle, and detect a dead connection quickly when it happens anyway.
3Why the Server Sent GOAWAY too_many_pings
A keepalive ping is an HTTP/2 PING frame; the other side answers with a PING acknowledgement. Sending one every 10 seconds certainly keeps the NAT mapping alive. But a server that accepts unlimited pings can be overwhelmed by clients pinging constantly, so gRPC servers enforce a policy. In grpc-java, permitKeepAliveTime defaults to 5 minutes: pings more frequent than that are counted as strikes. And permitKeepAliveWithoutCalls defaults to false: a ping on a connection with no active calls is treated as too frequent unless it comes hours apart.
After a couple of strikes, the server sends a GOAWAY frame with the error code ENHANCE_YOUR_CALM and the debug data too_many_pings, and closes the connection. Recent grpc-java clients react by doubling their keepalive time, but check your version. Either way, the 10-second keepalive turned a quiet morning problem into regular connection resets.
4Configuring Both Sides Together
The rule is that the client's ping interval must be longer than the server's minimum permitted interval, and if the client pings while idle, the server must permit idle pings. The interval must also be shorter than the NAT's 350-second idle timeout, with margin.
Notice the keepAliveTimeout. Keepalive does two jobs: the pings keep the NAT mapping fresh, and if a ping is not acknowledged within 20 seconds, the client closes the connection, fails its in-flight calls with UNAVAILABLE and reconnects. That second job also protects against other silent failures, such as a crashed middlebox. If we do not control the server, for example a partner's API, we must ask what it permits and stay above it.
5Alternative: Close Idle Connections Before the NAT Does
Instead of keeping idle connections alive, the server can close them cleanly before the NAT forgets them. With maxConnectionIdle set below 350 seconds, say 5 minutes, the server sends GOAWAY to a connection that has had no calls for that long, and the client opens a new connection the next time it needs one. The first morning call then pays one TCP and TLS handshake, a few round trips, instead of hanging until its deadline. This needs no client changes and no idle pings, which makes it attractive when we control the server but not every client. Many setups use both: idle close on the server, plus a moderate client keepalive for connections that carry occasional calls.
6Deadlines and Retries as the Last Line
Whatever we configure, some connection will die silently one day. So every call should carry a deadline, which the team already had, and idempotent calls should be retryable on UNAVAILABLE, the status a call gets when its connection fails. grpc-java supports retries through the service config, so a dead connection costs one quick retry on a fresh connection instead of a full timeout.
7Follow-up questions
How does a GOAWAY frame let in-flight calls finish?
A GOAWAY frame tells the peer that no new streams will be accepted on this connection, and it carries the id of the last stream the sender will process. Streams with that id or lower continue normally and complete; streams with a higher id were not processed and can safely be retried elsewhere. The client stops creating new streams on the connection and opens a new one for new calls. gRPC servers shutting down gracefully often send a first GOAWAY with the maximum stream id, wait a ping round trip so calls already in flight are counted, then send the final GOAWAY with the real last id.
Why does grpc-java reject frequent pings at all?
Because pings cost the server CPU and network for every connection, and a misconfigured fleet of clients pinging every second can create real load. The enforcement policy protects the server and pushes clients towards sensible intervals agreed with the server owner.
8Conclusion
In this answer, we saw that the NAT silently removed idle flows after 350 seconds, so the first morning calls went into a dead connection and hung on TCP retransmissions until their deadlines. A 10-second keepalive violated grpc-java's default policy, pings no more often than 5 minutes and none without calls, and got GOAWAY too_many_pings. The fix is to configure both sides together, with the server permitting idle pings every minute and the client pinging every 2 to 4 minutes with a 20-second timeout, or to close idle connections on the server before 350 seconds, backed by deadlines and retries on UNAVAILABLE.
Open with
There are two problems. First, the NAT gateway silently drops a flow after 350 seconds idle, but neither client nor server is told, so in the morning the client sends calls on a connection the NAT no longer knows.
Then, if they want more
The packets are dropped, TCP keeps retransmitting with backoff, and each call waits until its deadline expires.
Second, the 10-second keepalive did keep the flow alive, but grpc-java servers by default only accept pings every 5 minutes, and none on a connection with no active calls, so after a couple of strikes the server sends GOAWAY with ENHANCE_YOUR_CALM and too_many_pings and closes the connection. Keepalive has to be configured on both sides.
On the server I would set permitKeepAliveTime to one minute and permitKeepAliveWithoutCalls to true. On the client, keepAliveTime around 2 to 4 minutes, which is above the server minimum and below 350 seconds, keepAliveWithoutCalls true, and keepAliveTimeout around 20 seconds so a dead connection is detected and replaced quickly.
An alternative is maxConnectionIdle under 350 seconds on the server, so it closes idle connections cleanly and clients reconnect instead of using a dead one. And I would keep deadlines on every call and enable retries on UNAVAILABLE for idempotent methods, so a dead connection costs one retry, not a full timeout.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain both problems and configure keepalive correctly on client and server.": https://scrivio-interview-library.netlify.app/architecture/load-balancing-networking/1c72a02385/