⚡ Elysia vs Hono vs NestJS vs Encore

So sánh 4 framework backend TypeScript phổ biến — Chọn đúng công cụ cho đúng level

💜 Elysia

Framework cho Bun runtime. Siêu nhanh, type-safe, API gọn gàng. Tối ưu cho performance cực cao.

🔥 Hono

Framework siêu nhẹ (<14KB), chạy trên mọi runtime. Tối ưu cho Edge Computing & serverless.

🐱 NestJS

Framework enterprise-grade, kiến trúc Angular-style. DI, module hóa, ecosystem khổng lồ.

🟢 Encore

Framework cloud-native với Rust runtime. Tự động hóa infra, DevOps & observability.

1. Tổng Quan Nhanh

Trong thế giới backend TypeScript, 4 framework này đại diện cho 4 triết lý phát triển khác nhau. Hiểu rõ từng framework sẽ giúp bạn chọn đúng "vũ khí" cho dự án của mình.

Tiêu chí 💜 Elysia 🔥 Hono 🐱 NestJS 🟢 Encore
Ra đời 2022 2021 2017 2021
Runtime Bun (chính) Mọi runtime Node.js Node.js + Rust
Triết lý Performance-first Portable & Edge Enterprise & Structure Cloud-native & Auto
Bundle size Nhỏ <14KB (tiny) Lớn Trung bình
Type Safety End-to-end ⭐ End-to-end ⭐ TypeScript native End-to-end ⭐
Learning Curve Thấp Rất thấp Cao Trung bình
Community Đang phát triển Phát triển nhanh Rất lớn ⭐ Nhỏ
Stars GitHub ~12K ~22K ~70K ~8K
Phù hợp cho API nhanh, microservices Edge, serverless, API Enterprise, team lớn Cloud-native, startup

2. Elysia — Siêu Nhanh Trên Bun

Elysia được thiết kế chuyên biệt cho Bun runtime, khai thác tối đa tốc độ của JavaScriptCore engine. Nó cung cấp type inference end-to-end mà không cần code generation.

import { Elysia, t } from 'elysia'

const app = new Elysia()
  .get('/', () => 'Hello Elysia! 💜')
  .post('/users', ({ body }) => {
    return { message: `Created user: ${body.name}`, email: body.email }
  }, {
    body: t.Object({
      name: t.String(),
      email: t.String({ format: 'email' })
    })
  })
  .listen(3000)

console.log(`🦊 Elysia running at ${app.server?.hostname}:${app.server?.port}`)

✅ Ưu điểm

  • Hiệu suất cực cao: 250K+ req/s, nhanh hơn Express 5x
  • Type-safe end-to-end: Tự động infer types, không cần codegen
  • API declarative: Syntax chainable, gọn gàng, ít boilerplate
  • Plugin ecosystem: Auth, CORS, Swagger, GraphQL, WebSocket
  • Startup siêu nhanh: Phù hợp serverless, cold start thấp
  • Validation tích hợp: TypeBox/Zod, validate request tự động

❌ Nhược điểm

  • Phụ thuộc Bun: Chưa hỗ trợ tốt Node.js / Deno
  • Ecosystem còn non: Ít thư viện bên thứ 3 hơn Express/Nest
  • Community nhỏ: Ít tutorials, tài liệu ngoài official
  • Bun chưa stable 100%: Một số edge cases còn lỗi
  • Ít dùng trong production lớn: Chưa nhiều case study enterprise
  • Breaking changes: API thay đổi giữa các version

3. Hono — Siêu Nhẹ, Chạy Mọi Nơi

Hono nổi bật với triết lý "Write Once, Run Anywhere". Chỉ <14KB, zero dependencies, chạy trên Cloudflare Workers, Deno, Bun, Node.js, AWS Lambda, Vercel Edge...

import { Hono } from 'hono'
import { cors } from 'hono/cors'
import { jwt } from 'hono/jwt'

const app = new Hono()

app.use('/*', cors())

app.get('/', (c) => c.text('Hello Hono! 🔥'))

app.get('/users/:id', (c) => {
  const id = c.req.param('id')
  return c.json({ id, name: 'John Doe' })
})

app.post('/users', async (c) => {
  const body = await c.req.json()
  return c.json({ message: `Created: ${body.name}` }, 201)
})

export default app // Deploy to any platform!

