A high-concurrency like/thumbs-up system built with modern backend technologies, designed to handle massive traffic with optimized caching strategies and asynchronous processing.
Built with Spring Boot 3 + Redis + Apache Pulsar, this system handles massive traffic for social media-style like operations. It showcases enterprise-level solutions for cache penetration, hot key detection, eventual consistency, and real-time monitoring—capable of processing thousands of concurrent like requests with sub-100ms latency.
Tech Stack: Spring Boot 3 · MyBatis-Plus · Redis · Apache Pulsar · Caffeine · HeavyKeeper
Implements a three-tier cache architecture (Caffeine → Redis → MySQL) with the HeavyKeeper algorithm to automatically identify and cache the top-100 most accessed keys. Only promotes keys to local cache after exceeding 10 accesses, minimizing memory overhead while maintaining cache coherence across all layers.
Event-driven architecture where all write operations are published to Pulsar, decoupling API responses from database writes. Batch consumer processes up to 1,000 messages with intelligent deduplication, applies exponential backoff retry strategies, and routes failed messages to Dead Letter Queue. This approach reduce database writes by batching operations.
Redis Lua scripts provide atomic read-check-write operations for like status, eliminating the need for distributed locks. Scripts validate user state before modifying counters, achieving zero lock contention.
Daily scheduled job (2:00 AM) compares Redis (source of truth) against MySQL using cursor-based scanning (1,000 keys per batch) to detect missing database records. Automatically republishes compensation events to Pulsar for any discrepancies found, with error logging and performance tracking for monitoring.
thumb-backend/
├── src/main/java/com/zxuhan/thumb/
│ ├── config/
│ ├── constant/
│ ├── controller/
│ │ ├── BlogController.java # Blog list/detail with like status
│ │ ├── ThumbController.java # Like/unlike API + Prometheus metrics
│ │ └── UserController.java # Login & session management
│ │
│ ├── job/
│ │ ├── SyncThumb2DBJob.java # Scheduled sync (every 10s)
│ │ ├── SyncThumb2DBCompensatoryJob.java # Cleanup orphaned temp keys (daily 2am)
│ │ └── ThumbReconcileJob.java # Redis↔MySQL reconciliation (daily 2am)
│ │
│ ├── listener/thumb/
│ │ ├── ThumbConsumer.java # Pulsar batch consumer (1000 msgs/batch)
│ │ └── msg/ThumbEvent.java # Event POJO (userId, blogId, type, timestamp)
│ │
│ ├── manager/cache/
│ │ ├── CacheManager.java # Multi-level cache coordinator
│ │ ├── HeavyKeeper.java # Top-K hot key detection (Count-Min-Sketch variant)
│ │ ├── TopK.java # Interface for hot key algorithms
│ │ └── Item.java # (key, count) record
│ │
│ ├── mapper/
│ ├── model/
│ ├── service/impl/
│ │ ├── ThumbServiceImpl.java # Synchronous + local cache only
│ │ ├── ThumbServiceRedisImpl.java # Time-sliced Redis sync
│ │ └── ThumbServiceMQImpl.java # Async Pulsar (production mode)
│ │
│ └── util/
│ └── RedisKeyUtil.java # Key builders (thumb:{userId}, thumb:temp:HH:mm:ss)
│
├── src/main/resources/
└── pom.xml
- JDK 21
- MySQL 8.0+
- Redis 6.0+
- Apache Pulsar 2.10+
- Maven 3.8+
1. Database Initialization
mysql -u root -p thumb_db < src/main/resources/create_table.sql2. Start Redis&Pulsar
# Start Redis
redis-stack-server
# Or if you use Homebrew
brew services start redis
# Start Pulsar
pulsar standalone3. Configuration
Update src/main/resources/application.yml:
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/thumb_db
username: your_username
password: your_password
data:
redis:
database: 0
host: localhost
password: your_redis_password
timeout: 5000
port: 63794. Build&Run
# Clone repository
git clone <your-repo-url>
cd thumb-backend
# Build (skips tests for quick start)
mvn clean package -DskipTests
# Run application
java -jar target/thumb-backend-1.0.0.jar
# Or run in development mode
mvn spring-boot:run5. Access Application
- Application: http://localhost:9199/api
- API Docs: http://localhost:9199/api/doc.html