Optimizing API Performance with Elasticsearch and Redis

6 months ago, I couldn't explain why my API was slow. I just knew it was — and that feeling bothered me. So I did what most people don't: I stopped copy-pasting Stack Overflow fixes and started understanding the architecture underneath. --- Last week, I built a Spring Boot project from scratch. One goal: take a 500ms search API and bring it under 100ms. No shortcuts. No magic libraries. Just engineering decisions — each one explained with comments in the code. Here's what I learned: → Your DB was never built for search. Move it to Elasticsearch. → 80% of users search the same 20 queries. Cache them in Redis. Serve in 5ms. → "Trending products" shouldn't be computed on every request. Precompute it every 5 min in the background. Serve instantly. → Don't fetch 10,000 results and sort in Java. Let the index return the top 20. Always. → Writes blocking reads is a design flaw, not a hardware problem. @Async fixes it. Slow path (DB LIKE query): ~500ms ❌ Elasticsearch, first call: ~30ms ✅ Elasticsearch, second call (Redis hit): ~5ms 🚀 Precomputed trending: ~2ms 🔥 --- But honestly? The code isn't even the most important part. What changed for me was learning to ask "why is this slow" instead of "how do I make it faster." Those are completely different questions. One leads to patches. The other leads to architecture. --- I'm a Backend Engineer with 1.5 years of experience — working with Java 17, Spring Boot 3, Kafka, Redis, Elasticsearch, AWS EKS, and Kubernetes. I build things end-to-end, document them properly, and genuinely care about how systems work under the hood. I'm currently open to new opportunities — backend roles. If you're building something interesting, or know someone who is — I'd love a conversation. DM me. Let's talk. 🤝 --- 🔗 Full source code (Spring Boot 3 + Java 17 + Redis + Elasticsearch + Docker) — Github : https://lnkd.in/dxJFCqtb Every file is commented to explain the "why", not just the "how". Do give it a star if you learned something new !! #OpenToWork #BackendEngineering #Java #SpringBoot #SystemDesign #Redis #Elasticsearch #Kafka #SoftwareEngineering #HiringEngineers

To view or add a comment, sign in

Explore content categories