How fernandobrandan/center-redis works
Project type and purpose
• This is a single microservice (Payment/Inventory Service) written in TypeScript/Node.js.
• Its purpose is to act as a distributed cache layer (cache-aside pattern) in front of a MySQL database, accelerate API responses via Redis (hashes, locks, pipelines), and handle atomic inventory purchase operations with optimistic locking and an event-driven queue.
File structure
• src/
• app.ts & index.ts: Bootstrap the Express (or equivalent) server and wire up middleware.
• config/: Configuration modules for MySQL (db_mysql.ts) and Redis (db_redis.ts).
• routes/route.ts: Defines HTTP endpoints (/api/items, /api/populate, /api/purchase).
• controllers/: Implements three core flows – getData.ts (read-through cache), normalizationData.ts (populate/cache-fill), controller.ts (common logic).
• Top-level Dockerfile & .env: Containerization and environment variables.
• package.json & tsconfig.json: Node build and compile setup.
README for architectural insights
• Core flows:
a. GET /api/items → Cache-Aside (HSET + EXPIRE).
b. POST /api/populate → Pipeline to batch-write cache after standardizing data.
c. POST /api/purchase → Optimistic locking (SET lock:item_id UUID), DB validation, atomic MULTI/EXEC, asynchronous queue for stock updates.
• Technologies: Redis (7+), MySQL, TypeScript/Node.js, Event-Driven via Redis List or Stream.
• Non-functional: High concurrency (>1k RPS), <5 ms cache latency, horizontal sharding support.