✅ Ưu điểm

  • Chạy mọi runtime: Cloudflare, Deno, Bun, Node, Lambda, Vercel
  • Siêu nhẹ: <14KB, zero dependencies, cold start cực nhanh
  • Tối ưu Edge: Lý tưởng cho Cloudflare Workers, edge functions
  • Middleware phong phú: Auth, CORS, ETag, JWT, caching built-in
  • RPC mode: Type-safe client-server qua Hono Client (hc)
  • RegExpRouter: Router cực nhanh, nhanh hơn hầu hết framework
  • Dễ học: API quen thuộc kiểu Express, minimal learning curve

❌ Nhược điểm

  • Không opinionated: Tự tổ chức cấu trúc dự án, dễ messy
  • Thiếu DI: Không có Dependency Injection built-in
  • Ít tính năng enterprise: Không có module system, guard, pipe
  • ORM tự chọn: Không tích hợp sẵn database layer
  • Testing tự setup: Không có testing module mặc định
  • Scale codebase khó: Dự án lớn cần convention riêng

4. NestJS — Enterprise-Grade

NestJS là "vua" của thế giới Node.js enterprise. Lấy cảm hứng từ Angular, cung cấp kiến trúc module hóa, DI mạnh mẽ, và ecosystem khổng lồ. Được dùng bởi Netflix, Adidas, Roche.

// users.controller.ts
import { Controller, Get, Post, Body, Param } from '@nestjs/common'
import { UsersService } from './users.service'
import { CreateUserDto } from './dto/create-user.dto'

@Controller('users')
export class UsersController {
  constructor(private readonly usersService: UsersService) {}

  @Get()
  findAll() {
    return this.usersService.findAll()
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.usersService.findOne(+id)
  }

  @Post()
  create(@Body() createUserDto: CreateUserDto) {
    return this.usersService.create(createUserDto)
  }
}

✅ Ưu điểm

  • Kiến trúc rõ ràng: Module, Controller, Service, DTO — separation of concerns
  • DI mạnh mẽ: Dependency Injection giống Spring/Angular, dễ test
  • Ecosystem khổng lồ: GraphQL, WebSocket, Queue, Caching, Auth built-in
  • Community lớn nhất: 70K+ stars, 3M+ weekly downloads, nhiều jobs
  • Testing tuyệt vời: Module testing, e2e testing built-in
  • Swagger auto: Generate API docs tự động
  • Microservices: Hỗ trợ gRPC, Kafka, RabbitMQ, Redis transport

❌ Nhược điểm

  • Learning curve cao: Cần hiểu OOP, DI, Decorators, Module system
  • Verbose / Boilerplate: Nhiều files cho 1 feature đơn giản
  • Performance thấp hơn: Abstraction layers gây overhead
  • Quá nặng cho dự án nhỏ: Overkill cho API đơn giản
  • Debug khó: Stack trace dài, compiled JS khó trace
  • Chậm startup: Khởi tạo module tree mất thời gian

5. Encore — Cloud-Native Tự Động

Encore.ts kết hợp TypeScript + Rust runtime, tự động hóa toàn bộ infrastructure (database, queue, cache, cron). Không cần Terraform, không cần Docker — chỉ code logic.

import { api } from "encore.dev/api"
import { SQLDatabase } from "encore.dev/storage/sqldb"

// Encore tự động provision PostgreSQL!
const db = new SQLDatabase("users", { migrations: "./migrations" })

interface User {
  id: number
  name: string
  email: string
}

// API endpoint — Encore tự tạo routing, docs, tracing
export const getUser = api(
  { method: "GET", path: "/users/:id", expose: true },
  async ({ id }: { id: number }): Promise => {
    return await db.queryRow`SELECT * FROM users WHERE id = ${id}`
  }
)

export const createUser = api(
  { method: "POST", path: "/users", expose: true },
  async ({ name, email }: { name: string; email: string }): Promise => {
    return await db.queryRow`
      INSERT INTO users (name, email) VALUES (${name}, ${email})
      RETURNING *
    `
  }
)

✅ Ưu điểm

  • Tự động infra: DB, queue, cache, cron — chỉ cần khai báo, tự provision
  • Rust runtime: Nhanh gấp 9x Express, latency cực thấp
  • Observability built-in: Distributed tracing, metrics, logging tự động
  • Zero DevOps: Không cần Terraform, Docker, YAML configs
  • Local dev dashboard: Live tracing, API explorer, dependency graph
  • Cloud-agnostic: Deploy AWS/GCP tự động, không vendor lock-in
  • Auto API docs: Generate từ TypeScript types tự động

