Skip to content

[BE] - Nguyen Chi Thuc#293

Open
chithuchcmus wants to merge 2 commits into
99techteam:mainfrom
chithuchcmus:main
Open

[BE] - Nguyen Chi Thuc#293
chithuchcmus wants to merge 2 commits into
99techteam:mainfrom
chithuchcmus:main

Conversation

@chithuchcmus

@chithuchcmus chithuchcmus commented Jul 5, 2026

Copy link
Copy Markdown

Description

This PR adds solutions for three coding challenge problems, covering algorithmic implementation, REST API development, and system design.


Problem 4: Sum to N (TypeScript)

Three unique implementations of a sum_to_n function that computes the summation from 1 to n for any integer input.

Approach Time Complexity Space Complexity
Iterative (for loop) O(n) O(1)
Recursive (trampoline) O(n) O(1)
Mathematical (Gauss's formula with BigInt) O(1) O(1)
  • Supports positive, zero, and negative integers
  • Trampoline-based recursion avoids stack overflow for large inputs
  • BigInt used in formula approach to prevent intermediate overflow
  • 21 test cases covering edge cases and large numbers

Problem 5: Product CRUD REST API

A production-ready RESTful API for managing products, built with Express.js, TypeScript, and PostgreSQL.

Features:

  • Full CRUD: Create, Read (with filters), Update (partial), Delete (soft delete)
  • Layered architecture: Router → Middleware → Controller → Service → Repository
  • Zod validation with centralized middleware
  • Dependency injection with interfaces (IProductService, IProductRepository)
  • Docker + Docker Compose setup (app + PostgreSQL)
  • pino logging with request ID correlation
  • Graceful shutdown handling
  • Pagination with separate COUNT query for performance
  • Optimized PostgreSQL indexes (partial indexes, trigram search)

API Endpoints:

  • POST /v1/products — Create product
  • GET /v1/products — List with filters (category, price range, search, pagination)
  • GET /v1/products/:id — Get by ID
  • PATCH /v1/products/:id — Partial update
  • DELETE /v1/products/:id — Soft delete

Testing: Unit tests (service layer with mocked repo) + integration tests (controller layer with Supertest)


Problem 6: Real-Time Leaderboard System Design

A comprehensive system design document for a real-time leaderboard service supporting 1M MAU, 10K TPS, and sub-100ms query latency.

Documents included:

  • SYSTEM_DESIGN.md — Complete architecture, data models, API specs, and design decisions
  • SEQUENCES.md — 7 Mermaid sequence diagrams for key flows
  • SERVICES.md — Microservices overview and scaling strategy

Architecture (3 microservices):

  1. Score Update Service — Validates actions, publishes to Kafka (202 Accepted)
  2. Event Processor Service — Consumes Kafka events, updates Redis + ClickHouse
  3. Leaderboard Service — Serves queries (HTTP) and live updates (SSE)

Key design decisions:

  • Kafka for durable event streaming with replay capability
  • Redis Sorted Sets for sub-5ms leaderboard queries
  • ClickHouse for long-term analytics with materialized views
  • SSE with selective broadcasting (90% bandwidth reduction)
  • Horizontal scaling with Redis pub/sub fan-out

Future optimizations documented: Event batching, priority-based tiers, distributed tracing, graceful degradation

chithuchcmus added 2 commits July 5, 2026 11:05
- (problem4): add sum_to_n TypeScript solution with tests
- (problem5): add product CRUD REST API with Express, Docker, and tests
- (problem6): add system design documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant