A Better Way to Write APIs?

preview_player
Показать описание
Turns out a method i found out that seemed pretty hacky to me at first because it messes with framework defaults actually works quite well. It's pretty fast, cheap, and easy to set up. Honestly there might be bugs that I haven't found yet, so please dont use this in production yet lol

-- sources for this video

-- my links
Рекомендации по теме
Комментарии
Автор

From where the difference in speed is coming from then ? If both are hosted on CF anyway

MaximeDehaye
Автор

Saying it’s double the performance is a bit of a stretch, in a basic example such as yours you’re saving the 10ms overhead that Vercel requires (understandably- Logging, Billing, Auth, etc etc).

The real question is how does it compare in a real world use case, my bet is it will remain in the 10ms range, and definitely not “double”.

Great vid though ❤

mendylanda
Автор

Vercel has something called “regional edge” where they deploy your backend to a cloud flare worker localized to a region like east US or whatever. Normal cloudflare does not do that. I don’t know if your vercel deployment was using regional edge, but if it was, that would explain the speed difference. Regional edge allows you to make multiple DB queries without the downside of the distance cost from a distributed edge to a centralized db. I think you can test it by having the backend do like 3 queries to a database. If Vercel is still slow in that test, then this is an easy cloud flare W. Cool video king, I love high effort stuff like this.

st-jngk
Автор

Nice insight.

For real world apps with database, the latency can be worse twice as much.
If the database is located at the same location of cloudflare, fetch from Database will be fast, but that won't be the case since cloudflare workers are global.
So once the request reaches cloudflare, another request has to go to the database. And if the request issues multiple DB queries, there will multiple requests to DB. Eg find user and then find orders.

So in case of requests requiring data from DB, better to colocate the server and DB in same region

vigneshm
Автор

I really like Hono + Clouflare Workers. Also D1 works fine too. I sometimes use Turso or D1

heyjitendra
Автор

Great! But the problem with edge or regional runtimes like CF Workers is when the distance between the worker (backend) and its other sources matters.
If the regional backend needs to fetch multiple times from a far away source (e.g. database on US-East), it will be worst. If it's one call, it will be the same time overall.

client <-> backend database [backend is near the client]
client backend <-> database [backend is near database]

This shines when the database read replica is regional too, like Turso

diegoquiroz
Автор

I’m working on a project with a client using CF worker, CF worker for platform, hono and solid js and trust me things are super fast. We are talking about single digit millisecond performance. So yeah this works

KrishnaJha
Автор

This is amazing guide, watch step by step while integrating hono in my nextjs app. Thanks alot

ajaymandal
Автор

Can I not just host my NextJs app on Cloudflare pages? As far as I know, all your serverless functions are deployed as workers this way

heyitsfemzy
Автор

Discovered Hono while back, So excited that i could not sleep. Tell me Hono.js vs Elysia.JS which

kasper
Автор

"yeet" as a dummy commit message. I feel so seen right now.

Goshified
Автор

So the only difference is switching the backend host? Wow, that's really a valuable insight

randomname
Автор

Nice catch! Can you please share the code if possible? I would like to see how it is structured and connected.

DhanushkaC
Автор

Do a video building out backend in bun. My curl responses always smoke my command prompt and break the screen 😂. Elysia and Hono both great frameworks but I’m leaning towards Elysia.

frackinfamous
Автор

What about nextjs middleware on CF workers? Should work too, no? Maybe a test with typical middleware like clerk or next-intil. If that stuff runs on CF might be some serious Speed gains 🔥

nvsWhocares
Автор

youre channel is a dream come true. Where do you even find these lol

thatpenguin
Автор

why im getting Error: You cannot define a route with the same specificity as a optional catch-all route ("/" and "/[[...route]]"). ? i follow ur video instructions :(

wanarchives
Автор

I think you can just add FastMode during built time. but conditionally exporting "edge". Adding the hono, only helps in treating the backend code just like a separate server.

sathishkannan
Автор

or just, saying, pick another language

gustavo-oidd
Автор

I don't understand why I see so much hono, while nobody mentions h3. H3 works everywhere with everything, while having 10 times the usage.

grinskks