Scrivio Interview library

Concurrency patterns

18 questions in 6 subtopics.

Producer-consumer

CodingFoundations7 min read
Implement producer-consumer with a BlockingQueue where one producer reads lines from a file and four consumers process them. How do the consumers stop cleanly when the file is finished?
DebuggingIntermediate7 min read
A service uses Executors.newFixedThreadPool(20) to send events to a slow downstream. During a downstream slowdown the service runs out of heap. Explain the cause and the fix.
DesignAdvanced7 min read
Two components of a system communicate as producer and consumer. One proposal uses an in-process bounded queue, another uses Kafka. How do you decide?

Thread pool

InternalsFoundations6 min read
Explain how ThreadPoolExecutor decides between creating a thread, queueing a task and rejecting it. Why does a pool with core 10, max 50 and an unbounded queue never grow beyond 10 threads?
ScenarioIntermediate7 min read
A service receives 500 requests per second, and each request makes a blocking call to a downstream that takes 200 ms on average. How do you size the thread pool, and what changes with virtual threads?
DesignAdvanced7 min read
Write the standards for thread pools and executors across your services, including virtual threads adoption.

Future and promise

CodingFoundations7 min read
Call two remote services in parallel with CompletableFuture, combine their results, and fail the whole operation if it takes longer than 2 seconds. Which executor do you use?
ConceptIntermediate6 min read
What is the difference between a future and a promise? How does CompletableFuture play both roles, and how can an API hide the write side from callers?
DebuggingIntermediate7 min read
A REST endpoint that builds a response from a CompletableFuture chain sometimes hangs forever, and no exception is logged. The chain uses thenApply and thenCompose, and one stage manually completes a CompletableFuture from a callback API. What are the likely causes?

Immutable object

CodingFoundations7 min read
Make this class immutable and explain each change:
public class Booking {
private Date start;
private List<String> guests;
public Booking(Date start, List<String> guests) {
this.start = start;
this.guests = guests;
}
public Date getStart() {
return start;
}
public List<String> getGuests() {
return guests;
}
}
InternalsIntermediate8 min read
Why are properly constructed immutable objects thread-safe without synchronisation? What does the Java Memory Model guarantee for final fields, and how can that guarantee be broken?
LeadershipPrincipal7 min read
Should your organisation make immutability the default for domain and data objects across all teams? Discuss the long-term costs and benefits and how you would introduce the standard.

Actor model

ConceptIntermediate7 min read
Explain the actor model. How would you implement a simple actor in plain Java, and what do frameworks such as Akka or Apache Pekko add?
DesignAdvanced8 min read
A real-time bidding system keeps per-campaign budgets in memory and receives 200,000 bid events per second. One architect proposes actors, another proposes lock-based services with a shared database. How do you evaluate the options?
LeadershipPrincipal7 min read
A widely used actor framework changed its licence in 2022, and a community fork followed. What does this teach about betting on concurrency frameworks that shape your application code for many years?

Reactor pattern

DebuggingFoundations7 min read
A Spring WebFlux endpoint calls a blocking JPA repository inside a map operator. Under load, throughput collapses and latency rises for all endpoints. Explain and fix.
InternalsIntermediate7 min read
Explain the reactor pattern and how Netty implements it. Why must code never block on an event loop thread?
LeadershipPrincipal7 min read
Java server code moved from thread-per-request to reactive event loops for scalability, and now virtual threads bring back thread-per-request with blocking code. What concurrency model should your company standardise on for the next decade, and how do you handle existing reactive services?