🎥 PodcastsHPR4728: Programmable Logic Controls - Episode 3(16.09.2026 um 02:00 Uhr)
🔧 AI Nachrichten OpenAI: Stay on top of the pack with ChatGPT Work.(16.09.2026 um 01:31 Uhr)
🔧 ProgrammierungWhat's New in macOS 27 for Developers?(15.09.2026 um 23:01 Uhr)
🔧 ProgrammierungThe 7 Essential Parts of Your Online Presence(15.09.2026 um 23:07 Uhr)
🐧 Linux TippsHow to Write a Linux Kernel Module That Actually Builds(15.09.2026 um 23:10 Uhr)
🔧 ProgrammierungA Task Without A Check Command Is Not Automated(16.09.2026 um 00:53 Uhr)
🔧 ProgrammierungWhy You Don't Have To Learn The Terminal(16.09.2026 um 00:54 Uhr)
🎥 PodcastsHPR4728: Programmable Logic Controls - Episode 3(16.09.2026 um 02:00 Uhr)
🔧 AI Nachrichten OpenAI: Stay on top of the pack with ChatGPT Work.(16.09.2026 um 01:31 Uhr)
🔧 ProgrammierungWhat's New in macOS 27 for Developers?(15.09.2026 um 23:01 Uhr)
🔧 ProgrammierungThe 7 Essential Parts of Your Online Presence(15.09.2026 um 23:07 Uhr)
🐧 Linux TippsHow to Write a Linux Kernel Module That Actually Builds(15.09.2026 um 23:10 Uhr)
🔧 ProgrammierungA Task Without A Check Command Is Not Automated(16.09.2026 um 00:53 Uhr)
🔧 ProgrammierungWhy You Don't Have To Learn The Terminal(16.09.2026 um 00:54 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 2 Min Lesezeit
0

Next 14 Rate Limiting serverless functions

↗ Quelle (dev.to)
🗣️ Stimme:

Rate limiting plays a crucial role in preventing abuse by controlling the number of requests a user can make within a certain period. While, to keep track of requests and ips, we need to store them in-memory for ease of access and speed in response. ⛔✋



Running your Next.js app on Vercel’s serverless or edge runtimes offers incredible speed and scalability. These environments handle requests in isolation, spinning up lightweight instances as needed to deliver lightning-fast responses. However, this architecture has a key limitation: data stored in an instance’s memory isn’t accessible to others, as each instance is stateless.



To address this, we often need external solutions like Redis, a high-performance in-memory database. Services like Upstash Redis complement Vercel perfectly by enabling shared, low-latency data access across instances.



With that foundation set, let’s dive into the implementation!






Upstash Redis 🙌



In your Vercel project page, go to Storage tab.

Click on Create Database button, then select Upstash for Redis:






Don't forget to put this line in your .gitignore:







CODE
.env*.local






Install the following modules:




CODE
npm i @upstash/redis @upstash/ratelimit 






Create a ratelimit instance and use it




CODE
// route.ts
import { Ratelimit } from "@upstash/ratelimit";
import { Redis } from "@upstash/redis";

const rateLimiter = new Ratelimit({
limiter: Ratelimit.fixedWindow(1, "60 s"),
redis: Redis.fromEnv(),
analytics: true,
prefix: "@upstash/ratelimit",
});

const getIP = (req: Request) => {
const ip =
req.headers.get("cf-connecting-ip") ||
req.headers.get("x-forwarded-for") ||
undefined;
return Array.isArray(ip) ? ip[0] : ip;
};

export async function POST(req: Request) {
// ...
// Here we check if limit hit! 👇
const { success } = await rateLimiter.limit(ip || "unknown");
if (!success) return Response.json({ error: "Too many requests" }, { status: 429 } );
// ...
}






Congratulations! 🎉 You’ve unlocked the power of combining Vercel’s serverless capabilities with Upstash Redis. This setup will not only elevate your app’s performance but also open the door to building highly scalable, fast, and reliable applications. With this powerful foundation, your Next.js app is ready to handle whatever comes next—smoothly and efficiently. 🚀

Vollständiger Original-Artikel
Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Ryzen Master does not support current processor: Unsupported Processor
1 Quelle
What's New in macOS 27 for Developers?
1 Quelle
How to Build an Endpoint Data Loss Prevention Strategy for Your Development Team
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Next 14 Rate Limiting serverless functions

Thematisch verwandte Begriffe: Next, Rate, Limiting, serverless · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...