{"id":30287,"date":"2025-11-07T11:24:54","date_gmt":"2025-11-07T19:24:54","guid":{"rendered":"https:\/\/www.pingcap.com\/?p=30287"},"modified":"2025-11-07T11:25:45","modified_gmt":"2025-11-07T19:25:45","slug":"supercharging-real-time-applications-tidb-dragonflydb","status":"publish","type":"post","link":"https:\/\/www.pingcap.com\/ko\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/","title":{"rendered":"Supercharging Real-Time Applications with TiDB and DragonflyDB"},"content":{"rendered":"<p>Data-intensive applications demand scalability, <a href=\"https:\/\/www.pingcap.com\/ko\/tidb-cloud-serverless-vs-amazon-rds\/?utm_source=google&amp;utm_medium=cpc&amp;utm_campaign=plg_search_RDScompare_blog_01&amp;utm_term=tidb%20cloud&amp;utm_campaign=plg_search_RDScompare_blog_01&amp;utm_source=adwords&amp;utm_medium=ppc&amp;hsa_acc=7438219570&amp;hsa_cam=21762816921&amp;hsa_grp=165117033501&amp;hsa_ad=715506387577&amp;hsa_src=g&amp;hsa_tgt=kwd-2397205853419&amp;hsa_kw=tidb%20cloud&amp;hsa_mt=p&amp;hsa_net=adwords&amp;hsa_ver=3&amp;gad_source=1&amp;gad_campaignid=21762816921&amp;gbraid=0AAAAABXQRYAA9jo2CvLhV9bdQf0Wj0ZLz&amp;gclid=CjwKCAiAzrbIBhA3EiwAUBaUdSDAnuRA075XpRogrHCfYj9KtRYBLSi7nnzXhzGnQ0QUiUyH9p1gFRoCvbcQAvD_BwE\">low latency<\/a>, \uadf8\ub9ac\uace0 <a href=\"https:\/\/www.pingcap.com\/ko\/article\/ensuring-99-99-uptime-with-tidbs-resilient-architecture\/\">resilience<\/a>. However, traditional databases often struggle to handle both transactional consistency and fast in-memory caching at scale. But that\u2019s where TiDB and DragonflyDB shine together:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><a href=\"https:\/\/www.pingcap.com\/ko\/tidb\/\">\ud2f0DB<\/a><\/strong> : a distributed, MySQL-compatible database designed for massive scalability and mixed workload processing.<\/li>\n\n\n\n<li><strong><a href=\"https:\/\/www.dragonflydb.io\">DragonflyDB<\/a><\/strong>: a modern, Redis compatible in-memory data store that delivers sub-millisecond caching and queuing performance with much better efficiency than Redis.<\/li>\n<\/ul>\n\n\n\n<p>In this tutorial, we\u2019ll walk through setting up a TiDB + Dragonfly stack, show how they complement each other, and build a hands-on example for a real-time leaderboard system.<\/p>\n\n\n\n<p>TiDB gives you the scale and consistency of a <a href=\"https:\/\/www.pingcap.com\/ko\/blog\/why-distributed-sql-databases-elevate-modern-app-dev\/\">distributed SQL database<\/a>, while DragonflyDB delivers blazing-fast, Redis-compatible caching. Together, they power real-time use cases like leaderboards, payments, and feeds.<\/p>\n\n\n\n<p>Think of TiDB as your engine and DragonflyDB as your turbocharger.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_TiDB_DragonflyDB\"><\/span>Why TiDB + DragonflyDB?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Both TiDB (like MySQL) and DragonflyDB are multi-threaded by design. This is critical for data-intensive workloads.<\/p>\n\n\n\n<p>TiDB\u2019s architecture distributes queries and transactions across multiple nodes and threads for parallel execution.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>TiDB Strengths: <\/strong>Horizontal scalability, <a href=\"https:\/\/www.pingcap.com\/ko\/blog\/distributed-transactions-tidb\/\">strong consistency<\/a>, mixed workload processing.<\/li>\n<\/ul>\n\n\n\n<p>On the other hand, DragonflyDB can fully utilize multi-core CPUs, unlike Redis which is single-threaded by default. This means DragonflyDB can handle far more throughput per instance with the same hardware.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>DragonflyDB Strengths: <\/strong>Lightning-fast cache, Redis drop-in replacement, multi-threaded scalability. DragonflyDB is also horizontally scalable with Dragonfly Swarm, a multi-node clustering solution.<\/li>\n<\/ul>\n\n\n\n<p>Together, TiDB serves as the durable source of truth, while DragonflyDB accelerates reads, queues, and ephemeral data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"DragonflyDB_Drop-In_Redis_Replacement\"><\/span>DragonflyDB: Drop-In Redis Replacement<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>DragonflyDB is 100% Redis-compatible. Migrating from Redis usually just requires changing the endpoint in your application code \u2014 no rewrites needed. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Before: using Redis\nr = redis.Redis(host=\"redis-host\", port=6379)\n\n# After: using Dragonfly\nr = redis.Redis(host=\"dragonfly-host\", port=6379)<\/code><\/pre>\n\n\n\n<p>That\u2019s it. Your Redis commands will just work, but with significantly better performance and efficiency.<\/p>\n\n\n\n<p>Next, we&#8217;ll walk you through how to get started running TiDB and DragronflyDB together in Docker.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_1_Setting_Up_with_Colima_Install_Colima_Docker_CLI\"><\/span><strong>Step 1. Setting Up with Colima: Install Colima + Docker CLI<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>brew install colima docker docker-compose\ncolima start --cpu 4 --memory 8 --disk 20\ndocker context use colima<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_2_Run_TiDB\"><\/span>Step 2. Run TiDB<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If you don\u2019t already have a TiDB cluster, the easiest path is <a href=\"https:\/\/tidbcloud.com\/free-trial\/\">TiDB Cloud \uc2a4\ud0c0\ud130<\/a>.<br>You can also run it locally with Docker:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d --name tidb -p 4000:4000 pingcap\/tidb:latest<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_3_Run_DragonflyDB\"><\/span>Step 3. Run DragonflyDB<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>DragonflyDB runs easily in Docker as well:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d --name dragonfly -p 6379:6379 docker.dragonflydb.io\/dragonflydb\/dragonfly<\/code><\/pre>\n\n\n\n<p>Now you have a Redis-compatible cache at port 6379.<\/p>\n\n\n\n<p>At this point, both TiDB and Dragonfly should be running inside Colima. Let\u2019s confirm:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker ps<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"83\" src=\"https:\/\/static.pingcap.com\/files\/2025\/11\/07084331\/image-6-1024x83.png\" alt=\"Both TiDB and Dragonfly are running inside Docker \u2014 TiDB on port 4000, Dragonfly on port 6379.\" class=\"wp-image-30322\" srcset=\"https:\/\/static.pingcap.com\/files\/2025\/11\/07084331\/image-6-1024x83.png 1024w, https:\/\/static.pingcap.com\/files\/2025\/11\/07084331\/image-6-300x24.png 300w, https:\/\/static.pingcap.com\/files\/2025\/11\/07084331\/image-6-768x62.png 768w, https:\/\/static.pingcap.com\/files\/2025\/11\/07084331\/image-6.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"><em>Both TiDB and Dragonfly are running inside Docker \u2014 TiDB on port 4000, DragonflyDB on port 6379.<\/em><\/figcaption><\/figure>\n<\/div>\n\n\n<p>Next, confirm TiDB &amp; DragonflyDB are both reachable:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -h 127.0.0.1 -P 4000 -uroot -e \"SELECT VERSION();\"\nredis-cli -h 127.0.0.1 -p 6379 PING<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"405\" src=\"https:\/\/static.pingcap.com\/files\/2025\/11\/07084434\/image-7-1024x405.png\" alt=\"Quick health check: TiDB responds with version 8.0.11-TiDB-v7.5.1 and Dragonfly returns PONG, confirming both services are ready.\" class=\"wp-image-30323\" srcset=\"https:\/\/static.pingcap.com\/files\/2025\/11\/07084434\/image-7-1024x405.png 1024w, https:\/\/static.pingcap.com\/files\/2025\/11\/07084434\/image-7-300x119.png 300w, https:\/\/static.pingcap.com\/files\/2025\/11\/07084434\/image-7-768x304.png 768w, https:\/\/static.pingcap.com\/files\/2025\/11\/07084434\/image-7.png 1026w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"><em>Quick health check: TiDB responds with version 8.0.11-TiDB-v7.5.1 and DragonflyDB returns PONG, confirming both services are ready.<\/em><\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_4_Create_Schema_in_TiDB\"><\/span>Step 4. Create Schema in TiDB<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let\u2019s create a durable leaderboard table in TiDB.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE game;\nUSE game;\n\nCREATE TABLE leaderboard (\n&nbsp; user_id BIGINT PRIMARY KEY,\n&nbsp; username VARCHAR(50),\n&nbsp; score INT,\n&nbsp; updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\n);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_5_Building_a_Read-Through_Leaderboard_with_Python_Example\"><\/span>Step 5. Building a Read-Through Leaderboard with Python (Example)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You&#8217;ll need to set up a Virtual Environment (PEP 668 safe). On macOS\/Linux, don\u2019t install Python libraries globally. Instead:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python3 -m venv venv\nsource venv\/bin\/activate<\/code><\/pre>\n\n\n\n<p>You\u2019ll see (venv) in your shell prompt. Now install dependencies:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install mysql-connector-python redis<\/code><\/pre>\n\n\n\n<p><strong>Python Demo Code (Read-Through Cache)<\/strong><\/p>\n\n\n\n<p>Here\u2019s the heart of our demo: a read-through cache pattern in Python.<\/p>\n\n\n\n<p>Save as leaderboard_demo.py:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># leaderboard_demo.py\nimport mysql.connector\nimport redis\nfrom datetime import datetime, timedelta\n\n# --- Connections ---\ndb = mysql.connector.connect(\n&nbsp; host=\"127.0.0.1\", port=4000, user=\"root\", password=\"\", database=\"game\"\n)\ncursor = db.cursor(dictionary=True)&nbsp; # dict rows for convenience\nr = redis.Redis(host=\"127.0.0.1\", port=6379)\n\nCACHE_TTL_SECONDS = 300&nbsp; # 5m; tune for your app\n\ndef _lb_key(period: str | None = None) -&gt; str:\n&nbsp; # Examples: leaderboard:alltime, leaderboard:2025-09\n&nbsp; if period in (None, \"alltime\"):\n&nbsp; &nbsp; &nbsp; return \"leaderboard:alltime\"\n&nbsp; return f\"leaderboard:{period}\"\n\ndef add_score(user_id: int, username: str, score: int):\n&nbsp; # Write-through: TiDB first (source of truth)\n&nbsp; cursor.execute(\n&nbsp; &nbsp; &nbsp; \"INSERT INTO leaderboard (user_id, username, score) VALUES (%s,%s,%s) \"\n&nbsp; &nbsp; &nbsp; \"ON DUPLICATE KEY UPDATE username=VALUES(username), score=VALUES(score)\",\n&nbsp; &nbsp; &nbsp; (user_id, username, score),\n&nbsp; )\n&nbsp; db.commit()\n\n&nbsp; # Then update Dragonfly cache(s). For simplicity we update all-time only here.\n&nbsp; r.zadd(_lb_key(\"alltime\"), {username: score})\n&nbsp; r.expire(_lb_key(\"alltime\"), CACHE_TTL_SECONDS)\n\ndef get_top_players(n: int = 10, period: str | None = \"alltime\"):\n&nbsp; \"\"\"\n&nbsp; Read-through: try Dragonfly; on miss, query TiDB, rehydrate Dragonfly, return data.\n&nbsp; period:\n&nbsp; &nbsp; - \"alltime\" (default)\n&nbsp; &nbsp; - \"YYYY-MM\" for monthly boards (e.g., \"2025-09\")\n&nbsp; \"\"\"\n&nbsp; key = _lb_key(period)\n&nbsp; results = r.zrevrange(key, 0, n - 1, withscores=True)\n\n&nbsp; if results:&nbsp; # cache hit\n&nbsp; &nbsp; &nbsp; return results\n\n&nbsp; # --- Cache miss: rebuild from TiDB ---\n&nbsp; if period in (None, \"alltime\"):\n&nbsp; &nbsp; &nbsp; sql = (\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \"SELECT username, score FROM leaderboard \"\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \"ORDER BY score DESC LIMIT %s\"\n&nbsp; &nbsp; &nbsp; )\n&nbsp; &nbsp; &nbsp; params = (n,)\n&nbsp; else:\n&nbsp; &nbsp; &nbsp; # Monthly board using updated_at; adjust to your business rule\n&nbsp; &nbsp; &nbsp; start = datetime.strptime(period, \"%Y-%m\")\n&nbsp; &nbsp; &nbsp; end = (start.replace(day=28) + timedelta(days=4)).replace(day=1)\n&nbsp; &nbsp; &nbsp; sql = (\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \"SELECT username, score FROM leaderboard \"\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \"WHERE updated_at &gt;= %s AND updated_at &lt; %s \"\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \"ORDER BY score DESC LIMIT %s\"\n&nbsp; &nbsp; &nbsp; )\n&nbsp; &nbsp; &nbsp; params = (start, end, n)\n\n&nbsp; cursor.execute(sql, params)\n&nbsp; rows = cursor.fetchall()\n\n&nbsp; # Rehydrate Dragonfly (pipeline for speed)\n&nbsp; pipe = r.pipeline()\n&nbsp; pipe.delete(key)\n&nbsp; for row in rows:\n&nbsp; &nbsp; &nbsp; pipe.zadd(key, {row&#91;\"username\"]: int(row&#91;\"score\"])})\n&nbsp; pipe.expire(key, CACHE_TTL_SECONDS)\n&nbsp; pipe.execute()\n\n&nbsp; # Return in the same shape as ZREVRANGE ... WITHSCORES\n&nbsp; return &#91;(row&#91;\"username\"].encode(\"utf-8\"), float(row&#91;\"score\"])) for row in rows]\n\n# --- demo ---\nif __name__ == \"__main__\":\n&nbsp; add_score(1, \"Alice\", 1500)\n&nbsp; add_score(2, \"Bob\", 2000)\n&nbsp; print(\"Top Players (all-time):\", get_top_players())<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>get_top_players() implements a read-through cache. It calls ZREVRANGE; if the list is empty (key missing\/expired), it queries TiDB, rehydrates DragonflyDB with ZADD, sets a short TTL, and returns the results.<\/li>\n\n\n\n<li><em>Why it matters:<\/em> This shows TiDB on both the write path and the read path while keeping hot reads sub-ms from DragonflyDB.<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"559\" src=\"https:\/\/static.pingcap.com\/files\/2025\/11\/07084535\/image-8-1024x559.png\" alt=\"Setting up a Python virtual environment, installing dependencies (mysql-connector-python and redis), and running the leaderboard_demo.py script \u2014 showing Bob and Alice ranked in the DragonflyDB leaderboard.\" class=\"wp-image-30324\" srcset=\"https:\/\/static.pingcap.com\/files\/2025\/11\/07084535\/image-8-1024x559.png 1024w, https:\/\/static.pingcap.com\/files\/2025\/11\/07084535\/image-8-300x164.png 300w, https:\/\/static.pingcap.com\/files\/2025\/11\/07084535\/image-8-768x419.png 768w, https:\/\/static.pingcap.com\/files\/2025\/11\/07084535\/image-8.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"><em>Setting up a Python virtual environment, installing dependencies (mysql-connector-python and redis), and running the leaderboard_demo.py script, showing Bob and Alice ranked in the Dragonfly leaderboard.<\/em><\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Monthly_Leaderboards_Period-Based_Queries\"><\/span>Monthly Leaderboards (Period-Based Queries)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Use period=&#8221;YYYY-MM&#8221; to fetch a monthly leaderboard using the updated_at column. Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python -c 'from leaderboard_demo import get_top_players; print(get_top_players(10, period=\"2025-09\"))'<\/code><\/pre>\n\n\n\n<p>This function computes the month window and rebuilds the cache on a miss.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_6_Testing_Cache_Miss_Rehydration\"><\/span>Step 6. Testing Cache Miss &amp; Rehydration:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Next, delete the cache key to start clean:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>redis-cli -h 127.0.0.1 -p 6379 DEL leaderboard:2025-09\nredis-cli -h 127.0.0.1 -p 6379 CONFIG RESETSTAT<\/code><\/pre>\n\n\n\n<p>First read -&gt; miss + rebuild from TiDB (filtered by updated_at month window):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python -c 'from leaderboard_demo import get_top_players; print(get_top_players(10, period=\"2025-09\"))'<\/code><\/pre>\n\n\n\n<p>Check stats (expect a miss):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>redis-cli -h 127.0.0.1 -p 6379 INFO stats | egrep \"keyspace_hits|keyspace_misses\"<\/code><\/pre>\n\n\n\n<p>Second read -&gt; hit:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python -c 'from leaderboard_demo import get_top_players; print(get_top_players(10, period=\"2025-09\"))'<\/code><\/pre>\n\n\n\n<p>Check stats again (hits should increase):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>redis-cli -h 127.0.0.1 -p 6379 INFO stats | egrep \"keyspace_hits|keyspace_misses\"<\/code><\/pre>\n\n\n\n<p>See the month key content:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>redis-cli -h 127.0.0.1 -p 6379 ZREVRANGE leaderboard:2025-09 0 9 WITHSCORES<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/static.pingcap.com\/files\/2025\/11\/07084622\/image-9-1024x768.png\" alt=\"Cache miss and rehydration followed by a cache hit: the first get_top_players() call triggers a miss (keyspace_misses:1), repopulates Dragonfly from TiDB, and the second call immediately returns from cache (keyspace_hits:1).\" class=\"wp-image-30325\" srcset=\"https:\/\/static.pingcap.com\/files\/2025\/11\/07084622\/image-9-1024x768.png 1024w, https:\/\/static.pingcap.com\/files\/2025\/11\/07084622\/image-9-300x225.png 300w, https:\/\/static.pingcap.com\/files\/2025\/11\/07084622\/image-9-768x576.png 768w, https:\/\/static.pingcap.com\/files\/2025\/11\/07084622\/image-9.png 1120w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\"><em>Cache miss and rehydration followed by a cache hit: the first get_top_players() call triggers a miss (keyspace_misses:1), repopulates DragonflyDB from TiDB, and the second call immediately returns from cache (keyspace_hits:1).<\/em><\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Production_Notes\"><\/span>Production Notes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>TTL &amp; freshness: Tune CACHE_TTL_SECONDS per workload; add jitter (\u00b120%) to avoid thundering herds.<\/li>\n\n\n\n<li>Cache stampede control: Use lightweight locks (SETNX \/ SET lock:key token NX EX 10) so only one process rebuilds on expiry.<\/li>\n\n\n\n<li>Indexes: Add INDEX(updated_at) in TiDB if you\u2019ll query monthly leaderboards often.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>By combining TiDB\u2019s distributed, multi-threaded architecture with DragonflyDB\u2019s drop-in Redis replacement and multi-threaded caching engine, you get the best of both worlds:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Strong durability, MySQL compatibility, and scalable analytics with TiDB.<\/li>\n\n\n\n<li>Ultra-fast cache, queues, and leaderboards with DragonflyDB without rewriting Redis code.<\/li>\n<\/ul>\n\n\n\n<p>This architecture fits perfectly for <a href=\"https:\/\/www.pingcap.com\/ko\/article\/enhancing-gaming-with-real-time-data-using-tidb\/\">gaming<\/a>, <a href=\"https:\/\/www.pingcap.com\/ko\/solutions\/fintech\/\">fintech<\/a>, <a href=\"https:\/\/www.pingcap.com\/ko\/article\/optimizing-ad-tech-with-high-performance-databases\/\">ad tech<\/a>, \uadf8\ub9ac\uace0 <a href=\"https:\/\/www.pingcap.com\/ko\/article\/graph-databases-transforming-social-networks-with-tidb\/\">social apps<\/a> where speed and reliability matter equally.<\/p>\n\n\n\n<p>If you\u2019re building apps that need to scale without compromise, try pairing TiDB and DragonflyDB. It\u2019s like giving your database rocket fuel.<\/p>\n\n\n\n<p>You can also check out more free, hands-on tutorials by heading over to <a href=\"https:\/\/labs.tidb.io\/\">TiDB Labs<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Data-intensive applications demand scalability, low latency, and resilience. However, traditional databases often struggle to handle both transactional consistency and fast in-memory caching at scale. But that\u2019s where TiDB and DragonflyDB shine together: In this tutorial, we\u2019ll walk through setting up a TiDB + Dragonfly stack, show how they complement each other, and build a hands-on [&hellip;]<\/p>\n","protected":false},"author":323,"featured_media":30337,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ub_ctt_via":"","footnotes":""},"categories":[436],"tags":[147,437,230,11,111],"class_list":["post-30287","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorial","tag-distributed-sql","tag-dragonflydb","tag-mysql-compatibility","tag-real-time-analytics","tag-tidb"],"acf":[],"featured_image_src":"https:\/\/static.pingcap.com\/files\/2025\/11\/07104614\/tidb_feature_1800x600-1-1.png","author_info":{"display_name":"Ben Sherrill","author_link":"https:\/\/www.pingcap.com\/ko\/blog\/author\/bsherrill\/"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>DragonflyDB and TiDB: Supercharging Real-Time Applications<\/title>\n<meta name=\"description\" content=\"Learn how to build fast, scalable real-time applications using TiDB for durable, distributed SQL storage and DragonflyDB for sub-ms caching.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pingcap.com\/ko\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"DragonflyDB and TiDB: Supercharging Real-Time Applications\" \/>\n<meta property=\"og:description\" content=\"Learn how to build fast, scalable real-time applications using TiDB for durable, distributed SQL storage and DragonflyDB for sub-ms caching.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pingcap.com\/ko\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/\" \/>\n<meta property=\"og:site_name\" content=\"TiDB\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/pingcap2015\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-07T19:24:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-07T19:25:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/static.pingcap.com\/files\/2025\/11\/07104637\/tidb_1200x627-2-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1254\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Ben Sherrill\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/static.pingcap.com\/files\/2025\/11\/07104652\/tidb_twitter_1600x900-3-1.png\" \/>\n<meta name=\"twitter:creator\" content=\"@PingCAP\" \/>\n<meta name=\"twitter:site\" content=\"@PingCAP\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ben Sherrill\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/\"},\"author\":{\"name\":\"Ben Sherrill\",\"@id\":\"https:\/\/www.pingcap.com\/#\/schema\/person\/147c81795fb60c74d7419c6d8e442378\"},\"headline\":\"Supercharging Real-Time Applications with TiDB and DragonflyDB\",\"datePublished\":\"2025-11-07T19:24:54+00:00\",\"dateModified\":\"2025-11-07T19:25:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/\"},\"wordCount\":847,\"publisher\":{\"@id\":\"https:\/\/www.pingcap.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/static.pingcap.com\/files\/2025\/11\/07104614\/tidb_feature_1800x600-1-1.png\",\"keywords\":[\"Distributed SQL\",\"DragonflyDB\",\"MySQL Compatibility\",\"Real-time analytics\",\"TiDB\"],\"articleSection\":[\"Tutorial\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/\",\"url\":\"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/\",\"name\":\"DragonflyDB and TiDB: Supercharging Real-Time Applications\",\"isPartOf\":{\"@id\":\"https:\/\/www.pingcap.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/static.pingcap.com\/files\/2025\/11\/07104614\/tidb_feature_1800x600-1-1.png\",\"datePublished\":\"2025-11-07T19:24:54+00:00\",\"dateModified\":\"2025-11-07T19:25:45+00:00\",\"description\":\"Learn how to build fast, scalable real-time applications using TiDB for durable, distributed SQL storage and DragonflyDB for sub-ms caching.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/#primaryimage\",\"url\":\"https:\/\/static.pingcap.com\/files\/2025\/11\/07104614\/tidb_feature_1800x600-1-1.png\",\"contentUrl\":\"https:\/\/static.pingcap.com\/files\/2025\/11\/07104614\/tidb_feature_1800x600-1-1.png\",\"width\":3600,\"height\":1200},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pingcap.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Supercharging Real-Time Applications with TiDB and DragonflyDB\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pingcap.com\/#website\",\"url\":\"https:\/\/www.pingcap.com\/\",\"name\":\"TiDB\",\"description\":\"TiDB | SQL at Scale\",\"publisher\":{\"@id\":\"https:\/\/www.pingcap.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pingcap.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pingcap.com\/#organization\",\"name\":\"PingCAP\",\"url\":\"https:\/\/www.pingcap.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/www.pingcap.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/static.pingcap.com\/files\/2021\/11\/pingcap-logo.png\",\"contentUrl\":\"https:\/\/static.pingcap.com\/files\/2021\/11\/pingcap-logo.png\",\"width\":811,\"height\":232,\"caption\":\"PingCAP\"},\"image\":{\"@id\":\"https:\/\/www.pingcap.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/facebook.com\/pingcap2015\",\"https:\/\/x.com\/PingCAP\",\"https:\/\/linkedin.com\/company\/pingcap\",\"https:\/\/youtube.com\/channel\/UCuq4puT32DzHKT5rU1IZpIA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pingcap.com\/#\/schema\/person\/147c81795fb60c74d7419c6d8e442378\",\"name\":\"Ben Sherrill\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/www.pingcap.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/static.pingcap.com\/files\/2022\/10\/17234942\/avatar.jpg\",\"contentUrl\":\"https:\/\/static.pingcap.com\/files\/2022\/10\/17234942\/avatar.jpg\",\"caption\":\"Ben Sherrill\"},\"description\":\"Senior Solutions Engineer\",\"url\":\"https:\/\/www.pingcap.com\/ko\/blog\/author\/bsherrill\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"DragonflyDB and TiDB: Supercharging Real-Time Applications","description":"Learn how to build fast, scalable real-time applications using TiDB for durable, distributed SQL storage and DragonflyDB for sub-ms caching.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pingcap.com\/ko\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/","og_locale":"ko_KR","og_type":"article","og_title":"DragonflyDB and TiDB: Supercharging Real-Time Applications","og_description":"Learn how to build fast, scalable real-time applications using TiDB for durable, distributed SQL storage and DragonflyDB for sub-ms caching.","og_url":"https:\/\/www.pingcap.com\/ko\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/","og_site_name":"TiDB","article_publisher":"https:\/\/facebook.com\/pingcap2015","article_published_time":"2025-11-07T19:24:54+00:00","article_modified_time":"2025-11-07T19:25:45+00:00","og_image":[{"width":2400,"height":1254,"url":"https:\/\/static.pingcap.com\/files\/2025\/11\/07104637\/tidb_1200x627-2-1.png","type":"image\/png"}],"author":"Ben Sherrill","twitter_card":"summary_large_image","twitter_image":"https:\/\/static.pingcap.com\/files\/2025\/11\/07104652\/tidb_twitter_1600x900-3-1.png","twitter_creator":"@PingCAP","twitter_site":"@PingCAP","twitter_misc":{"Written by":"Ben Sherrill","Est. reading time":"7\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/#article","isPartOf":{"@id":"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/"},"author":{"name":"Ben Sherrill","@id":"https:\/\/www.pingcap.com\/#\/schema\/person\/147c81795fb60c74d7419c6d8e442378"},"headline":"Supercharging Real-Time Applications with TiDB and DragonflyDB","datePublished":"2025-11-07T19:24:54+00:00","dateModified":"2025-11-07T19:25:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/"},"wordCount":847,"publisher":{"@id":"https:\/\/www.pingcap.com\/#organization"},"image":{"@id":"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/#primaryimage"},"thumbnailUrl":"https:\/\/static.pingcap.com\/files\/2025\/11\/07104614\/tidb_feature_1800x600-1-1.png","keywords":["Distributed SQL","DragonflyDB","MySQL Compatibility","Real-time analytics","TiDB"],"articleSection":["Tutorial"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/","url":"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/","name":"DragonflyDB and TiDB: Supercharging Real-Time Applications","isPartOf":{"@id":"https:\/\/www.pingcap.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/#primaryimage"},"image":{"@id":"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/#primaryimage"},"thumbnailUrl":"https:\/\/static.pingcap.com\/files\/2025\/11\/07104614\/tidb_feature_1800x600-1-1.png","datePublished":"2025-11-07T19:24:54+00:00","dateModified":"2025-11-07T19:25:45+00:00","description":"Learn how to build fast, scalable real-time applications using TiDB for durable, distributed SQL storage and DragonflyDB for sub-ms caching.","breadcrumb":{"@id":"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/"]}]},{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/#primaryimage","url":"https:\/\/static.pingcap.com\/files\/2025\/11\/07104614\/tidb_feature_1800x600-1-1.png","contentUrl":"https:\/\/static.pingcap.com\/files\/2025\/11\/07104614\/tidb_feature_1800x600-1-1.png","width":3600,"height":1200},{"@type":"BreadcrumbList","@id":"https:\/\/www.pingcap.com\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pingcap.com\/"},{"@type":"ListItem","position":2,"name":"Supercharging Real-Time Applications with TiDB and DragonflyDB"}]},{"@type":"WebSite","@id":"https:\/\/www.pingcap.com\/#website","url":"https:\/\/www.pingcap.com\/","name":"\ud2f0DB","description":"TiDB | SQL at Scale","publisher":{"@id":"https:\/\/www.pingcap.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pingcap.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/www.pingcap.com\/#organization","name":"PingCAP","url":"https:\/\/www.pingcap.com\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/www.pingcap.com\/#\/schema\/logo\/image\/","url":"https:\/\/static.pingcap.com\/files\/2021\/11\/pingcap-logo.png","contentUrl":"https:\/\/static.pingcap.com\/files\/2021\/11\/pingcap-logo.png","width":811,"height":232,"caption":"PingCAP"},"image":{"@id":"https:\/\/www.pingcap.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/facebook.com\/pingcap2015","https:\/\/x.com\/PingCAP","https:\/\/linkedin.com\/company\/pingcap","https:\/\/youtube.com\/channel\/UCuq4puT32DzHKT5rU1IZpIA"]},{"@type":"Person","@id":"https:\/\/www.pingcap.com\/#\/schema\/person\/147c81795fb60c74d7419c6d8e442378","name":"Ben Sherrill","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/www.pingcap.com\/#\/schema\/person\/image\/","url":"https:\/\/static.pingcap.com\/files\/2022\/10\/17234942\/avatar.jpg","contentUrl":"https:\/\/static.pingcap.com\/files\/2022\/10\/17234942\/avatar.jpg","caption":"Ben Sherrill"},"description":"Senior Solutions Engineer","url":"https:\/\/www.pingcap.com\/ko\/blog\/author\/bsherrill\/"}]}},"grav_blocks":false,"card_markup":"<a class=\"card-resource bg-white\" href=\"https:\/\/www.pingcap.com\/ko\/blog\/supercharging-real-time-applications-tidb-dragonflydb\/\"><div class=\"card-resource__image-container\"><img class=\"card-resource__image\" alt=\"tidb_feature_1800x600 (1)\" src=\"https:\/\/static.pingcap.com\/files\/2025\/11\/07104614\/tidb_feature_1800x600-1-1.png\" loading=\"lazy\" width=3600 height=1200 \/><\/div><div class=\"card-resource__content-container\"><div class=\"card-resource__content-head\"><div class=\"card-resource__category\">Tutorial<\/div><\/div><h5 class=\"card-resource__title\">Supercharging Real-Time Applications with TiDB and DragonflyDB<\/h5><\/div><\/a>","_links":{"self":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/posts\/30287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/users\/323"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/comments?post=30287"}],"version-history":[{"count":21,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/posts\/30287\/revisions"}],"predecessor-version":[{"id":30357,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/posts\/30287\/revisions\/30357"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/media\/30337"}],"wp:attachment":[{"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/media?parent=30287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/categories?post=30287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pingcap.com\/ko\/wp-json\/wp\/v2\/tags?post=30287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}