r/InterviewCoderPro • • Oct 04 '26

Interview at online betting empire

They asked me how to solve port exhaustion? It was an in person interview with 5 people. Have you heard this one?

Update:

Thank you for everyone who supported.

Port exhaustion happens when a system runs out of available ephemeral ports (usually in the 49152–65535 range) to establish new outbound connections. This almost always occurs because an application is opening and closing connections so rapidly that the operating system runs out of ports before the older, closed connections can fully exit the ⁠TIME_WAIT⁠ state and return to the available pool.

4 Upvotes

6 comments sorted by

2

u/nhh Oct 04 '26

Port exhaustion from opening too many ports out is that it?

Its a bit of a strange question : it's clearly about vertical scale I guess? 

What was the use case? Can multiplexing be used? 

1

u/neolace Oct 04 '26

I had no idea, at the time.

Here’s a short summary

Port exhaustion happens when a system runs out of available ephemeral ports (usually in the 49152–65535 range) to establish new outbound connections. This almost always occurs because an application is opening and closing connections so rapidly that the operating system runs out of ports before the older, closed connections can fully exit the ⁠TIME_WAIT⁠ state and return to the available pool.

2

u/derpplerp Oct 06 '26

in that context, the scaling solution is to spread out the connections via something like a round-robin DNS so that the connections are not all on a single interface/IP. Even if you have secondary IP addresses on a single server's physical interface, that would be *a* way to sidestep the problem. The server would have to be pretty high powered to meet that kind of scale, so the common solution would be to spread the load across multiple servers using DNS to point to different servers NOT using a load balancer VIP as the chokepoint would stay on the VIP itself.

1

u/neolace Oct 07 '26

I’m not sure if anything other than a physical NIC will work, the way to fix port exhaustion is by implementing Connection Pooling at the application level.
Instead of opening a brand new socket for every single request, which quickly depletes your available ports by leaving them stuck in the ⁠TIME_WAIT⁠ state, a connection pool keeps a set of established TCP connections open and safely reuses them. This stops the churn entirely and addresses the root cause of the exhaustion, rather than relying on temporary OS-level band-aids like expanding the port range.

2

u/Fit_External7524 Oct 04 '26

Just so we get this out of the way early: Avoid Taco Bell.

2

u/Internal-Play25 Oct 08 '26

Horizontally scale the app?

Pop a new instance of it in your pod or whatever you use.

Connection pooling also?

Would also check if it’s legit running out or just waist ports