Scrivio Interview library
ConceptIntermediate6 min read · updated 12 November 2026

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?

A future is the read side of an asynchronous result: a handle the consumer uses to wait for, check or react to a value that will exist later. A promise is the write side: the object the producer uses to complete that result with a value or a failure. CompletableFuture is both at once, so anyone who holds it can read and chain it and also call complete. To hide the write side, keep the CompletableFuture private inside the producer and return a CompletionStage, preferably the one from minimalCompletionStage(), or a copy, so callers cannot complete the real one.

Why this question is asked

Asynchronous APIs hand out results that do not exist yet, and somebody has to be responsible for filling them in. Many languages separate the reader's handle from the writer's handle, and Java blurred the two with CompletableFuture, which is convenient but makes it easy for callers to interfere with an API's results. Interviewers ask this to see whether we understand the roles and can design an API that keeps them apart. In this answer, we will define future and promise, look at Java's Future interface as a pure read side, see how CompletableFuture plays both roles, show how a caller can break an API that returns it, and then hide the write side properly.

1A Quick Recap: Two Sides of One Result

Think of a restaurant pager. When we order, the counter gives us a pager: we can wait for it to buzz, check it, or walk away. That pager is the future, a read-only handle to a result that will be available later. The kitchen has the other side, the button that makes the pager buzz. That button is the promise, the write side, used by the producer to complete the result with a value, or in software, with a failure.

The separation matters because the two sides belong to different people. The customer should not be able to buzz their own pager, and the kitchen should be the only one deciding when the meal is ready. Scala's standard library, for example, models this with two types, Promise and Future, where the promise creates the future and only the promise can complete it.

2Java's Future: a Pure Read Side

The original java.util.concurrent.Future interface from Java 5 is purely a reading handle. We can call get() to block until the result is ready, get(timeout, unit) to wait with a limit, isDone() to check, and cancel() to say we no longer need it. There is no method to complete it, because the executor that ran the task does that internally.

Java
ExecutorService pool = Executors.newFixedThreadPool(4);
Future<Integer> f = pool.submit(() -> 6 * 7); // the pool holds the write side internally
System.out.println(f.get()); // 42
System.out.println(f.isDone()); // true
// there is no f.complete(...): the reader cannot set the value

The limitation of Future is that it can only be waited on. We cannot say when this finishes, do that next, so composing several asynchronous steps means blocking threads on get(). That is what CompletableFuture, added in Java 8, solved.

3CompletableFuture Plays Both Roles

CompletableFuture implements Future for reading and CompletionStage for composition, with methods like thenApply, thenCompose and thenCombine. It also has the write methods: complete(value), completeExceptionally(ex), and the stronger obtrudeValue, which overwrites even a completed result. So the same object is both the promise and the future.

Java
CompletableFuture<String> cf = new CompletableFuture<>(); // created by the producer
cf.thenApply(String::toUpperCase) // a reader chains on it
.thenAccept(System.out::println);
cf.complete("ready"); // the producer completes it; prints READY
cf.complete("again"); // false: a future completes only once

This is convenient for producers: an adapter for a callback API can create a CompletableFuture, return it, and complete it from the callback. But there is a catch: if the same object is returned to callers, they also hold the write side.

4How a Caller Can Break an API That Returns It

Suppose a price service returns its internal CompletableFuture to every caller who asks for the same product, a common caching trick to avoid duplicate remote calls.

Java
public CompletableFuture<Price> priceOf(String sku) {
return inFlight.computeIfAbsent(sku, this::fetchAsync); // shared by all callers
}
// One careless caller somewhere:
CompletableFuture<Price> p = prices.priceOf("A-17");
p.complete(Price.ZERO); // "default while we wait"
// Every other caller of priceOf("A-17") now receives a price of zero.
// The real remote result is ignored when it arrives: the future was already complete.
Step throughWho may complete the result
CallerPriceServiceHidden CompletableFutureRemote API
priceOf("A-17")
new CompletableFuture, kept private
minimalCompletionStage(): read-only view
fetch price asynchronously
price 19.99
complete(19.99): only the producer can
view completes with 19.99; the caller reacts

7 messages in order. Play them, or step through them one at a time.

The producer keeps the promise; callers receive only a future they cannot complete.

