You're building a price comparison service. When a user searches for a product, you need to fetch prices from Amazon, eBay, and Walmart. Each API call takes 200-500ms.
The naive approach calls each API sequentially. Total time: 600-1500ms. Users wait while your server sits idle between network calls.
You could use threads and callbacks. Spawn three threads, each calls an API and invokes a callback with the result. But now you're managing thread lifecycles, synchronizing callbacks, handling partial failures, and your code looks like spaghetti.
The Future/Promise Pattern solves this elegantly. A Future is a placeholder for a result that will arrive later. You start all three API calls, get three Futures immediately, and combine them. The framework handles threading, synchronization, and composition. Your code stays clean and readable.
In this article, we'll explore:
If you're enjoying this newsletter and want to get even more value, consider becoming a [paid subscriber](https://blog.algomaster.io/subscribe).
As a paid subscriber, you'll unlock all premium articles and gain full access to all [premium courses](https://algomaster.io/newsletter/paid/resources) on [algomaster.io](https://algomaster.io).
The Future/Promise Pattern represents the result of an asynchronous computation. A Future is a read-only placeholder that will eventually contain a value or an error. A Promise is the writable side that completes the Future.
Think of it like ordering food at a restaurant. You get a receipt (Future) immediately. The kitchen (async task) prepares your food and delivers it (completes the Promise). You can do other things while waiting, and when the food is ready, you're notified.
Without Futures, handling async operations is painful.
The thread blocks on each call, doing nothing while waiting for network responses.
You manage thread creation, coordination, and error handling manually.
Each async step adds a nesting level. Error handling duplicates everywhere.
Start all calls, get Futures, combine them. The framework handles parallelism.
A Future has a lifecycle from creation to completion.
The caller gets the Future immediately and can:
get() until the result is readyA Promise lets you manually complete a Future.
Blocking defeats the purpose. Use callbacks to react when the Future completes.
The main thread never blocks. When the result arrives, the callback runs.
The real power of Futures is composition. Chain operations, combine results, handle errors declaratively.
Transform a Future's result without blocking.
When one async operation depends on another's result.
No nesting. Each step flows into the next.
Run operations in parallel and combine results.
Sometimes you only need the fastest response.
Futures propagate errors through the chain.
An error at any step skips remaining steps and goes to the error handler.
Futures should not wait forever. Add timeouts to fail fast.
Futures need a thread pool to run tasks.
These terms often cause confusion.
The Future/Promise Pattern appears frequently in system design.
allOf to wait for all API calls, then combine the results."exceptionally to provide fallback values so one failure doesn't break everything."Let's implement the price comparison service from the introduction.
Key design decisions:
The Future/Promise Pattern represents asynchronous computation results as first-class values that can be composed, transformed, and handled declaratively.
The Future/Promise Pattern is essential for building responsive, scalable systems. In LLD interviews, it demonstrates understanding of async programming, composition, and practical concurrency patterns.
Thank you for reading!
If you found it valuable, hit a like and consider subscribing for more such content every week.
If you have any questions or suggestions, leave a comment.
This post is public so feel free to share it.
P.S. If you're enjoying this newsletter and want to get even more value, consider becoming a [paid subscriber](https://blog.algomaster.io/subscribe).
As a paid subscriber, you'll unlock all premium articles and gain full access to all [premium courses](https://algomaster.io/newsletter/paid/resources) on [algomaster.io](https://algomaster.io).
There are [group discounts](https://blog.algomaster.io/subscribe?group=true), [gift options](https://blog.algomaster.io/subscribe?gift=true), and [referral bonuses](https://blog.algomaster.io/leaderboard) available.
Checkout my [Youtube channel](https://www.youtube.com/@ashishps_1/videos) for more in-depth content.
Follow me on [LinkedIn](https://www.linkedin.com/in/ashishps1/) and [X](https://twitter.com/ashishps_1) to stay updated.
Checkout my [GitHub repositories](https://github.com/ashishps1) for free interview preparation resources.
I hope you have a lovely day!
See you soon, Ashish