My System Design & Backend Engineering repo is now open source!
Java, System Design, Kafka, Redis & real-world case studies.
Contributions & feedback are welcome 🤝
🔗 github.com/CyberVerve07/Syst…
#OpenSource #Java #SystemDesign
1
176
Open-sourcing my System Design + Backend Engineering repository
System Design concepts & architecture
Real-world case studies
Java/backend implementations
I'm opening it for developers who want to learn, improve, and contribute
github.com/CyberVerve07/Syst…
Aditya retweeted
Solution of yesterday’s question:
The concept is idempotency.
Play is not “start a stream.”
Play is “claim this listen once.”
A tap is one intent.
A retry is the same intent arriving twice.
If you check Redis then write, two servers can both see “not playing.”
That is a race, not a design.
Do this instead.
1. The client sends an idempotency key
play_id = hash(user_id + track_id + device_id + tap_id)
Same tap, same key.
Retry does not mint a new listen.
2. Claim the listen with one atomic write
SET play:{play_id} 1 NX EX 30
If the set succeeds → this request owns the listen.
If it fails → it is a retry. Serve audio. Do not increment the counter.
No read-then-write.
One command. One winner.
3. Audio and accounting are different paths
Hot track → CDN / edge cache. Origin never sees 5 million file reads.
Listen count → a queue.
Consumer is idempotent on play_id.
Kafka + a unique key on play_id so the royalty row exists once.
Fast path: bytes.
Slow path: money.
Do not couple them.
4. Two devices is a different problem
That is session ownership, not retries.
user:{id}:now_playing stores device_id + position + play_id.
New device steals the session. Old device gets a pause event.
Timestamps follow the session, not the file.
The interview answer in one line
CDN keeps the origin alive.
Idempotency keeps the royalty ledger honest.
Atomic SET NX is how you stop two retries from becoming two streams.
If your Play API can run the same request 10 times and the listen count still moves by 1, you designed it.
If it depends on “the network won’t retry,” you didn’t.
Recently I interviewed a Senior Engineer.
Strong candidate.
Kafka? ✅
Redis? ✅
CDN? ✅
Microservices? ✅
Distributed systems? ✅
Then I asked:
"Design Spotify."
They drew boxes.
Then I made it real.
A new track drops.
5 million people hit Play on the same song in the first minute.
A user taps Play.
The request reaches your playback service.
Audio starts.
Then the network blips.
The app retries Play.
Now you have two play requests for the same user, same track, same second.
Both can hit different servers.
Both can start a stream.
Both can try to record a listen.
Royalties get paid per qualifying stream.
How do you guarantee:
→ playback starts in under 200ms
→ origin servers don’t melt on one hot track
→ the user is not billed two streams for one tap
→ two devices don’t play the same song at two different timestamps
"Just put the file on a CDN."
Doesn’t solve the listen count.
"Use Redis to store now playing."
What happens when two retries check Redis at the same time?
"Check if the user already started this track."
Same race. Two requests. Both see “not playing.” Both write.
Your turn:
How would you design Spotify’s Play API so a retry doesn’t double-count a stream
and a viral track doesn’t take the system down with it?
There’s a specific distributed-systems concept behind this.
And you’ll encounter it anywhere a click must be fast, unique, and expensive if you get it wrong. 👇
Learning SOLID Principles in Java 🚀
S — Single Responsibility
O — Open/Closed
L — Liskov Substitution
I — Interface Segregation
D — Dependency Inversion
Writing code that is easy to maintain, extend, and scale. 💻
#Java #SOLID #Backend #SpringBoot #SoftwareEngineering
1
57
This meme perfectly captures the struggle! 😂 It's all too relatable when your strengths aren't what they're looking for. Who else has felt this pain? 😩😅 #TechLife #DeveloperStruggles
4
4,272
Bhaiya is right! 😅 I just learned a fun fact about the days of the week. Six of them contain the letter 'd'—Sunday, Monday, Tuesday, Wednesday, Thursday, and Friday. Only Saturday misses out! 🗓️📝 #FunFacts
2
73
CM Vijay Thalapathy and Suresh Raina are likely to attend the CSK vs SRH Game at Chepauk Tomorrow..!!
We’re in the Endgame Now 😞
#DCvsRR
1
372



