❌ Nhược điểm

  • Community rất nhỏ: Ít tài liệu, tutorials, StackOverflow answers
  • Opinionated mạnh: Khó customize ngoài convention đã định
  • Lock-in Encore Cloud: Nhiều feature chỉ hoạt động với Encore Cloud
  • Database hạn chế: Chủ yếu PostgreSQL, ít hỗ trợ NoSQL
  • Không có frontend/SSR: Chỉ backend, cần kết hợp framework khác
  • Khó debug deep: Rust runtime là black-box với JS developers

6. Bảng So Sánh Chi Tiết

🏎️ Performance & Runtime

Tiêu chí Elysia Hono NestJS Encore
Requests/s ~250K ⭐ ~150K ~30K ~200K ⭐
Cold start Cực nhanh ⭐ Cực nhanh ⭐ Chậm Nhanh
Memory Thấp Rất thấp ⭐ Cao Thấp
Runtime engine Bun (JSC) Any (Web Standard) Node.js (V8) Node.js + Rust

🛠️ Developer Experience

Tiêu chí Elysia Hono NestJS Encore
Thời gian học 1-2 ngày Vài giờ ⭐ 1-2 tuần 3-5 ngày
Boilerplate Ít ⭐ Rất ít ⭐ Nhiều Ít
API Docs tự động ✅ Swagger plugin ✅ OpenAPI ✅ Swagger decorator ✅ Built-in ⭐
Hot reload ✅ Bun --watch ✅ Tùy runtime ✅ Webpack HMR ✅ Built-in
Dev Dashboard ✅ ⭐

🏗️ Architecture & Scalability

Tiêu chí Elysia Hono NestJS Encore
Architecture Flexible Minimal Opinionated ⭐ Opinionated
DI (Inject) ❌ Tự implement ❌ Không có ✅ Built-in ⭐ ✅ Built-in
Microservices ✅ Manual ✅ Manual ✅ Built-in ⭐ ✅ Built-in ⭐
Database Tự chọn ORM Tự chọn ORM TypeORM/Prisma PostgreSQL tích hợp ⭐
Infra as Code ✅ Built-in ⭐
Observability ❌ Tự setup ❌ Tự setup ✅ Plugin ✅ Built-in ⭐

7. Khi Nào Dùng Framework Nào?

💜 Chọn Elysia khi:
• Cần performance tối đa (real-time, gaming, chat)
• Đã sử dụng hoặc muốn adopt Bun runtime
• Xây dựng API/microservices nhẹ, cần startup nhanh
• Thích syntax declarative, type-safe mà ít boilerplate
• Dự án side project hoặc startup tốc độ phát triển nhanh

🔥 Chọn Hono khi:
• Deploy trên edge (Cloudflare Workers, Vercel Edge Functions)
• Cần framework chạy trên nhiều runtime khác nhau
• Xây dựng serverless functions, Lambda handlers
• Muốn bundle size siêu nhẹ, cold start gần bằng 0
• Migrate dần từ Express sang framework hiện đại

🐱 Chọn NestJS khi:
• Dự án enterprise, team 5+ developers
• Cần kiến trúc rõ ràng, enforce coding patterns
• Hệ thống phức tạp: microservices, GraphQL, WebSocket, Queue
• Cần community lớn, nhiều tài liệu, dễ tuyển dụng
• Long-term maintenance, codebase sống 3-5+ năm

🟢 Chọn Encore khi:
• Startup cần ship nhanh mà không muốn lo DevOps
• Muốn infra tự động: database, queue, cache, cron
• Cần observability (tracing, metrics) mà không setup phức tạp
• Xây dựng hệ thống cloud-native distributed
• Team nhỏ muốn productivity cao nhất

8. So Sánh Code: Cùng 1 API

Cùng xem cách mỗi framework xử lý một GET endpoint đơn giản:

// ═══ ELYSIA ═══
import { Elysia } from 'elysia'
new Elysia()
  .get('/hello/:name', ({ params }) => `Hello ${params.name}!`)
  .listen(3000)

