Retrieved article excerpt
Open article · Retrieved 2026-11-09T18:22:12.014381+00:00
ℵ
# A language for agents to write backends that *scale safely.*
Every Aleph route declares what it can read, write, and compute, and anything unbounded is rejected before it ships. So an app can’t flood your database or spike CPU and memory. Auth, databases, queues, and more are built in, and many apps can share one runtime. [See how the language works in depth.](https://www.aleph-lang.com/docs/programming-model/)
Write TypeScript. Run on Rust.
Infra protectionBuiltin guardrailsExactly once by defaultBuilt in the languageShared infra & reduced costsWrite in TS, execute in Rust↻
a typical backendusersquery · no limit40 rows180 rows420 rows700 rows1,000 rowswith alephyour codealeph checkquery · limit 2020 rowsserverdb
aleph · app.ts↻
app.ts
accepted
24a.route("GET /posts")
25 .query({ cursor: t.cursor() })
26 .handle((\_, { query }) => {
27 const page = Post.page({ limit: 20, after: query.cursor });
28 return {
29 next: page.cursor,
30 posts: page.items.map((post) => ({
31 post,
32 comments: Comment.query({ prefix: [post.postId], limit: 5 }),
33 })),
34 };
35 });
24a.route("GET /posts")
25 .query({ cursor: t.cursor() })
26 .handle((\_, { query }) => {
27 const page = Post.page({ limit: 20, after: query.cursor });
28 return {
29 next: page.cursor,
30 posts: page.items.map((post) => ({
31 post,
32 comments: Comment.query({ prefix: [post.postId], limit: 5 }),
33 })),
34 };
35 });
typical node + express
server.ts
accepted
1app.get("/posts", async (req, res) => {
2 const { rows: posts } = await db.query("SELECT \* FROM posts");
3 const out = [];
4 for (const post of posts) {
5 const { rows } = await db.query("SELECT \* FROM comments WHERE post\_id = $1", [post.id]);
6 out.push({ post, comments: rows });
7 }
8 res.json(out);
9});
two roads to production
general-purposeCPU /memoryalertDBloadtests,CI,deploysslowresponseshugebillaleph✔ auth✔ transactions✔ retries✔ scaling✔ migrations✔ API docs✔ isolation
General-purpose code steers around what can go wrong in production. Aleph rules it out and builds the rest into the road.
Why Aleph
## Less flexibility, *on purpose.*
General-purpose languages let an app do anything. So every app needs its own isolated runtime, like a Lambda function, a Docker container, or a VPS, plus its own review and its own guardrails, and someone has to set up and maintain all of it.
Aleph makes the opposite trade. It gives up some flexibility for shared building blocks for what every backend needs, predictable behavior, and code that’s trusted by default. When agents write the code, that trade matters more than ever: a narrow language is easy to check and hard to get wrong. [How Aleph programs work](https://www.aleph-lang.com/docs/programming-model/)
Usage limits
## Aleph knows what your code can use before it runs
Aleph code is declarative. A route isn’t a program that can do anything. It’s a fixed plan of queries, loops, and writes, each with a known maximum size. So Aleph can count, before a single request runs, the most work any piece of logic can ever do: the rows it reads, the rows it writes, the operations it runs, and the memory it uses.
1. **Counted**Every route, trigger, and job gets its worst-case usage, computed from its code.
2. **Checked**Code that could use too much, like a query that reads too many rows or a loop with no end, doesn’t build. A meter enforces the same limits while it runs.
3. **Shared**No app can take the CPU, memory, or database that other apps need, so many apps can run safely in one process, on one database.
4. **Cheaper**Servers and databases aren’t set aside for each app and left idle, so each app costs far less to run.
worst case of every route↻
app.ts
24a.route("GET /posts")
25 .query({ cursor: t.cursor() })
26 .handle((\_, { query }) => {
27 const page = Post.page({ limit: 20, after: query.cursor });
28 return {
29 next: page.cursor,
30 posts: page.items.map((post) => ({
31 post,
32 comments: Comment.query({ prefix: [post.postId], limit: 5 }),
33 })),
34 };
35 });
24a.route("GET /posts")
25 .query({ cursor: t.cursor() })
26 .handle((\_, { query }) => {
27 const page = Post.page({ limit: 20, after: query.cursor });
28 return {
29 next: page.cursor,
30 posts: page.items.map((post) => ({
31 post,
32 comments: Comment.query({ prefix: [post.postId], limit: 5 }),
33 })),
34 };
35 });
$ aleph check app.ts
✔ valid. The most each route and handler can use in one run:
route reads writes ops bytes read effects calls memory
limit 250 50 2,000 2 MB 50 3 8 MB
add\_comment 1 <1% 1 2% 8 <1% 3.5 KB <1% 1 2% 0 – 14.2 KB <1%
create\_post 1 <1% 1 2% 489 24% 3.1 KB <1% 0 – 0 – 138.0 KB 2%
get\_posts 120 48% 0 – 192 10% 416.1 KB 20% 0 – 0 – 3.02 MB 38%
$ aleph check app.ts
✔ valid. The most each route and handler can use in one run:
route reads writes ops bytes read effects calls memory
limit 250 50 2,000 2 MB 50 3 8 MB
add\_comment 1 <1% 1 2% 8 <1% 3.5 KB <1% 1 2% 0 – 14.2 KB <1%
create\_post 1 <1% 1 2% 489 24% 3.1 KB <1% 0 – 0 – 138.0 KB 2%
get\_posts 120 48% 0 – 192 10% 416.1 KB 20% 0 – 0 – 3.02 MB 38%
A page of 20 posts, 5 comments each, and a cursor for the next page: at most 120 reads. Ask for 10,000 at once and it won't build.
Guardrails
## No query can read too much
Every query has a limit, and Aleph multiplies them out: a page of 20 posts with 5 comments each is at most 120 reads, before a single request runs.
So the natural way to return a long list is the right one: a page and a cursor. Ask for everything at once and it’s rejected before it ships, with the line to change. The same limits are enforced while it runs, so a limit is a guarantee, not a guess.
a loop inside a loop↻
app.ts
37a.route("POST /posts")
38 .id("create\_post")
39 .body({
40 title: t.string().min(1).max(200),
41 tags: t.array(t.string().max(32), 10),
42 })
43 .status(201)
44 .handle((\_, { body }) =>
45 Post.insert({
46 title: body.title,
47 tags: body.tags.filter((tag) =>
48 body.tags.filter((other) => other.eq(tag)).length.eq(1)),
49 }));
37a.route("POST /posts")
38 .id("create\_post")
39 .body({
40 title: t.string().min(1).max(200),
41 tags: t.array(t.string().max(32), 100),
42 })
43 .status(201)
44 .handle((\_, { body }) =>
45 Post.insert({
46 title: body.title,
47 tags: body.tags.filter((tag) =>
48 body.tags.filter((other) => other.eq(tag)).length.eq(1)),
49 }));
$ aleph check app.ts
✔ valid. The most each route and handler can use in one run:
route reads writes ops bytes read effects calls memory
limit 250 50 2,000 2 MB 50 3 8 MB
create\_post 1 <1% 1 2% 489 24% 3.1 KB <1% 0 – 0 – 138.0 KB 2%
$ aleph check app.ts
✖ over\_budget at app.ts:44:4 (routes[1].plan)
route "create\_post" can use up to 40809 ops in the worst case, over the limit of 2000. Lower the bounds that drive it (query limits, list sizes) or split the work.
2 problems
Comparing every tag with every other: 10 tags is 489 ops. Allow 100 and it's 40,809, over the limit of 2,000.
Guardrails
## No loop can run away
There’s no unbounded `while` loop and no recursion. Every loop runs over a list with a known maximum size, or declares its own maximum, so even a loop inside a loop has a worst case Aleph can count.
That’s why one app can’t burn the CPU that other apps share: code that could doesn’t build.
more than routes↻
app.ts
1import { app, t } from "@aleph-lang/sdk";
2
3const a = app("blog"); // the app everything is declared on
4
5const Post = a.entity("Post", {
6 key: ["postId"],
7 fields: {
8 postId: t.id().generated(),
9 title: t.string().min(1).max(200),
10 tags: t.array(t.string().max(32), 10),
11 },
12});
13
14const Comment = a.entity("Comment", {
15 key: ["postId", "commentId"],
16 fields: {
17 postId: t.string().max(26),
18 commentId: t.id().generated(),
19 authorId: t.string().max(64),
20 text: t.string().min(1).max(500),
21 },
22});
23
24a.route("GET /posts")
25 .query({ cursor: t.cursor() })
26 .handle((\_, { query }) => {
27 const page = Post.page({ limit: 20, after: query.cursor });
28 return {
29 next: page.cursor,
30 posts: page.items.map((post) => ({
31 post,
32 comments: Comment.query({ prefix: [post.postId], limit: 5 }),
33 })),
34 };
35 });
36
37a.route("POST /posts")
38 .id("create\_post")
39 .body({
40 title: t.string().min(1).max(200),
41 tags: t.array(t.string().max(32), 10),
42 })
43 .status(201)
44 .handle((\_, { body }) =>
45 Post.insert({
46 title: body.title,
47 tags: body.tags.filter((tag) =>
48 body.tags.filter((other) => other.eq(tag)).length.eq(1)),
49 }));
50
51a.route("POST /posts/:postId/comments")
52 .id("add\_comment")
53 .params({ postId: t.string().max(26) })
54 .body({ text: t.string().min(1).max(500) })
55 .status(201)
56 .handle(($, { params, body }) =>
57 Comment.insert({
58 postId: params.postId,
59 authorId: $.caller,
60 text: body.text.trim(),
61 }));
62
63// An external HTTP API. "call" waits for the answer.
64// Each call counts toward the limit.
65const moderation = a.integration("moderation", {
66 provider: "http",
67 operations: {
68 check: {
69 mode: "call",
70 input: { text: t.string().max(500) },
71 output: { spam: t.bool() },
72 },
73 },
74});
75
76// Email. "effect" is sent after commit,
77// exactly once.
78const email = a.integration("email", {
79 provider: "email",
80 operations: {
81 send: {
82 mode: "effect",
83 input: { to: t.string().max(200), subject: t.string().max(200) },
84 },
85 },
86});
87
88// A live channel that clients subscribe to, per post.
89const live = a.channel("comments", {
90 key: { postId: t.string().max(26) },
91 message: { text: t.string().max(500) },
92});
93
94// A trigger: runs after each new comment commits,
95// in the background. The request doesn't wait.
96a.onInsert("moderate", Comment, ($, { payload }) => {
97 const comment = payload.after;
98 const verdict = moderation.call("check", { text: comment.text });
99 // Delete spam; push everything else live.
100 $.if(verdict.spam)
101 .then(() => comment.delete())
102 .else(() =>
103 live.publish({ postId: comment.postId }, { text: comment.text }));
104});
105
106// A schedule: every Monday at 09:00.
107a.every("weeklyDigest", "mon 09:00", ($) => {
108 const posts = Post.query({ limit: 10, order: "desc" });
109 email.send("send", {
110 to: "[email protected]",
111 subject: $.fmt`${posts.length} new posts`,
112 });
113});
114
115export default a;
1import { app, t } from "@aleph-lang/sdk";
2
3const a = app("blog"); // the app everything is declared on
4
5const Post = a.entity("Post", {
6 key: ["postId"],
7 fields: {
8 postId: t.id().generated(),
9 title: t.string().min(1).max(200),
10 tags: t.array(t.string().max(32), 10),
11 },
12});
13
14const Comment = a.entity("Comment", {
15 key: ["postId", "commentId"],
16 fields: {
17 postId: t.string().max(26),
18 commentId: t.id().generated(),
19 authorId: t.string().max(64),
20 text: t.string().min(1).max(500),
21 },
22});
23
24a.route("GET /posts")
25 .query({ cursor: t.cursor() })
26 .handle((\_, { query }) => {
27 const page = Post.page({ limit: 20, after: query.cursor });
28 return {
29 next: page.cursor,
30 posts: page.items.map((post) => ({
31 post,
32 comments: Comment.query({ prefix: [post.postId], limit: 5 }),
33 })),
34 };
35 });
36
37a.route("POST /posts")
38 .id("create\_post")
39 .body({
40 title: t.string().min(1).max(200),
41 tags: t.array(t.string().max(32), 10),
42 })
43 .status(201)
44 .handle((\_, { body }) =>
45 Post.insert({
46 title: body.title,
47 tags: body.tags.filter((tag) =>
48 body.tags.filter((other) => other.eq(tag)).length.eq(1)),
49 }));
50
51a.route("POST /posts/:postId/comments")
52 .id("add\_comment")
53 .params({ postId: t.string().max(26) })
54 .body({ text: t.string().min(1).max(500) })
55 .status(201)
56 .handle(($, { params, body }) =>
57 Comment.insert({
58 postId: