Chapterبەش 10 · Lectureوانە 10.2
Serverless and Edge Functionsکردارەکان بێڕاژەکار و کردارەکانی لێوار
A server you run compared with a function the platform runs; serverless computing and FaaS (and SQLite's other meaning of serverless); events and triggers; a fetch-style handler run with Node.js and the same job in PHP; cold starts measured in a demo; limits on time, memory, files and state; pricing per request with a worked example; edge functions in CDN edge locations, what they are good for, a runnable edge function; how they differ from IoT edge computing; and the real platforms of November 2026.
کە خۆت کاری پێدەکەیت بەراورد بە کە کاری پێدەکات؛ و (و واتاکەی تری بێڕاژەکار لە SQLiteـدا)؛ و ؛ بە شێوازی fetch کە بە Node.js کاری پێدەکرێت و هەمان کار بە PHP؛ لە نموونەیەکدا؛ سنووری کات، ، و دۆخ؛ نرخی هەر بە نموونەیەکی کارکراو؛ لە ، بۆ چی باشن و کە کاری پێدەکرێت؛ جیاوازییان لەگەڵ IoT؛ و ڕاستەقینەکانی تشرینی دووەمی 2026.
What you will learnچی فێر دەبیت
- Explain how a serverless function differs from a server you run, and place FaaS next to IaaS, PaaS and BaaS.
- Tell the cloud meaning of serverless from SQLite's meaning.
- Name common events and triggers, and write and run a fetch-style handler.
- Explain cold and warm starts, the limits of functions and pay-per-request pricing, with a worked cost.
- Say what edge functions are good and bad at, and how they differ from IoT edge computing.
- ڕوونی بکەیتەوە بێڕاژەکار چ جیاوازییەکی لەگەڵ هەیە کە خۆت کاری پێدەکەیت و لە تەنیشت ، و دابنێیت.
- واتای هەوریی بێڕاژەکار لە واتاکەی SQLite جیا بکەیتەوە.
- و باو ناو ببەیت و بە شێوازی fetch بنووسیت و کاری پێ بکەیت.
- و ، سنوورەکانی و نرخی هەر بە ژماردنێکی کارکراو ڕوون بکەیتەوە.
- بڵێیت بۆ چی باشن و بۆ چی خراپن و چ جیاوازییەکیان لەگەڵ IoT هەیە.
Who runs the server?کێ ڕاژەکارەکە کار پێدەکات؟
Until now your PHP code has lived on a server that you run yourself. In XAMPP you start Apache, and it waits all day for requests; for a real site you rent a server and keep it updated. There is another way: you upload only a function, and a platform runs it each time a request or another event arrives. While nobody asks, nothing of yours is running.
تا ئێستا کۆدی PHPـەکەت لەسەر ژیاوە کە خۆت کاری پێدەکەیت. لە XAMPPـدا Apache دەست پێ دەکەیت و هەموو ڕۆژەکە چاوەڕێی دەکات؛ بۆ ڕاستەقینە بە کرێ دەگریت و نوێی دەکەیتەوە. ڕێگەیەکی تریش هەیە: تەنیا هەڵبار دەکەیت و هەر جارێک یان تر بگات کاری پێدەکات. کاتێک کەس داوا ناکات، هیچ شتێکی تۆ کار ناکات.
This lesson explains that way: serverless functions, the events that start them, cold starts, their limits and their price. Then it turns to edge functions: small functions that run in many data centres, close to each visitor.
ئەم وانەیە ئەو ڕێگەیە ڕوون دەکاتەوە: بێڕاژەکار، ئەو دەستیان پێ دەکەن، ، سنوورەکان و نرخیان. پاشان دەچێتە سەر : بچووک کە لە زۆر ، نزیک لە هەر سەردانکەرێک، کار دەکەن.
Serverless computing and FaaSژمێرکاریی بێڕاژەکار و FaaS
A cloud model in which the provider starts and stops servers automatically as requests arrive, so you never manage a server and pay only while your code or database is working.
مۆدێلێکی هەورییە کە تێیدا دابینکەرەکە بە شێوەیەکی خۆکار ڕاژەکارەکان کاتێک داواکاری دێت دادەگیرسێنێت و دەیانوەستێنێت، بۆیە هەرگیز ڕاژەکار بەڕێوە نابەیت و تەنیا لەو کاتەدا پارە دەدەیت کە کۆد یان بنکەدراوەکەت کار دەکات.
Serverless does not mean that there are no servers. It means that the servers are not your job: the provider starts copies of your code when requests arrive, adds more on a busy day, removes them when traffic stops (even down to zero) and bills you for the use. The most common form is FaaS, Function as a Service, where your unit of work is a single function; AWS Lambda and Cloudflare Workers are examples.
بێڕاژەکار واتای ئەوە نییە کە هیچ نییە. واتە کاری تۆ نین: دابینکەرەکە کاتێک دێن کۆپیی کۆدەکەت دەست پێ دەکات، لە ڕۆژی قەرەباڵغدا زیاتر زیاد دەکات، کاتێک هاتوچۆ دەوەستێت لایان دەبات (تەنانەت تا سفر) و بەپێی بەکارهێنان پارەت لێ وەردەگرێت. باوترین شێوەی ـە، Function as a Service، کە تێیدا یەکەی کارەکەت تەنیا یەک ؛ AWS Lambda و Cloudflare Workers نموونەن.
It sits next to the service models of Cloud Computing: with IaaS you run the virtual machines, with PaaS the platform runs your app, and with FaaS you hand over even the decision of how many servers run and when. BaaS is a close relative: it gives an app a ready back end, and serverless functions often add the custom parts.
لە تەنیشت مۆدێلەکانی خزمەتگوزاریی هەورەژمێرکاری دادەنیشێت: لە خۆت کار پێدەکەیت، لە کار پێدەکات و لە تەنانەت بڕیاری ئەوەش دەدەیتە دەست دابینکەر کە چەند و کەی کار بکەن. BaaS خزمێکی نزیکە: ئامادە دەداتە و بێڕاژەکار زۆرجار بەشە تایبەتەکانی بۆ زیاد دەکەن.
Serverless computing and FaaSژمێرکاریی بێڕاژەکار و FaaS
Serverless: two meaningsبێڕاژەکار: دوو واتا
You met the word in SQLite Basics: SQLite is serverless because there is no separate database server program; the SQLite library inside your program reads the file itself. In cloud computing the word means something else: the servers exist, but the provider runs them. SQLite's own website calls the first meaning classic serverless and the second neo-serverless, and advises asking which one a product means. CêIT keeps them apart with two terms: for SQLite's meaning and for the cloud.
ئەم وشەیەت لە بنەماکانی SQLiteـدا بینی: بێڕاژەکارـە چونکە هیچ جیای نییە؛ SQLite لە ناو خۆی دەخوێنێتەوە. لە وشەکە واتایەکی تری هەیە: هەن، بەڵام دابینکەرەکە کاریان پێدەکات. خودی SQLite بە واتای یەکەم دەڵێت classic serverless و بە دووەم neo-serverless و ئامۆژگاری دەکات بپرسیت بەرهەمێک مەبەستی کامیانە. CêIT بە دوو زاراوە لە یەکیان جیا دەکاتەوە: بۆ واتای SQLite و بۆ هەور.
Events and triggersڕووداوەکان و پیتکەکانی کردار
A serverless function never runs by itself. It runs because something happened: an event. A trigger is the setting that connects one kind of event to your function. AWS's documentation says that more than 200 of its services can trigger a Lambda function. The common event sources are:
بێڕاژەکار هەرگیز خۆبەخۆ کار ناکات. کار دەکات چونکە شتێک ڕووی داوە: . ئەو کە جۆرێک لە بە دەبەستێتەوە. AWS دەڵێت زیاتر لە 200 خزمەتگوزاریی AWS دەتوانن Lambda کار پێ بکەن. سەرچاوە باوەکانی ئەمانەن:
- an HTTP request: an API call, a form, or a message from another service;
- a file uploaded to cloud storage: make a small copy of a photo;
- a message in a queue: send an email a little later;
- a timer: every night at 02:00, build a report;
- a change in a database: update a search list when a row changes.
- HTTP: بانگکردنی API، ، یان پەیامێک لە خزمەتگوزارییەکی ترەوە؛
- کە هەڵبار دەکرێت بۆ : کۆپییەکی بچووکی وێنەیەک دروست بکە؛
- پەیامێک لە : ئیمەیڵێک کەمێک دواتر بنێرە؛
- : هەموو شەوێک لە کاتژمێر 02:00، دروست بکە؛
- گۆڕانکارییەک لە : کاتێک دەگۆڕێت، لیستی گەڕان نوێ بکەرەوە.
A function in code: request in, response outکردارێک لە کۆددا: داواکاری دێتە ژوورەوە، وەڵام دەچێتە دەرەوە
For HTTP events most platforms now use one shape: a handler that receives a standard Request object and returns a Response object, the same objects as the Fetch API of the browser (MDN: Response). Cloudflare Workers, Vercel Functions, Netlify, Supabase and Deno accept it in November 2026. Node.js has Request and Response built in (stable since version 21), so with Node.js 24 you can run a handler on your own computer and play the platform yourself:
بۆ HTTP زۆربەی ئێستا یەک شێوە بەکار دەهێنن: کە ستانداردی Request وەردەگرێت و Response دەگەڕێنێتەوە، هەمان ئەو Fetch APIـی (MDN: Response). Cloudflare Workers، Vercel Functions، Netlify، Supabase و Deno لە تشرینی دووەمی 2026ـدا قبووڵی دەکەن. Node.js خۆی Request و Responseـی تێدایە (لە وەشانی 21ـەوە جێگیرن)، بۆیە بە Node.js 24 دەتوانیت لەسەر خۆت کار پێ بکەیت و خۆت ڕۆڵی ببینیت:
// hello-function.mjs - a fetch-style function: a Request comes in, a Response goes out
export default {
async fetch(request) {
const url = new URL(request.url);
if (url.pathname === '/hello') {
const name = url.searchParams.get('name') ?? 'world';
return Response.json({ message: `Hello, ${name}!` });
}
return new Response('Not found', { status: 404 });
},
};Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
The handler: the platform calls
fetch()once for every request.: بۆ هەر جارێک
fetch()بانگ دەکات.- Lineدێڕی 8
Response.json()makes a 200 response with theapplication/jsoncontent type.Response.json()200 بە جۆری ناوەڕۆکیapplication/jsonدروست دەکات.- Lineدێڕی 10
Any other path: a plain-text 404.
هەر تر: 404 بە دەقی سادە.
// run-locally.mjs - play the platform: build Requests and call the function
import fn from './hello-function.mjs';
for (const path of ['/hello?name=Shilan', '/hello', '/menu']) {
const response = await fn.fetch(new Request('https://example.com' + path));
console.log(path, '->', response.status, response.headers.get('content-type'));
console.log(' ', await response.text());
}/hello?name=Shilan -> 200 application/json
{"message":"Hello, Shilan!"}
/hello -> 200 application/json
{"message":"Hello, world!"}
/menu -> 404 text/plain;charset=UTF-8
Not foundOutput of node run-locally.mjs with Node.js 24.14.
node run-locally.mjs بە Node.js 24.14.
A function in code: request in, response outکردارێک لە کۆددا: داواکاری دێتە ژوورەوە، وەڵام دەچێتە دەرەوە
The same job in PHP on XAMPPهەمان کار بە PHP لەسەر XAMPP
Compare it with the PHP way from Build your own JSON API. In PHP the file is the handler: Apache, always running, finds hello.php and runs it for each request. The superglobals hold the request, and header() and echo build the response.
بەراوردی بکە لەگەڵ ڕێگای PHP لە APIـی JSONـی خۆت دروست بکە. لە PHPـدا : Apache، کە هەمیشە کار دەکات، hello.php دەدۆزێتەوە و بۆ هەر جێبەجێی دەکات. هەڵدەگرن و header() و echo دروست دەکەن.
<?php
// api/hello.php - the same job on XAMPP: Apache runs all the time and calls this file
header('Content-Type: application/json');
$name = $_GET['name'] ?? 'world';
echo json_encode(['message' => "Hello, $name!"]);HTTP/1.1 200 OK
Content-Type: application/json
{"message":"Hello, Shilan!"}Asked with curl -i "http://127.0.0.1:8097/api/hello.php?name=Shilan" from PHP 8.2's built-in server (php -S); the headers Host, Date, Connection and X-Powered-By are left out.
بە curl -i "http://127.0.0.1:8097/api/hello.php?name=Shilan" لە ناوخۆیی PHP 8.2 (php -S) داواکرا؛ Host، Date، Connection و X-Powered-By لابراون.
| Questionپرسیار | PHP on your server (XAMPP)PHP لەسەر خۆت (XAMPP) | A serverless function بێڕاژەکار |
|---|---|---|
| Who waits for requestsکێ چاوەڕێی دەکات | Apache, all dayApache، هەموو ڕۆژەکە | the platform; your code sleeps؛ کۆدەکەت دەخەوێت |
| The request | $_GET, $_POST, $_SERVER | a Request object Request |
| The response | header(), http_response_code(), echo | new Response(...), Response.json() |
| A busy dayڕۆژێکی قەرەباڵغ | one machine: buy a bigger oneیەک ئامێر: ئامێرێکی گەورەتر بکڕە | more copies start by themselvesکۆپیی زیاتر خۆیان دەست پێ دەکەن |
| The billپارەدان | the same every monthهەموو مانگێک وەک یەک | per request and run timeبۆ هەر و کاتی کارکردن |
Cold starts and warm startsدەستپێکی سارد و دەستپێکی گەرم
A function needs a place to run: an execution environment with the language runtime, your code and some memory. When a request arrives and no environment is ready, the platform must first download the code, start the runtime and run your start-up code, which is everything outside the handler. That wait is a cold start. Afterwards the environment is kept for a while, so the next request is a fast warm start. AWS reports that cold starts happen in under 1% of calls and take from under 100 ms to over 1 second (as of 2026), and that this start-up time is billed too.
شوێنێکی پێویستە بۆ کارکردن: بە بەرنامەی زمانەکە، کۆدەکەت و بڕێک . کاتێک دێت و هیچ ژینگەیەک ئامادە نییە، دەبێت سەرەتا کۆدەکە بهێنێت، بەرنامەی زمانەکە دەست پێ بکات و کۆدی دەستپێکردنی تۆ جێبەجێ بکات، کە هەموو ئەو کۆدەیە لە دەرەوەی . ئەو چاوەڕوانییە . دواتر ژینگەکە ماوەیەک دەهێڵرێتەوە، بۆیە دواتر دەبێت بە خێرا. AWS دەڵێت لە کەمتر لە 1%ـی بانگکردنەکاندا ڕوو دەدەن و لە کەمتر لە 100 ms تا زیاتر لە 1 چرکە دەخایەنن (لە 2026ـدا) و پارەی ئەم کاتی دەستپێکردنەش وەردەگیرێت.


Cold starts and warm startsدەستپێکی سارد و دەستپێکی گەرم
Watch it: code outside the handler runs onceببینە: کۆدی دەرەوەی مامەڵەکەر یەکجار کار دەکات
Code at the top of the module runs once, when an environment starts; fetch() runs for every request. This demo plays two environments by importing the same file twice:
ئەو کۆدەی لە سەرەوەی مۆدیولەکەدایە یەکجار کار دەکات، کاتێک ژینگەیەک دەست پێ دەکات؛ fetch() بۆ هەموو کار دەکات. ئەم نموونەیە بە دوو جار هێنانی هەمان ، ڕۆڵی دوو ژینگە دەبینێت:
// counter-function.mjs - code outside fetch() runs once per environment
console.log('init: the platform starts a new environment (cold start)');
const startedAt = Date.now();
let calls = 0; // lives only as long as THIS environment
export default {
async fetch(request) {
calls++;
return Response.json({ calls, aliveMs: Date.now() - startedAt });
},
};Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2-4
Outside the handler: runs once per environment, at the cold start.
لە دەرەوەی : بۆ هەر ژینگەیەک یەکجار، لە کاتی ، کار دەکات.
- Lineدێڕی 8
Inside the handler: runs on every request.
لە ناو : لە هەموو کار دەکات.
// cold-and-warm.mjs - one environment serves three requests, then a second one starts
const request = () => new Request('https://example.com/count');
const first = (await import('./counter-function.mjs?env=1')).default; // cold start
for (let i = 0; i < 3; i++) {
console.log('env 1:', await (await first.fetch(request())).text()); // warm starts
}
const second = (await import('./counter-function.mjs?env=2')).default; // another copy
console.log('env 2:', await (await second.fetch(request())).text());init: the platform starts a new environment (cold start)
env 1: {"calls":1,"aliveMs":38}
env 1: {"calls":2,"aliveMs":41}
env 1: {"calls":3,"aliveMs":41}
init: the platform starts a new environment (cold start)
env 2: {"calls":1,"aliveMs":0}Output of node cold-and-warm.mjs (Node.js 24.14). The aliveMs numbers change from run to run.
node cold-and-warm.mjs (Node.js 24.14). ژمارەکانی aliveMs لە هەر جارێکدا دەگۆڕێن.
Environment 1 counted 1, 2, 3; environment 2 started again at 1. Use the first fact: open a database connection or load a library outside the handler, so that warm starts reuse it, as AWS recommends. Beware of the second: never keep important data, such as a visitor count, in a variable, because you never know which environment answers, or when it disappears.
ژینگەی 1 ژماردی 1، 2، 3؛ ژینگەی 2 دیسان لە 1ـەوە دەستی پێ کرد. سوود لە ڕاستییەکەی یەکەم وەربگرە: بکەرەوە یان لە دەرەوەی بهێنە، بۆ ئەوەی دووپاتە بەکاری بهێننەوە، وەک AWS ئامۆژگاری دەکات. ئاگاداری دووەمیان بە: هەرگیز گرنگ، وەک ژمارەی سەردانکەران، لە هەڵمەگرە، چونکە هەرگیز نازانیت کام ژینگە وەڵام دەداتەوە یان کەی نامێنێت.
Limits: time, memory, files and stateسنوورەکان: کات، بیرگە، فایلەکان و دۆخ
A platform shares its machines among many customers, so every function lives inside limits. As of November 2026:
ئامێرەکانی لە نێوان زۆر کڕیاردا بەش دەکات، بۆیە هەموو لە ناو سنوورێکدا دەژی. لە تشرینی دووەمی 2026ـدا:
- Time: an AWS Lambda function may run for at most 15 minutes per call. A Cloudflare Worker on the free plan gets 10 ms of CPU time per request (30 seconds by default on the paid plan, up to 5 minutes).
- Memory: Lambda from 128 MB to 10,240 MB; a Worker gets 128 MB.
- Files: the disk is read-only except a scratch folder (
/tmpon Lambda and Vercel) that disappears with the environment. Keep uploads in cloud storage and data in a database. - State: variables die with their environment, as the demo showed.
- کات: AWS Lambda لە هەر بانگکردنێکدا زۆرترین 15 خولەک کار دەکات. Cloudflare Worker لە پلانی بێبەرانبەردا 10 ms کاتی CPU بۆ هەر وەردەگرێت (لە پلانی پارەداردا بە بنەڕەت 30 چرکە، تا 5 خولەک).
- : Lambda لە 128 MB تا 10,240 MB؛ Worker 128 MB وەردەگرێت.
- : دیسکەکە تەنیا بۆ خوێندنەوەیە جگە لە بوخچەیەکی کاتی (
/tmpلە Lambda و Vercelـدا) کە لەگەڵ ژینگەکەدا ون دەبێت. ئەو هەڵبار دەکرێن لە و لە هەڵبگرە. - دۆخ: لەگەڵ ژینگەکەیاندا دەمرن، وەک نموونەکە پیشانی دا.
Paying per requestپارەدان بۆ هەر داواکارییەک
Serverless follows the pay-as-you-go idea of cloud computing (measured service). AWS Lambda, for example, charges for the number of requests and for the time × memory your code uses, counted in GB-seconds. In November 2026 its US East price list said: $0.20 per million requests, about $0.0000167 per GB-second, and a free tier of 1 million requests and 400,000 GB-seconds a month. Worked example: a school's results API gets 3 million requests a month, and each runs 120 ms with 128 MB (0.125 GB).
پەیڕەوی بیرۆکەی ـی دەکات (خزمەتگوزاریی پێوانەکراو). بۆ نموونە AWS Lambda پارە بۆ ژمارەی و بۆ کات × ئەو کۆدەکەت بەکاری دەهێنێت وەردەگرێت، کە بە GB-چرکە دەژمێردرێت. لە تشرینی دووەمی 2026ـدا لیستی نرخی US East دەیگوت: $0.20 بۆ هەر ملیۆنێک ، نزیکەی $0.0000167 بۆ هەر GB-چرکەیەک و بەشی بێبەرانبەری مانگانە 1 ملیۆن و 400,000 GB-چرکە. نموونەیەکی کارکراو: APIـی ئەنجامەکانی قوتابخانەیەک مانگانە 3 ملیۆن وەردەگرێت و هەریەکەیان 120 ms بە 128 MB (0.125 GB) کار دەکات.
Total for the month: $0.40. Other services, such as data transfer, are billed separately.
کۆی مانگەکە: $0.40. خزمەتگوزارییەکانی تر، وەک گواستنەوەی ، بە جیا حیساب دەکرێن.
The other side: a bug that loops, or an attack, can send millions of requests, and the bill follows; at 100 million requests the same function would cost about $38 a month. Set a budget alert, and remember that moving to another provider later is work (vendor lock-in).
لایەنەکەی تر: کە بێ کۆتایی دووپاتە دەبێتەوە، یان هێرشێک، دەتوانێت ملیۆنان بنێرێت و پارەکەش بەدوایدا دێت؛ لە 100 ملیۆن هەمان مانگانە نزیکەی $38 تێدەچێت. ئاگادارکەرەوەیەکی بودجە دابنێ و لە بیرت بێت گواستنەوە بۆ دابینکەرێکی تر دواتر کاری دەوێت (قەتیسبوون لای دابینکەر).
Edge functions: code close to every visitorکردارەکانی لێوار: کۆد نزیک لە هەموو سەردانکەرێک
A normal serverless function runs in one region that you choose; Vercel's default, for example, is Washington, D.C. (iad1). A visitor in Erbil then waits for a trip across the world and back. A already keeps copies of pages in many edge locations: data centres spread over the world. An edge function runs your code in those edge locations, so the one nearest the visitor answers. Cloudflare says its network reaches 348 cities and that 95% of internet users are within 50 ms of it (November 2026). Edge platforms such as Cloudflare Workers run code in small sandboxes inside one JavaScript engine (V8 isolates), which start far faster than a container, so cold starts are rare and short.
بێڕاژەکاری ئاسایی لە یەک ناوچەدا کار دەکات کە خۆت هەڵیدەبژێریت؛ بۆ نموونە بنەڕەتی Vercel واشنتنە (iad1). ئەوسا سەردانکەرێک لە هەولێر چاوەڕێی گەشتێک بە جیهاندا دەکات و دەگەڕێتەوە. پێشتر کۆپیی لە زۆر هەڵدەگرێت: ئەو بە جیهاندا بڵاو کراونەتەوە. کۆدەکەت لە کار پێدەکات، بۆیە نزیکترینیان لە سەردانکەرەکە وەڵام دەداتەوە. Cloudflare دەڵێت ڕایەڵەکەی دەگاتە 348 شار و 95%ـی بەکارهێنەرانی ئینتەرنێت لە ماوەی 50 msـدا لێیەوە نزیکن (تشرینی دووەمی 2026). سەکۆکانی لێوار وەک Cloudflare Workers کۆد لە ناو بچووکدا لە ناو یەک بزوێنەری JavaScript (isolateـەکانی V8) کار پێدەکەن، کە زۆر خێراتر لە دەست پێ دەکەن، بۆیە دەگمەن و کورتن.
Edge functions: code close to every visitorکردارەکانی لێوار: کۆد نزیک لە هەموو سەردانکەرێک
What edge functions are good atکردارەکانی لێوار بۆ چی باشن
An edge function is small and sees every request before the origin server does. That makes it good at quick decisions: redirects (send / to the visitor's language page); access checks (stop requests without the right secret before they reach the origin); A/B tests (keep each visitor in group A or B with a cookie); small personalisation (text or prices by country, from the platform's location data); and small, fast APIs and header changes.
بچووکە و هەموو پێش دەبینێت. ئەمە بۆ بڕیاری خێرا باشی دەکات: (/ بنێرە بۆ زمانی سەردانکەرەکە)؛ پشکنینی ( بەبێ نهێنییە دروستەکە ڕابگرە پێش ئەوەی بگەنە )؛ (هەر سەردانکەرێک بە لە کۆمەڵەی A یان B بهێڵەرەوە)؛ تایبەتکردنی بچووک (دەق یان نرخ بەپێی وڵات، لە شوێنی )؛ هەروەها APIـی بچووک و خێرا و گۆڕینی .
It is a poor fit for long or heavy work, for big libraries that need Node.js-only features or a disk, and for code that sends many queries to one database far away: every query would cross the world again. Vercel's documentation advises running functions close to their data for this reason.
بۆ کاری درێژ یان قورس، بۆ گەورە کە تایبەتمەندیی تایبەت بە Node.js یان دیسکیان پێویستە و بۆ کۆدێک کە زۆر بۆ یەک دوور دەنێرێت گونجاو نییە: هەر دیسان بە جیهاندا دەڕوات. Vercel بەم هۆیەوە ئامۆژگاری دەکات نزیک لە کار پێ بکرێن.
Edge functions: code close to every visitorکردارەکانی لێوار: کۆد نزیک لە هەموو سەردانکەرێک
An edge function with three jobsکردارێکی لێوار بە سێ کار
This edge function does all three jobs in the fetch style. env holds the settings that the platform passes in, so the admin secret is not written in the code. In the local run, env.origin stands in for the origin server.
ئەم هەر سێ کارەکە بە شێوازی fetch دەکات. env ئەو هەڵدەگرێت کە دەیاننێرێت، بۆیە نهێنیی بەڕێوەبەر لە کۆدەکەدا نانووسرێت. لە کارپێکردنی ناوخۆییدا env.origin جێگای دەگرێتەوە.
// edge-function.mjs - three small jobs an edge function does before the origin server
export default {
async fetch(request, env) {
const url = new URL(request.url);
// 1. Redirect: the home page sends each visitor to a page in their language
if (url.pathname === '/') {
const lang = request.headers.get('accept-language') ?? '';
const page = lang.startsWith('ckb') ? '/ckb/' : '/en/';
return Response.redirect(new URL(page, url), 302);
}
// 2. Auth check: stop requests to /admin that have no valid token
if (url.pathname.startsWith('/admin')) {
if (request.headers.get('authorization') !== `Bearer ${env.ADMIN_TOKEN}`) {
return new Response('Unauthorized', { status: 401 });
}
}
// 3. A/B test: every visitor stays in group A or B, remembered in a cookie
const cookie = request.headers.get('cookie') ?? '';
let group = cookie.match(/ab=(A|B)/)?.[1];
const isNew = !group;
group ??= Math.random() < 0.5 ? 'A' : 'B';
const fromOrigin = await env.origin(request, group); // ask the origin server
const response = new Response(fromOrigin.body, fromOrigin); // a copy we may change
if (isNew) {
response.headers.append('set-cookie', `ab=${group}; Path=/; Max-Age=2592000`);
}
return response;
},
};Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 7-10
Redirect:
Accept-Languageis a standard HTTP header;new URL(page, url)makes the full address thatResponse.redirect()needs.:
Accept-Languageکە هەموو دەینێرێت؛new URL(page, url)ئەو ناونیشانە تەواوە دروست دەکات کەResponse.redirect()پێویستیەتی.- Lineدێڕی 14-16
Access check: the secret comes from
env, not from the code. A wrong or missing header gets 401 at the edge.پشکنینی : نهێنییەکە لە
envـەوە دێت، نەک لە کۆدەوە. هەڵە یان نەبوو لە لێوارەوە 401 وەردەگرێت.- Lineدێڕی 21-29
A/B test: an old visitor keeps the group in the cookie; a new one gets a random group and a cookie for 30 days.
: سەردانکەری کۆن کۆمەڵەکەی لە دەمێنێتەوە؛ سەردانکەری نوێ کۆمەڵەیەکی هەڕەمەکی و بۆ 30 ڕۆژ وەردەگرێت.
// run-edge.mjs - play the platform: settings in env, and a pretend origin server
import edge from './edge-function.mjs';
const env = {
ADMIN_TOKEN: 'demo-123', // a setting, not in the code
origin: async (request, group) =>
new Response(`page ${new URL(request.url).pathname} (design ${group})`),
};
const site = 'https://shop.example';
const tests = [
['/', { 'accept-language': 'ckb-IQ,ckb;q=0.9,en;q=0.5' }],
['/', { 'accept-language': 'en-GB,en;q=0.9' }],
['/admin', {}],
['/admin', { authorization: 'Bearer demo-123' }],
['/products', { cookie: 'ab=B' }],
['/products', {}],
];
for (const [path, headers] of tests) {
const res = await edge.fetch(new Request(site + path, { headers }), env);
const where = res.headers.get('location') ?? (await res.text());
const cookie = res.headers.get('set-cookie') ?? '';
console.log(`${path.padEnd(9)} ${res.status} ${where} ${cookie}`);
}/ 302 https://shop.example/ckb/ / 302 https://shop.example/en/ /admin 401 Unauthorized /admin 200 page /admin (design A) ab=A; Path=/; Max-Age=2592000 /products 200 page /products (design B) /products 200 page /products (design B) ab=B; Path=/; Max-Age=2592000
Output of node run-edge.mjs (Node.js 24.14). A new visitor's group is random, so your run may show A where this one shows B.
node run-edge.mjs (Node.js 24.14). کۆمەڵەی سەردانکەری نوێ هەڕەمەکییە، بۆیە لەوانەیە کارپێکردنی تۆ A پیشان بدات لە شوێنێک کە ئەمە B پیشان دەدات.
Read the six lines: two redirects (Kurdish first, then English); 401 for /admin without the secret and the page with it; the visitor with the cookie ab=B stays in B and gets no new cookie; the new visitor gets a group and a set-cookie.
شەش دێڕەکە بخوێنەوە: دوو (سەرەتا کوردی، پاشان ئینگلیزی)؛ 401 بۆ /admin بەبێ نهێنییەکە و لەگەڵیدا؛ ئەو سەردانکەرەی ab=Bـی هەیە لە B دەمێنێتەوە و نوێ وەرناگرێت؛ سەردانکەرە نوێیەکە کۆمەڵەیەک و set-cookie وەردەگرێت.
Edge functions, edge computing and the cloudکردارەکانی لێوار، ژمێرکاریی لێوار و هەور
The word edge means “closer to where things happen”, but in different places. Edge functions run in a CDN's data centres, near the people who visit a website. Edge computing in the Internet of Things runs on the device itself or on a gateway next to it, near the sensors (cloud, fog and edge). A serverless function in a region runs in the cloud, near the data. And cloud databases can be serverless too: the provider adds and removes computing power and can pause the database when nobody uses it.
وشەی لێوار واتە «نزیکتر لەو شوێنەی شتەکانی لێ ڕوو دەدات»، بەڵام لە شوێنی جیاوازدا. لە کار دەکەن، نزیک لەو خەڵکەی سەردانی دەکەن. لە لەسەر خودی ئامێرەکە یان لەسەر دەروازەیەکی تەنیشتی کار دەکات، نزیک لە (هەور، تەم و لێوار). بێڕاژەکار لە ناوچەیەکدا لە هەوردا کار دەکات، نزیک لە . هەروەها بنکەدراوە هەورییەکانـیش دەتوانن بێڕاژەکار بن: دابینکەر توانای ژمێرکاری زیاد و کەم دەکات و دەتوانێت ڕابگرێت کاتێک کەس بەکاری ناهێنێت.
Platforms in November 2026سەکۆکان لە تشرینی دووەمی 2026ـدا
Product names, runtimes and limits change every year, so learn the ideas and check the official pages before you choose. As of November 2026:
ناوی بەرهەمەکان، بەرنامەی زمانەکان و سنوورەکان هەموو ساڵێک دەگۆڕێن، بۆیە بیرۆکەکان فێر ببە و پێش هەڵبژاردن لاپەڕە فەرمییەکان بپشکنە. لە تشرینی دووەمی 2026ـدا:
| Platform | Where the code runsکۆدەکە لە کوێ کار دەکات | Notes (as of November 2026)تێبینی (تشرینی دووەمی 2026) |
|---|---|---|
| AWS Lambda | one region you chooseیەک ناوچە کە خۆت هەڵیدەبژێریت | Node.js, Python, Java and more; up to 15 minutes per call; triggered by 200+ AWS servicesNode.js، Python، Java و زیاتر؛ تا 15 خولەک بۆ هەر بانگکردنێک؛ زیاتر لە 200 خزمەتگوزاریی AWS دەتوانن کاری پێ بکەن |
| Lambda@Edge, CloudFront Functions | AWS's CDN edgeلێواری CDNـی AWS | Lambda@Edge: Node.js and Python. CloudFront Functions: JavaScript, under a millisecond, 2 MB of memory, no network accessLambda@Edge: Node.js و Python. CloudFront Functions: JavaScript، کەمتر لە میلیچرکەیەک، 2 MB ، بێ دەستگەیشتن بە |
| Cloudflare Workers | 348 cities348 شار | V8 isolates; free plan: 100,000 requests a day and 10 ms CPU per requestisolateـی V8؛ پلانی بێبەرانبەر: 100,000 لە ڕۆژێکدا و 10 ms CPU بۆ هەر |
| Vercel Functions | one region by default (iad1, Washington, D.C.)بە بنەڕەت یەک ناوچە (iad1، واشنتن) | Node.js, Bun, Python, Go, Ruby, Rust, Wasm; the Edge runtime still exists, but Vercel now advises Node.js, and Next.js 16.3 no longer supports runtime = 'edge'Node.js، Bun، Python، Go، Ruby، Rust، Wasm؛ Edge runtime هێشتا هەیە، بەڵام Vercel ئێستا Node.js پێشنیار دەکات و Next.js 16.3 چیتر پشتگیریی runtime = 'edge' ناکات |
| Netlify Functions, Netlify Edge Functions | Functions: one region (default Ohio); Edge Functions: the edgeFunctions: یەک ناوچە (بنەڕەت Ohio)؛ Edge Functions: لێوار | Edge Functions run on Deno: 50 ms CPU per request, 512 MBEdge Functions لەسەر Deno کار دەکەن: 50 ms CPU بۆ هەر ، 512 MB |
| Supabase Edge Functions | regional nodes near usersنۆدی ناوچەیی نزیک لە | TypeScript, Deno-compatible; 2 s CPU, 256 MB, 150 s (free) or 400 s (paid)TypeScript، گونجاو لەگەڵ Deno؛ 2 s CPU، 256 MB، 150 s (بێبەرانبەر) یان 400 s (پارەدار) |
| Deno Deploy | 2 regions (the new platform)2 ناوچە (سەکۆ نوێیەکە) | JavaScript and TypeScript; Deploy Classic was shut down on 20 July 2026JavaScript و TypeScript؛ Deploy Classic لە 20ی تەمموزی 2026 داخرا |
Common mistakesهەڵە باوەکان
// mistake-redirect.mjs - Response.redirect() needs a full URL
const response = Response.redirect('/ckb/', 302);
console.log(response.status);TypeError: Failed to parse URL from /ckb/
at Response.redirect (node:internal/deps/undici/undici:11363:17)
at file:///…/mistake-redirect.mjs:2:27
…
[cause]: TypeError: Invalid URL
…
code: 'ERR_INVALID_URL',
input: '/ckb/'Real output of node mistake-redirect.mjs (Node.js 24.14), shortened where you see ….
ڕاستەقینەی node mistake-redirect.mjs (Node.js 24.14)، لەو شوێنانەی … دەبینیت کورت کراوەتەوە.
Fix: build the full address from the request, as the edge function does: Response.redirect(new URL('/ckb/', request.url), 302).
چارەسەر: ناونیشانە تەواوەکە لە دروست بکە، وەک دەیکات: Response.redirect(new URL('/ckb/', request.url), 302).
Exercisesڕاهێنانەکان
Serverless function, edge function or a long-running server? (a) Send visitors from / to /ckb/ or /en/. (b) Build a report every night at 02:00. (c) A chat service that keeps thousands of connections open all day. (d) Make a small copy of every photo that is uploaded.
بێڕاژەکار، یان کە هەمیشە کار دەکات؟ (أ) ناردنی سەردانکەران لە /ـەوە بۆ /ckb/ یان /en/. (ب) دروستکردنی هەموو شەوێک لە کاتژمێر 02:00. (ج) خزمەتگوزارییەکی چات کە هەزاران پەیوەندی هەموو ڕۆژەکە کراوە دەهێڵێتەوە. (د) دروستکردنی کۆپییەکی بچووک بۆ هەر وێنەیەک کە هەڵبار دەکرێت.
Show answerوەڵامەکە پیشان بدە
- (a) An edge function: a tiny decision about each request, best made near the visitor.
- (b) A serverless function with a timer trigger.
- (c) A long-running server, or a service built for open connections: functions are made for short calls with time limits.
- (d) A serverless function with a file-upload trigger.
- (أ) : بڕیارێکی بچووک لەبارەی هەر ، باشترە لە نزیک سەردانکەرەوە بدرێت.
- (ب) بێڕاژەکار کە دەستی پێ دەکات.
- (ج) کە هەمیشە کار دەکات، یان خزمەتگوزارییەک کە بۆ پەیوەندیی کراوە دروست کراوە: بۆ بانگکردنی کورت و بە سنووری کات دروست کراون.
- (د) بێڕاژەکار کە دەستی پێ دەکات.
With the Lambda prices of this lesson, what does a function cost per month if it gets 4 million requests, each running 200 ms with 256 MB?
بە نرخەکانی Lambda لەم وانەیەدا، مانگانە چەندی تێدەچێت ئەگەر 4 ملیۆن وەربگرێت و هەریەکەیان 200 ms بە 256 MB کار بکات؟
Show answerوەڵامەکە پیشان بدە
Total: $0.60 a month, before other services such as data transfer.
کۆ: $0.60 لە مانگێکدا، پێش خزمەتگوزارییەکانی تر وەک گواستنەوەی .
Change hello-function.mjs so that /hello answers only GET. Any other method must get status 405 and the header Allow: GET. Test it with GET, POST and DELETE.
hello-function.mjs بگۆڕە بۆ ئەوەی /hello تەنیا وەڵامی GET بداتەوە. هەر تر دەبێت 405 و Allow: GET وەربگرێت. بە GET، POST و DELETE تاقیی بکەرەوە.
Hintئاماژە
Check request.method before you build the JSON; new Response(body, { status, headers }) sets both.
پێش دروستکردنی JSONـەکە request.method بپشکنە؛ new Response(body, { status, headers }) هەردووکیان دادەنێت.
Show answerوەڵامەکە پیشان بدە
// hello-get-only.mjs - /hello answers only GET; other methods get 405
export default {
async fetch(request) {
const url = new URL(request.url);
if (url.pathname === '/hello') {
if (request.method !== 'GET') {
return new Response('Method Not Allowed', { status: 405, headers: { allow: 'GET' } });
}
const name = url.searchParams.get('name') ?? 'world';
return Response.json({ message: `Hello, ${name}!` });
}
return new Response('Not found', { status: 404 });
},
};import fn from './hello-get-only.mjs';
for (const method of ['GET', 'POST', 'DELETE']) {
const res = await fn.fetch(new Request('https://example.com/hello?name=Dilan', { method }));
console.log(method.padEnd(6), res.status, res.headers.get('allow') ?? '-', await res.text());
}GET 200 - {"message":"Hello, Dilan!"}
POST 405 GET Method Not Allowed
DELETE 405 GET Method Not AllowedOutput of node test-get-only.mjs (Node.js 24.14).
node test-get-only.mjs (Node.js 24.14).
Find the bug: let visits = 0; export default { fetch() { visits++; return Response.json({ visits }); } }; is used as the visitor counter of a school website.
بدۆزەرەوە: let visits = 0; export default { fetch() { visits++; return Response.json({ visits }); } }; وەک سەردانکەرانی قوتابخانەیەک بەکار دەهێنرێت.
Show answerوەڵامەکە پیشان بدە
Each execution environment has its own visits, starting at 0 at its cold start, and the number disappears when the environment is removed. Two visitors can both see 1, and the count falls back after a quiet night. Store the count in a database and add 1 there with one UPDATE.
هەر visitsـی خۆی هەیە کە لە لە 0ـەوە دەست پێ دەکات و کاتێک ژینگەکە لادەبرێت ژمارەکە نامێنێت. دوو سەردانکەر دەتوانن هەردووکیان 1 ببینن و دوای شەوێکی بێدەنگ ژمارەکە دەگەڕێتەوە دواوە. ژمارەکە لە هەڵبگرە و بە یەک UPDATE لەوێ 1ـی بۆ زیاد بکە.
An edge function runs 12 queries on a database in Frankfurt for every page. Visitors in Erbil and in Sydney both complain that pages are slow. Why, and what would you change?
بۆ هەر 12 لەسەر لە فرانکفۆرت جێبەجێ دەکات. سەردانکەران لە هەولێر و لە سیدنی هەردووکیان سکاڵا دەکەن کە خاون. بۆچی و چی دەگۆڕیت؟
Show answerوەڵامەکە پیشان بدە
The function runs near each visitor, but each of the 12 queries travels to Frankfurt and back, so the far trip is paid 12 times. Run that function in a region next to the database (or a regional serverless function), send fewer queries (one query that returns everything), or cache answers at the edge.
نزیک لە هەر سەردانکەرێک کار دەکات، بەڵام هەر یەک لە 12 دەچێت بۆ فرانکفۆرت و دەگەڕێتەوە، بۆیە گەشتە دوورەکە 12 جار دەدرێت. ئەو لە ناوچەیەکی تەنیشت کار پێ بکە ( بێڕاژەکاری ناوچەیی)، کەمتر بنێرە (یەک کە هەموو شتێک بگەڕێنێتەوە)، یان لە لێوار لە هەڵبگرە.
Summaryپوختە
- Serverless computing: servers still exist, but the provider runs and scales them; FaaS runs single functions per event and bills per request and time.
- SQLite's serverless (no database server program) is a different meaning from the cloud's.
- Functions run because of events (HTTP, uploads, queues, timers, database changes) connected by triggers; the fetch-style handler takes a
Requestand returns aResponse. - A cold start prepares a new execution environment; warm starts reuse it. Code outside the handler runs once per environment; never keep data in variables.
- Limits: time, memory, a temporary disk and no lasting state. Pricing: per request and GB-second, with free tiers; set a budget alert.
- Edge functions run in a CDN's edge locations near the visitor: good for redirects, access checks, A/B tests and small APIs; not for heavy work or many far queries. They are not IoT edge computing, which runs on the device.
- : هەر هەن، بەڵام دابینکەر کاریان پێدەکات و زیاد و کەمیان دەکات؛ بۆ هەر کار پێدەکات و بەپێی و کات پارە وەردەگرێت.
- بێڕاژەکارـی SQLite (هیچ نییە) واتایەکی جیاوازە لە هی هەور.
- بەهۆی کار دەکەن (HTTP، ، ، ، گۆڕانکاریی ) کە بە دەبەسترێنەوە؛ شێوازی fetch
Requestوەردەگرێت وResponseدەگەڕێنێتەوە. - نوێ ئامادە دەکات؛ دووپاتە بەکاری دەهێننەوە. کۆدی دەرەوەی بۆ هەر ژینگەیەک یەکجار کار دەکات؛ هەرگیز لە هەڵمەگرە.
- سنوورەکان: کات، ، دیسکی کاتی و هیچ دۆخێکی بەردەوام. نرخ: بۆ هەر و GB-چرکەیەک، بە بەشی بێبەرانبەرەوە؛ ئاگادارکەرەوەی بودجە دابنێ.
- لە نزیک لە سەردانکەر کار دەکەن: بۆ ، پشکنینی ، و APIـی بچووک باشن؛ بۆ کاری قورس یان زۆر دوور نا. ئەمانە IoT نین، کە لەسەر ئامێرەکە کار دەکات.
Next: put the whole course together in Course review and practice.
دواتر: هەموو کۆرسەکە لە پێداچوونەوە و ڕاهێنانی کۆرسـدا پێکەوە کۆ بکەرەوە.
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Course review and practiceپێداچوونەوە و ڕاهێنانی کۆرسەکە
Related lecturesوانە پەیوەندیدارەکان
- Cloud Computingهەورەژمێرکاری
- Mobile Cloud and Backend-as-a-Serviceهەورەژمێرکاریی مۆبایل و BaaS
- Cloud Databasesبنکەدراوە هەورییەکان
- Cloud, Fog and Edge Computingهەورەژمێرکاری، ژمێرکاریی تەم و ژمێرکاریی لێوار
- SQLite Basicsبنەماکانی SQLite
- Publishing Your Website: Hosting, Domains and HTTPSبڵاوکردنەوەی تۆڕگەکەت: هۆستینگ، ناوەکانی دۆمەین و HTTPS
- Introduction to PHPسەرەتایەک بۆ PHP
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
- NIST SP 800-145: The NIST Definition of Cloud Computing (2011)
- CNCF: Serverless Whitepaper announcement (definition of serverless computing, 2018)
- SQLite: Serverless (classic and neo-serverless)
- AWS Lambda Developer Guide: What is AWS Lambda?
- AWS Lambda Developer Guide: Understanding the execution environment lifecycle (cold starts)
- AWS Lambda Developer Guide: Lambda quotas
- AWS Lambda pricing
- Amazon CloudFront Developer Guide: Differences between CloudFront Functions and Lambda@Edge
- Cloudflare Workers: How Workers works (V8 isolates)
- Cloudflare Workers: Limits
- Cloudflare Workers: Pricing
- Cloudflare: The Cloudflare global network (cities, latency)
- Vercel: Vercel Functions
- Vercel: Runtimes
- Vercel: Edge Runtime
- Netlify: Edge Functions overview
- Netlify: Edge Functions limits
- Netlify: Functions configuration (regions)
- Supabase: Edge Functions
- Supabase: Edge Functions limits
- Deno Deploy documentation
- MDN: Response
- Node.js: Global objects (fetch, Request, Response)
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.