The caller meant well, perhaps wanting a default value, but because CompletableFuture is a promise too, the caller completed the shared future for everyone. Callers can also call cancel(), which completes the shared future with a CancellationException for all other readers. Returning CompletableFuture from an API exposes the write side, so the producer no longer controls its own results.

5Hiding the Write Side

The fix is to keep the CompletableFuture private in the producer and give callers a type without write methods. The interface CompletionStage has all the composition methods but no complete(), so returning CompletionStage<Price> is the first step. There is a subtlety, though: CompletionStage has a method toCompletableFuture(), and for a CompletableFuture returned as a CompletionStage it simply returns the same object, so a determined caller can still complete it. Java 9 added two methods for exactly this. minimalCompletionStage() returns a stage that cannot be completed independently and whose toCompletableFuture() returns a new copy, and copy() returns a new CompletableFuture that completes when the original does, so completing the copy affects only that copy.

Java
public CompletionStage<Price> priceOf(String sku) {
CompletableFuture<Price> shared = inFlight.computeIfAbsent(sku, this::fetchAsync);
return shared.minimalCompletionStage(); // read-only view for this caller
}
CompletionStage<Price> view = prices.priceOf("A-17");
view.toCompletableFuture().complete(Price.ZERO); // completes only a private copy
view.thenAccept(System.out::println); // 19.99 when the real price arrives

Now each caller gets its own read-only view. They can chain on it, and if they need a CompletableFuture to call join(), toCompletableFuture() gives them a copy they may do anything with, without touching the producer's result. Callers that want to block call view.toCompletableFuture().join(), which is fine because it waits on their own copy of the same result.

6Follow-up questions

If CompletionStage is returned, how does a caller apply a timeout?

They convert to their own copy with toCompletableFuture() and apply orTimeout or completeOnTimeout to it. On a minimal stage that copy is independent, so the caller's timeout fails only their view and never the shared result, which is exactly the separation we want.

Is exposing CompletableFuture always wrong?

No. If each call returns a fresh future that only that caller holds, completing or cancelling it affects nobody else, and many libraries return CompletableFuture for convenience. The danger appears when futures are shared, cached or reused, and in public APIs whose authors want to keep full control. Returning CompletionStage is the safer default for library APIs.

What does a JavaScript Promise correspond to?

A JavaScript Promise is mostly the read side: callers attach then and catch, while the resolve and reject functions are given only to the code inside the Promise constructor. That is the same separation we built with a private CompletableFuture and a minimal stage.

7Conclusion

In this answer, we saw that a future is the read-only handle to a later result and a promise is the producer's write side. Java's Future interface is purely the read side, while CompletableFuture is both, so anyone holding it can call complete or cancel and affect every other reader. To hide the write side, the producer keeps the CompletableFuture private and returns a CompletionStage, ideally from minimalCompletionStage() or as a copy(), so callers can chain and wait on their own view without being able to complete the real result.

What to say in the interviewAbout 90 seconds aloud

Open with

A future is the read side of an asynchronous result: a handle you can wait on, check, or attach callbacks to, for a value that will exist later.

Then, if they want more

A promise is the write side: the producer uses it to complete that result with a value or an exception. Some languages keep them as separate types, like Scala's Promise and Future. In Java, the old Future interface is a pure read side, you can get, check isDone and cancel, but not complete it.

CompletableFuture is both at once: it implements Future and CompletionStage for reading and chaining, and it also has complete and completeExceptionally. That is convenient for a producer adapting a callback API, but if I return the same CompletableFuture to callers, they hold the write side too.

If the future is shared, say cached for in-flight requests, one caller calling complete with a default value would give that value to everyone and the real result would be ignored. To hide the write side, I keep the CompletableFuture private in the producer and return CompletionStage.

Since toCompletableFuture on a plain CompletableFuture returns the same object, I return minimalCompletionStage, which cannot be completed independently and whose toCompletableFuture gives a copy, or I return copy. Then callers can chain, wait and even apply their own timeouts without affecting the producer's result.

About this answer

Last updated
12 November 2026
Versions it names
Java 5, Java 8, Java 9
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 "What is the difference between a future and a promise? How does CompletableFuture play...": https://scrivio-interview-library.netlify.app/java/concurrency-patterns/2c714dd20a/