// ═══ HONO ═══
import { Hono } from 'hono'
const app = new Hono()
app.get('/hello/:name', (c) => c.text(`Hello ${c.req.param('name')}!`))
export default app

// ═══ NESTJS ═══
// hello.controller.ts
@Controller('hello')
export class HelloController {
  @Get(':name')
  getHello(@Param('name') name: string) {
    return `Hello ${name}!`
  }
}
// + hello.module.ts, app.module.ts, main.ts ...

// ═══ ENCORE ═══
import { api } from "encore.dev/api"
export const hello = api(
  { method: "GET", path: "/hello/:name", expose: true },
  async ({ name }: { name: string }) => `Hello ${name}!`
)

📝 Nhận xét:

Elysia & Hono — Code ngắn gọn nhất, chỉ 3-4 dòng là xong. Phù hợp khi cần prototype nhanh.

NestJS — Cần nhiều files nhất (controller + module + main), nhưng structure rõ ràng cho team lớn.

Encore — Ngắn gọn + tự động generate routing, docs, tracing mà không cần config thêm.

9. Lời Khuyên Theo Level

🌱 Fresher / Beginner (0-1 năm)

Nên bắt đầu với: Hono hoặc Elysia

  • Hono — API giống Express nên dễ tiếp cận, chạy mọi nơi, tài liệu dễ hiểu. Bạn chỉ cần biết JS/TS cơ bản là bắt đầu được.
  • Elysia — Syntax rất gọn, validation tích hợp giúp học cách xây API đúng cách ngay từ đầu. Cài Bun rất nhanh.
  • ⚠️ Tránh NestJS lúc này — Decorators, DI, module system sẽ gây overwhelm. Hãy nắm vững HTTP basics trước đã.

🚀 Junior (1-2 năm)

Nên thử: Elysia hoặc Hono cho dự án cá nhân, bắt đầu tìm hiểu NestJS

  • Elysia/Hono — Dùng để build side projects, API nhanh, học TypeScript sâu hơn.
  • NestJS — Bắt đầu tìm hiểu DI pattern, module hóa, decorators. Đây là kiến thức quan trọng cho career growth.
  • Mục tiêu: Hiểu sự khác biệt giữa minimalist vs opinionated framework.

💪 Mid-Level (2-4 năm)

Nên master: NestJS + thử Encore

  • NestJS — Master framework này mở ra nhiều cơ hội công việc. Hiểu sâu DI, Guards, Interceptors, Pipes, Microservices.
  • Encore — Thử build side project để hiểu về cloud-native, distributed systems, observability.
  • Elysia/Hono — Dùng cho internal tools, microservices cần performance cao.

🎯 Senior / Lead (4+ năm)

Nên biết tất cả, chọn đúng tool cho đúng bài toán:

  • NestJS — Cho hệ thống enterprise, team lớn, cần standardize architecture.
  • Elysia — Cho microservices cần performance cực cao, real-time systems.
  • Hono — Cho edge computing, serverless, cần deploy multi-platform.
  • Encore — Cho startup cần ship nhanh, MVP cloud-native, giảm operational overhead.
  • Nguyên tắc: Không có framework tốt nhất — chỉ có framework phù hợp nhất cho context cụ thể.

10. Kết Luận

Bạn muốn... Chọn
Performance tối đa trên Bun 💜 Elysia
Nhẹ nhất, chạy mọi nơi, edge 🔥 Hono
Enterprise, team lớn, career 🐱 NestJS
Cloud-native, zero DevOps 🟢 Encore
Học nhanh, prototype 🔥 Hono hoặc 💜 Elysia
Nhiều jobs, dễ tuyển dụng 🐱 NestJS
Startup MVP siêu nhanh 🟢 Encore hoặc 💜 Elysia

💡 Lời khuyên cuối cùng:

Đừng chạy theo hype. Hãy chọn framework dựa trên 3 yếu tố:

1️⃣ Bài toán: Dự án cần gì? Performance? Structure? Auto infra?
2️⃣ Team: Mấy người? Kinh nghiệm ra sao? Dễ tuyển dụng không?
3️⃣ Tương lai: Dự án sống bao lâu? Community có bền vững không?

Với Fresher — hãy bắt đầu từ Hono hoặc Elysia.
Với Mid/Senior — NestJS là phải biết, còn lại tùy context.
Với Startup — Encore là game-changer nếu muốn ship nhanh.