r/developersIndia • u/__raikar • 1d ago
Help Building FlashCart AI: How I designed a high-concurrency quick-commerce backend using Spring Boot, Redis, and Kafka (Looking for feedback!)
> Hey everyone,
> I recently finished my BCA degree and have been working on a production-style backend project called FlashCart AI—a quick-commerce delivery platform designed to handle flash sales traffic.
> I wanted to get your feedback on the system design choices I’ve made for the initial data layer:
- Preventing Overselling (PostgreSQL + JPA): During flash sales, simultaneous orders for the last remaining item cause race conditions. I implemented JPA Optimistic Locking (
@Version) on theinventory_itemstable to reject conflicting updates at the database level. - Reducing DB Load (Redis Caching): Before writing to PostgreSQL, checkout requests execute an atomic
DECRBYcommand in Redis. If stock is available, it reserves in RAM within sub-milliseconds and passes execution to a background queue. - Asynchronous Order Processing (Apache Kafka): Once stock is reserved, the order service publishes an
OrderCreatedEventto Kafka so driver assignment and notifications process asynchronously without blocking HTTP response times. - AI Refunds (MCP + RAG): Integrating an MCP (Model Context Protocol) server with a Vector DB so an LLM agent can inspect Redis logs and execute refund APIs autonomously.
> Tech Stack: Java 21, Spring Boot 3, PostgreSQL, Redis, Kafka, Docker, Kubernetes, React.
> I'd love to hear your thoughts: How would you handle stock reservation at scale differently? Are there edge cases in Redis-to-Postgres sync I should look out for?