r/SpringBoot • u/Huge_Road_9223 • Feb 15 '26
Question Architecting a System for Millions of Requests
A friend of mine is interviewing for a new Java/SpringBoot role, and one of the questions is as the title suggests: "How would architect/design a system where there are millions of requests per day/hour and do some complicated work on the backend." He told me what his response was, and I feel it was spot on. But now I am thinking is there anything more that could be added:
- Make sure the database read/writes are performant, with some tweaking on the connection pooling side.
- Using Redis to cache common data to avoid going to the database all the time. This I know takes more memory, but makes it so much faster.
- Using Kafka, or Message Queuing for event-driven development. One request could be put on a queue/topic and then other systems take these events and so work could be done in paralell rather than serially. So, A B and C could do work at the same time instead of A, then B, then C.
- Microservices, API throttling, Resiliencey with Circuit Breaking, logging with correlation id
- Other third party API services could be used which we have no control over, so we don't know if those services will be up, or working poorly.
So, when a user makes a request, if the backend process takes time, an immediate response could go back to the user to let them know their process is being worked on, and they'll be notified when this is done or completed.
Anything else that is missing? Honestly, as a software engineer in the same space, we can only do so much when it comes to the code. When it comes to scaling this, I'm usually know when my code is deployed to DEV, and then to QA where it may or may not go through performance testing. When it comes to a Staging, Pre-Prod, or Prod environments no one has ever asked me about how to scale this? This is usually in the hands of people who are more in the Operations space, and know the Cloud environment like AWS who make it easy to add more resources when it is needed.
I know I have always tried to make my code work as fast as possible when running locally, or in the integrated DEV environment. I figure if something works quick there, then it will work even faster in Prod where I presume more resources are added.
Thoughts?
9
u/pagurix Feb 15 '26
If most of the requests that need to be served in real time are reads, while writes can be served at a slower rate, you might also consider the CQRS pattern.
11
u/StretchMoney9089 Feb 15 '26
Virtual threads
5
u/Appropriate_Swim9528 Feb 15 '26
Design with no server side sessions in mind.
3
u/Voiceless_One26 Feb 16 '26
This is usually an open ended question. When we are asked about something like this, it’s best not to jump into solution right away but ask a lot of clarifying questions to understand more about the system.
Are these requests for dynamic data or are there a lot of repeating requests for the same resource? For example, consider weather updates, once we get the details from the forecast service (could be a 3rd party service), it’s not likely to change for the next 24 hours, so caching them in a tiered-cache - InMemory (Caffeine) for super fast access + a distributed cache like Valkey (or Redis) would be very useful because the data doesn’t change that often, so you’re likely to have very good cache hit rates which can reduce the latencies compared to querying the DB or a 3rd party service. If it’s something that’s accessible to anonymous users and you have a CDN, you can cache these API responses there as well for few hours, greatly reducing the burden on your origin servers which will free them to do other things.
But the same caching strategy gets complicated with cache invalidation when you have data that’s getting modified frequently and how soon we need to return these updates in our APIs.
If it’s a read-heavy system and the replication lag between your DB nodes is within an acceptable range considering your use case, then making use of secondaries in your DB cluster will help in better utilisation of DB infrastructure + better latencies. But if your app is doing lots of writes or reads-after-writes or the replication lag is say >10s, then this might not be an option for all APIs but may be for some.
Going back to the strategy that you suggested earlier for deferred responses like - we’ve received your request and we’ll let you know in sometime - This might be a good idea for a use case like downloading last 6 months bank statements where we start some background process/job for the report generation but we send an acknowledgement immediately to FE - This would mean a user experience change compared to other things in your app and your FE needs to poll for the report-availability or be notified via web-sockets or SSE.
Virtual Threads in Java 21 or above are useful if you’re doing lots of IO operations - These VTs are optimised to use release underlying platform threads for IO ops but they won’t be faster for CPU intensive tasks. For example, VTs are a good option in a gateway or a proxy service that does very little work locally and waits for the response to come from downstream services but they will not be any better than existing threads if you were to do some data crunching.
To quote Sir Grady Booch - All architecture is design but not all design is architecture. Architecture represents the significant design decisions that shape a system, where significant is measured by cost of change.
It’s always about trade-offs but to make those decisions, we need to know our options and understand our use cases better. It’s alright if we don’t get everything right the first time - But if there’s a production incident, it’s important that we learn from them and make it better for next time.
1
u/veryspicypickle Feb 15 '26
What is being served at that rate?
What is the nature of the “complicated work”?
What kind NFRs are acceptable?
There’s a lot of questions to ask before we arrive at a solution
1
u/RScrewed Feb 16 '26
Why'd this need the "friend" part of the story?
2
u/rarereditter Feb 15 '26
I work on systems with TPS of millions with performance requirement p99 in 10s of milliseconds. We use Probabilistic filters to return what we can locally before even hitting caches and API. And even when the call reaches the API, the same waterfall model exists: Probabilistic filter > cache > db. Hope this makes sense
2
u/m1lk93 Feb 17 '26
"System design interview" by alex hu like 2nd or 3rd chapter dives deep how to scale to million users. it is not that simple. always ask further questions clarifying the requirements.
2
u/dudeaciously Feb 15 '26
I feel this calls for non-linear thinking. Rather than vertically scaling and tuning the database, how do you fell about CQRS, big data, separation of reads vs. writes. Scaling the app layer horizontally is a given. Data is harder.
Then there come event driven queuing and messaging. So I say architecting according to the core uses would be good.
1
u/daqueenb4u Feb 15 '26
Would Load balancing / rate limiting would be in scope? And perhaps setting up to take instances out of the load balance to perform updates and then add back to avoid downtime? Add a monitoring service like Pingdom.
1
u/guss_bro Feb 19 '26
Once you build a MVP or a prototype, profile and load test your app to find out where is the bottleneck, it's often outside of your code(eg external service, DB, etc). Then find a way to optimize those calls eg: cache, indexing, replicas etc.
Million of request per hour is not much. It depends on what kind of processing your request needs. Over-architecting or making it complex from the beginning is not a good idea IMO. You have spring and Java which allows you to write performant code. You just need to start small and optimize later.
If it's billions of requests per hour, then I would think differently from start.
1
u/eotty Feb 21 '26
I agree with worksfinelocally asking questions is key here.
But if we work backwards (always a good idea with complex problems), a well written java spring boot service without too much complexity - ofcause depending on hardware, can handle about 1000 request/second, 1000*60*60 = 3.6 million requests/hour or 84 million requests/day, so to that question i would say have a good loadbalancer, decent hardware and a decent optimized java app and maybe 2 instances and we are good for like 7 million requests/hour. Without any effort at all.
This is where we get back to the questions. What is the app? I ran locust on my local-lab authentication service, it runs on a MariaDB 10 database hosted by my local NAS with 4 gb ram and spinning disks. My Lab is 3x Raspberry pi 4b 4gb running K3s
Locust had 1 master 4 workers and was setup to move 10k concurrent requests.
With the above settings
It maxed out at 1000 concurrent users, not because of the spring boot app or the hardware but betcause of the default config limiting it.
This is where i get the 1000 from, so if i can host 1000 concurrent requests on a raspberry pi with 1.5ghz arm cpu and 4 gb of ram no settings and a DB running on an old NAS with 4 gb of ram on spinning disks, What could i do with an AWS cluster and some settings.
So when it comes to Springs capability and the hardware we are good. The question we need to ask is whats the requirement from the logic running inside the application.