Scrivio Interview library

Networking

20 questions in 7 subtopics.

Sockets

CodingFoundations7 min read
Write a minimal blocking TCP echo server with ServerSocket that can serve several clients at once. What would you change on Java 21?
DebuggingIntermediate7 min read
A service has thousands of sockets in TIME_WAIT and CLOSE_WAIT states. Explain what each state means and which one points to a bug in your Java code.

Java.net.http HttpClient

CodingFoundations6 min read
Use java.net.http.HttpClient to send a GET request with a 5 second timeout and parse the body as a String. Show both the synchronous and asynchronous call.
ConceptIntermediate6 min read
Compare java.net.http.HttpClient with Apache HttpClient, OkHttp and Spring's RestClient or WebClient for a service that calls many downstream APIs.
DesignAdvanced7 min read
Design a shared HTTP client library used by many teams for calling internal services. What defaults and features do you build in?
LeadershipAdvanced6 min read
Teams call internal services with five different HTTP client libraries, each with different defaults. Do you standardise on one, and how do you sequence the change across the organisation?

URL and URI

ConceptFoundations7 min read
What is the difference between java.net.URL and java.net.URI? Why is URL.equals considered dangerous, and what changed for URL constructors in recent JDKs?
DebuggingIntermediate7 min read
A client builds request URLs by string concatenation: "https://api/x?q=" + userInput. Some requests fail and one security test injects extra parameters. What is wrong and how do you build URIs safely?

TLS and certificates in Java

DebuggingFoundations7 min read
A Java client fails with PKIX path building failed: unable to find valid certification path to requested target when calling an internal HTTPS service. What does it mean and how do you fix it properly?
ScenarioIntermediate7 min read
Certificates for your services now rotate every few days through an internal CA. Java services keep failing after rotation until they restart. How do you make TLS reload work?
LeadershipAdvanced7 min read
Your platform runs a mix of JDK versions from several vendors. A new security rule requires TLS 1.3 where possible, no TLS 1.0 or 1.1, and central trust management. How do you roll this out?
LeadershipPrincipal6 min read
Certificate lifetimes keep getting shorter and post-quantum algorithms are being added to JDKs. Over the next several years, how should your organisation manage TLS and cryptography in Java services?

DNS caching in the JVM

ConceptIntermediate7 min read
How does the JVM cache DNS lookups? Explain networkaddress.cache.ttl and networkaddress.cache.negative.ttl and what happens in containers that call services with changing IPs.
DebuggingIntermediate7 min read
After a database failover that changed the endpoint's IP, one Java service kept connecting to the old address for a long time while others recovered quickly. What would you check?
LeadershipPrincipal6 min read
Infrastructure moved from fixed servers to cloud endpoints whose IPs change frequently, yet JVM and library defaults date from the old model. How do you govern network-related defaults such as DNS TTL, connection lifetime and keep-alive across the fleet?

Connection timeouts

ConceptFoundations7 min read
Explain the difference between a connect timeout, a read (socket) timeout and an overall request timeout. What happens if none is set on a Java client?
ScenarioIntermediate7 min read
During an incident a slow downstream service caused your service's thread pool to fill and the service stopped answering health checks. Which timeout settings and patterns would have prevented it?
LeadershipPrincipal6 min read
Timeouts, retries and DNS settings are defined differently in every client library and repeatedly cause incidents. Where should this responsibility live in a large organisation: in each service, in shared libraries, or in the platform such as a service mesh?

HttpURLConnection

DebuggingFoundations7 min read
Legacy code calls a REST service with HttpURLConnection. Threads hang forever when the service is slow, and connections are not reused. Show what is missing in the code, and say what replaces HttpURLConnection in modern Java.
ScenarioAdvanced7 min read
A security scan finds HttpURLConnection used directly in 90 places across 30 services, many without timeouts, and RestTemplate configured with SimpleClientHttpRequestFactory, which also uses it. Plan the retirement of HttpURLConnection usage.