Skip to content

Backend Engineer Take-Home Solutions (Problems 4–6): Go Algorithms, Express API, and Scoreboard System Design#292

Open
linhtutkyawdev wants to merge 15 commits into
99techteam:mainfrom
linhtutkyawdev:main
Open

Backend Engineer Take-Home Solutions (Problems 4–6): Go Algorithms, Express API, and Scoreboard System Design#292
linhtutkyawdev wants to merge 15 commits into
99techteam:mainfrom
linhtutkyawdev:main

Conversation

@linhtutkyawdev

Copy link
Copy Markdown

This PR contains complete solutions for the backend engineering assessment, covering:

  • Problem 4: Three implementations of “sum to N” in Go
  • Problem 5: Task Management API (Express + TypeScript + SQLite)
  • Problem 6: Scoreboard service design (live leaderboard + security model)

Each solution focuses on different aspects of backend engineering: algorithms, API design, persistence, and distributed system thinking.


1. Problem 4 – Sum to N (Golang)

Three distinct approaches are implemented to compute 1..n sum:

Implementations

  • Solution A – Gauss Formula

    • Direct arithmetic formula: n(n+1)/2
    • O(1) time, O(1) space
    • Optimal and production-ready for this problem
  • Solution B – Iterative Loop

    • Simple accumulation from 1..n
    • O(n) time, O(1) space
    • Baseline readable implementation
  • Solution C – Parallel Divide & Conquer

    • Recursive range splitting with controlled goroutines
    • O(n) time, O(p + log n) space
    • Demonstrates concurrency model and workload partitioning

Notes

  • Negative input support handled by normalization
  • Parallel version includes goroutine throttling to avoid overhead explosion
  • Benchmarks included for comparative analysis

2. Problem 5 – Task Management API (Express + TypeScript + SQLite)

A fully functional CRUD backend with persistence and relational structure.

Core Features

  • Task CRUD operations
  • Status updates and lifecycle tracking
  • Tag management (many-to-many relationship)
  • Filtering by status, priority, and tags
  • Task event logging (audit trail)
  • SQLite persistence with foreign key constraints

Architecture

  • Controller → Service → DB separation
  • Parameterized SQL queries (SQL injection safe)
  • Input validation layer
  • Soft delete behavior (with cascade handling for relations)

Database Design

  • tasks – core task data
  • tags – reusable tags
  • task_tags – many-to-many mapping
  • task_events – lifecycle audit log

Notes

  • SQLite database is bundled for assessment simplicity
  • Cascading deletes ensure relational consistency
  • Urgency score is computed at runtime
  • Designed for easy migration to PostgreSQL

3. Problem 6 – Scoreboard Service Design (Live Leaderboard System)

A backend design for a real-time Top 10 scoreboard with secure score updates.

System Overview

  • Users perform actions → backend increments score
  • Live leaderboard updates pushed to clients
  • Strong focus on preventing score manipulation

Architecture

  • API Server (score validation + orchestration)
  • Postgres (source of truth)
  • Redis (leaderboard cache using sorted sets)
  • WebSocket layer (real-time updates)

Score Update Flow

  1. Client performs action

  2. Signed request sent (HMAC-based)

  3. Backend validates:

    • signature validity
    • timestamp window
    • replay protection (actionId uniqueness)
  4. Score update:

    • Postgres update
    • Redis ZSET update
  5. Event broadcast via WebSocket


Security Model

  • HMAC request signing (prevents fake score injection)
  • Replay protection using actionId deduplication
  • Timestamp validation (anti-replay window)
  • Rate limiting per user/IP

Leaderboard Strategy

Redis Sorted Set used for performance:

  • ZINCRBY leaderboard <score> <userId>
  • ZREVRANGE leaderboard 0 9 WITHSCORES

Provides:

  • O(log N) updates
  • Fast Top-K queries
  • DB remains source of truth

Real-Time Updates

  • Score changes emit events
  • WebSocket server pushes updated Top 10 to clients

Added Artifacts

  • README.md for Problem 4 (Go implementations + benchmarks)
  • README.md for Task API (Problem 5)
  • README.md for Scoreboard design (Problem 6)
  • API_SPECIFICATION.md (bonus design detail)
  • PROJECT_PLAN.md (bonus planning breakdown)
  • Postman collection (Task API testing)

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