Java
CompletableFuture
Future
RxJava
Observable

Difference between CompletableFuture, Future and RxJava's Observable

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Future, CompletableFuture, and RxJava's Observable all deal with asynchronous work, but they solve different kinds of problems. The easiest way to separate them is by asking two questions: do you need one result or many, and do you need simple waiting or rich composition?

Future Is the Basic Placeholder for One Result

A Future represents the result of work that may finish later. It can tell you whether the work is done, let you cancel it, and let you block until the result arrives.

java
ExecutorService pool = Executors.newSingleThreadExecutor();
Future<String> future = pool.submit(() -> "done");
System.out.println(future.get());

The limitation is that Future does not compose well. You mostly wait for it or poll it.

CompletableFuture Adds Composition for One Async Result

CompletableFuture still models a single eventual result, but it adds a fluent API for chaining, combining, and handling errors without blocking at each step.

java
CompletableFuture.supplyAsync(() -> "hello")
    .thenApply(value -> value + " world")
    .thenAccept(System.out::println);

This is the usual Java choice when one async operation should trigger more work after it completes.

Observable Models a Stream of Values Over Time

RxJava's Observable is different because it can emit zero, one, or many items, plus completion or error events. That makes it suitable for UI events, network streams, repeated updates, or pipelines where data keeps arriving.

java
Observable.just("hello", "world")
    .map(String::toUpperCase)
    .subscribe(System.out::println);

This is not just a fancier Future. It is a stream abstraction with operators for transforming and combining sequences.

A Good Rule of Thumb

Use Future when you only need a minimal handle for background work. Use CompletableFuture when you have one eventual result and want non-blocking composition. Use Observable when the problem is naturally a stream of events or values rather than one completion.

That rule is more useful than memorizing API tables because it maps directly to the shape of the problem.

Error Handling and Backpressure Considerations

CompletableFuture has explicit error operators such as handle, exceptionally, and whenComplete. RxJava has rich stream-level error handling, but it also brings stream semantics and, depending on the type used, backpressure considerations. That extra power is valuable only when your problem actually benefits from a reactive stream model.

Cancellation and Lifecycle Feel Different

Future and CompletableFuture both have cancellation APIs, but cancellation in stream-oriented systems is a broader subscription concern. With Observable, you are managing a relationship to a data source over time rather than just waiting for one task to finish. That is another hint that reactive streams are a different abstraction, not just a nicer callback wrapper around a single async result.

Common Pitfalls

  • Using Future where composition is needed and then building manual blocking chains.
  • Using Observable for a single one-off result when CompletableFuture would be simpler.
  • Treating CompletableFuture as a stream abstraction when it only represents one completion.
  • Choosing a reactive library for style rather than for a true multi-value or event-stream requirement.
  • Comparing these types only by syntax instead of by the number of values and composition style they represent.

Summary

  • Future is the basic Java handle for one asynchronous result.
  • CompletableFuture is for one result with much better composition and error handling.
  • Observable represents a stream of values or events over time.
  • The right choice depends mainly on whether the problem yields one value or many.
  • Simpler async abstractions are usually better unless the problem is genuinely reactive.

Course illustration
Course illustration

All Rights Reserved.