Getting Low Latency Database Reads in Cloudflare D1
1:25

Getting Low Latency Database Reads in Cloudflare D1

TomDoesTech 30.04.2026 1 514 просмотров 21 лайков

Machine-readable: Markdown · JSON API · Site index

Поделиться Telegram VK Бот
Транскрипт Скачать .md
Анализ с AI
Описание видео
🌎 Follow me here: Discord: https://discord.gg/4ae2Esm6P7 X: https://x.com/tomdoes_tech Instagram: https://www.instagram.com/tomdoestech​ TikTok: https://www.tiktok.com/@tomdoes_tech Bluesky: https://bsky.app/profile/tomdoestech.bsky.social ☕ Buy me a coffee: https://www.buymeacoffee.com/tomn

Оглавление (1 сегментов)

Segment 1 (00:00 - 01:00)

This honestly feels like a cheat code to get really low latency database reads when you're using Cloudflare workers and a D1 database. So, you can see here I have this function and it is called get workspace billing and it's taken almost 1,200 milliseconds to execute this function. And that seems like a crazy long time considering this is just a worker hitting a D1 database. So, you would think that they're kind of co-located and that the latency there would be really low. So, the way that we can get this down is we can come into the database and we can enable this read replicas here. And so, this is going to create replicas of your database throughout a bunch of Cloudflare locations. Now, it does give you this warning this currently in beta. Ignore that, whatever. So, if we come back into our logs after we have enabled our read replicas, you can see that we have this function here get workspace billing and now it's taken 214 milliseconds. So, what's that like a five or six times decrease to execute this function? So, to enable this in your code, you do need to use sessions and luckily Drizzle ORM makes that really easy. You just need to use drizzle. db. withSession with this first unconstrained as the argument here. And I have got this working using a proxy inside of my server. ts. So, you can see I have this function here that surrounds my whole handler run with session. And that is going to use async local storage to keep a record of the session for that request because all of the database reads within that execution need to be done on the same session.

Другие видео автора — TomDoesTech

Ctrl+V

Экстракт Знаний в Telegram

Экстракты и дистилляты из лучших YouTube-каналов — сразу после публикации.

Подписаться

Дайджест Экстрактов

Лучшие методички за неделю — каждый понедельник