In a detailed exploration of building a real-time leaderboard system, the text outlines the integration of Dragonfly, an efficient alternative to Redis, with a SQL database such as PostgreSQL, to handle user scores dynamically and persistently. The system employs Dragonfly's Sorted-Set and Hash data types for real-time data handling, while PostgreSQL maintains a comprehensive score history and supports various leaderboard types: all-time, current-week, and previous weeks. A well-structured database schema, emphasizing normalization, ensures efficient data management and scalability. Materialized views are utilized to capture past weekly leaderboards, and caching strategies in Dragonfly enhance retrieval speed. The approach highlights the importance of key naming conventions, data synchronization, and the calculation of weekly periods to maintain accurate and up-to-date leaderboards, demonstrating the seamless integration of in-memory data handling with traditional databases for responsive user engagement.