[{"content":" Before you read: every number here comes from a command I ran on this machine on 2026-10-11 \u2014 git log, wc -l, go.mod, xdev --version, \/usr\/bin\/time -l. I wrote the commands into the text so you can argue with them. Nothing is estimated unless I say it is.\nI already wrote the story of the first seven days. This is the different story: what happened after the origin myth \u2014 the whole arc, from the first commit to the 743rd, and what the thing actually is now.\nIf you only want one fact: the first commit is 2026-09-09 and it is a document, not a program.\n1) Day one started with reading, not coding 2026-09-09 10:36 dcf378d docs: initial PRD, README, and omp\/pi Go-rebuild research 2026-09-09 11:29 05b9352 docs: extend PRD\/README to full omp feature parity; add M9-M14 issues 2026-09-09 13:06 7e516be docs: fix stale non-goal \u2014 theme engine is in scope (M12 CORE) 2026-09-09 13:40 ba1b809 docs: Claude Code cross-check \u2014 research, verdicts, and evidence 2026-09-09 15:22 000a14c docs: second-wave cross-harness research \u2014 omp\/pi\/CC\/opencode\/hermes internals 2026-09-09 17:27 a024b62 feat: MVP \u2014 providers, session core, agent loop, 4 core tools, print mode Six documentation commits before the first line of Go. That was not virtue, it was fear. I had just spent weeks reading that my own daily tools were 200 MB binaries wrapping a JS runtime, and the temptation was to start typing immediately and be proud of a main.go. What I did instead was write down what each of the five peer harnesses actually does \u2014 pi, omp, Claude Code, opencode, Hermes \u2014 with a verdict per feature: port, port differently, reject. All of it landed in docs\/research\/, which is now 29 documents.\nBy that evening there was a working MVP: providers, session core, agent loop, four tools, print mode. One more commit opened the TUI. A month later, that research directory is the single reason the project did not become a pile of one-off decisions.\n2. The first four days are a third of the project Here is the actual rhythm of the thing, from git log --format='%ad' --date=short | sort | uniq -c:\nRead that chart carefully, because it is the story:\nDay 1 (11 commits). Research, PRD, MVP, TUI. Milestones M0\u2013M4 \u2014 skeleton, provider layer, session core, agent loop, terminal UI \u2014 closed the same day. Days 2\u20134 (24, 116, 132 commits). M5\u2013M15 closed on 2026-09-11 and 2026-09-12: compaction and failover, RPC mode, subprocess extensions, the memory-hardening audit, model resolution and auth, session UX, the agent system, memory and skills, the extended tool set, the v2 modes, and the full-parity tail. Days 5\u201313. The field-driven pass: I used the thing daily, and every annoyance got fixed the day it annoyed me (more on this in \u00a73). Days 14\u201318. The flat week \u2014 4 commits, then 1. I was not working on xdev. Worth mentioning, because retrospectives usually delete this part. Days 20\u201332. The daily-driver pass: TUI polish, multi-session tabs, the sidebar, and on the last day the Telegram gateway. 283 of 743 commits landed in the first four days. That is 38% of the project in 12% of the calendar. Then the shape changes completely: no more big bang, just 4 to 30 commits a day of nervous small fixes in a UI I was using for hours at a time.\nThe longest gap between two commit days is three days. Zero Revert &quot; commits in the entire history, which is what a repo looks like when the research was done first.\n3. The device that made this possible: the PRD as a diary Here is the process fact I am proudest of, and it is measurable:\nCommits that touch docs\/PRD.md 364 &hellip;of those, commits that also touch a .go file 266 *Last updated:* stamps inside the PRD 466 Mentions of &ldquo;user report&rdquo; in the PRD 23 Total PRD length 3,508 lines The rule was simple and absolute, and it is written into CONTRIBUTING.md:\nAny change to scope, architecture or status updates docs\/PRD.md in the same commit.\nNot &ldquo;in the same PR&rdquo;. In the same commit. So when I run git log -- docs\/PRD.md I get a diary, and when I read a stamp like this one, the bug is still readable months later:\n*Last updated: 2026-10-06 (fix\/stop-at-the-report \u2014 user report: &#34;my xdev alwasy in the overthinking mode which is for the simple task or just research task...&#34;):* the symptom was one bug; the deepdive turned it into three Twenty-three of those stamps quote me, verbatim, being annoyed at my own tool. That is the highest-value artifact in the repository \u2014 higher than the code, because the code I can rewrite, and the reason I wrote it I cannot reconstruct.\nIt also keeps the milestone table honest. The PRD \u00a74 table has one row per milestone M0\u2013M15, with scope, exit criterion, status, and the issue numbers. There is no TASKS.md in the repo, on purpose: tasks are GitHub issues, the PRD is a status summary. 194 issues are open right now, mostly P2 breadth.\n4. What it is made of $ find . -name &#39;*.go&#39; -not -path &#39;.\/.worktrees\/*&#39; | wc -l 816 $ # non-test lines 128,179 $ # test lines 102,085 $ find . -name &#39;*_test.go&#39; | wc -l 458 44% of the Go in this repo is tests. 458 test files against 358 source files. For a project where &ldquo;does it still work&rdquo; is answered by looking at a terminal, that ratio is the whole safety net.\ngo.mod has seven direct dependencies: tcell, go-runewidth, the official MCP Go SDK, golang.org\/x\/sys, golang.org\/x\/term, yaml.v3, and modernc.org\/sqlite (used in exactly one file, to read Cursor&rsquo;s local IDE state for xdev connect cursor). No CGO, so CGO_ENABLED=0 cross-compiles to six platforms from one machine. Everything else \u2014 git, rg, fd, ast-grep, gh, python3, \/usr\/bin\/security \u2014 is shelled out to and probed, never required.\nAnd the numbers I re-measured today, on the installed release:\nBinary 21.8 MB xdev --version, median of 5 12 ms Peak RSS for that run 21.0\u201321.6 MB (footprint 11.1\u201311.4 MB) Same measurement, omp \/ Claude Code \/ opencode 198.6 MB \/ 229.5 MB \/ 171.9 MB A month in, the gap held. That was the hypothesis I was testing on day 1, and it survived contact with 743 commits of feature work \u2014 because the constraint was enforced in code, not in intent:\n\/\/ internal\/memlimit const DefaultLimitBytes = 100 &lt;&lt; 20 \/\/ hard worst-case ceiling: 100 MB const HighPressure = 0.85 \/\/ live heap fraction that forces compaction 5. One turn, end to end This is what actually runs when you type something. Every box is a real file.\nFour things in that diagram are decisions I would defend in a review:\nThe tool batch is genuinely concurrent, and order is restored after the join. internal\/agent\/loop.go runs one goroutine per tool call under a semaphore of 6 (MaxToolWorkers = 6, which the PRD budgets as &ldquo;~4\u20138&rdquo;). Then, after wg.Wait() and on the single goroutine, it walks the results in model order to feed the repeat-call guard. That ordering is deliberate: the loop the guard exists to catch is a sequence of calls as the model wrote them, not as my workers happened to finish them.\nCompaction has multiple triggers, and two of them ignore tokens entirely. The token trigger fires at the context window minus a reserve, where the reserve is at least 20% of the window \u2014 so ~80% is where a 200k session compacts. internal\/agent\/compact.go adds two more: a heap-pressure trigger at 85% of that 100 MB limit (so a runaway transcript degrades into &ldquo;compact now&rdquo; instead of being OOM-killed), and an idle trigger. Behind them sits a ladder \u2014 threshold, overflow, promotion are the triggers; handoff, snapcompact, shake, soft are the products, and the first one that yields a retained context wins. snapcompact, shake and soft are deterministic: no model call, so they work offline. remote is a documented no-op that says so instead of dressing a local summary up as a provider-native one.\nThe session is append-only, and the leaf is a pointer. Not one entry is ever mutated. A fork moves a pointer; context is rebuilt by walking parent links; jq reads the file. This is the one design decision I ported wholesale from pi\/omp&rsquo;s data model rather than reinventing, and the interop test in internal\/session\/interop_test.go runs against a real omp session fixture to keep the format honest. xdev -from-claude and -from-codex import another harness&rsquo;s transcript and continue it.\nBounded everything, including the load path. The M8 audit measured a 50k-entry session loading to a 130 MB heap \u2014 over budget. The fix (ce8fcae, 2026-09-11) was windowed materialization: entries before the latest reset or compaction boundary are dropped at load, indexes are rebuilt in batches, and the file on disk is untouched. The bound is on memory, not on history.\nThe system prompt next to all of this is deliberately tiny: SystemPromptBase is 1,889 characters (about 470 tokens at the crude 4-chars-per-token estimate), and there is a test that fails if the total prompt plus every tool description crosses 1,000 tokens. It is a gate, not a ruler \u2014 it exists so that growing the prompt requires a conscious PRD amendment instead of happening by accident.\n6. What the tool surface actually is now xdev has 42 subcommands (the map in cmd\/xdev\/main.go) and, today, this many tools the model can call. The core four get the eager schema; the long tail is behind a deferred catalog (tool_search \u2192 tool_describe \u2192 tool_call), which is why the prompt budget above is still possible:\nLayer Tools The eager core read write edit bash Search and structure grep glob ast_grep ast_edit Run things eval (a persistent Python kernel; .ipynb as cell blocks) lsp debug (DAP: dlv, debugpy, lldb-dap) browser (CDP) Reach out web_search github gmail security_scan computer tts generate_image typesafe Delegate task (subagents with their own tool allowlist) hub send_message inbox vibe_status advise propose Remember and undo learn recall retain reflect checkpoint rewind notes new_context Plan and organise todo goal ask schedule_create schedule_list schedule_delete The bridge tool_search tool_describe tool_call Plus anything from an MCP server (the official Go SDK, stdio and HTTP) or a subprocess extension speaking JSONL on stdio with a per-event timeout and SIGKILL. Both land in the same registry as the built-ins, so a foreign tool is policy-gated and output-sunk exactly like bash.\nEight wire formats, so any OpenAI-compatible gateway works: anthropic-messages, openai-completions, openai-responses, azure-openai-responses, openai-codex-responses, google-generative-ai, google-vertex, gemini-cli. Subscriptions work through the browser OAuth flow (xdev login claude), and xdev connect writes from a generated ~200-host catalog so you rarely hand-write a provider block.\n7. The part I did not plan: it moved into my pocket The last cluster of the 743 is the interesting one, because a month of building a terminal UI ended by making the terminal optional:\n2026-10-11 5bd5f1b feat(gateway): register the command menu in the Telegram client (#626) 2026-10-11 77258d2 feat(gateway): format messages for the phone like Hermes does (#625) 2026-10-11 dee214d fix(gateway): a transport error never carries the bot token (#624) 2026-10-11 bc003ec fix(gateway): a 409 no longer kills the daemon (#623) 2026-10-11 53bd7c5 feat(gateway): the Telegram bridge \u2014 background daemon, setup, LeanKG memory (#622) xdev gateway is a background daemon that long-polls Telegram and runs the same agent loop against the same session store, per chat. Five commits, one day, and the four after the first are all defect work:\na 409 from Telegram used to kill the daemon. It shouldn&rsquo;t: Telegram terminates an old long poll when a new getUpdates arrives, so a 409 means someone poked the API \u2014 including me, checking it by hand. So it now paces and continues, and a real rival poller still shows up as a 409 on every poll. a transport error was printing the bot token into the log. model markdown is converted to Telegram&rsquo;s HTML subset rather than MarkdownV2, and falls back to plain text when the parser rejects the parse. the bot registers its command menu, so \/help exists where a user looks for it. This is the part I would not have predicted from the day-1 plan. The harness did not get better because I added features. It got better because I started driving it from places I did not design it for, and the seams held: one session core, one agent loop, one tool registry, and a different front door.\n7.5. How I tested a thing that only exists as text The repo has 12 scripts\/tui-*-drive.py files. They are not unit tests. They drive the real binary in a real pty and assert on the frames it paints \u2014 tab policy, sidebar ink, sticky padding, overlay width, thinking colour, subagent transcripts. Plus scripts\/tui-shot.py, which runs xdev tui in a detached tmux session, asks tmux for the pane with its colors (capture-pane -p -e), repaints that cell grid as an SVG and rasterizes it.\nNothing about the screenshots in this series is mocked up. Every cell came from what the TUI painted.\nThat test layer exists because of a specific class of bug I hit repeatedly: a modal that paints nothing but still eats keystrokes, or a draw path that re-locks a mutex it already holds and freezes the whole UI while the process looks perfectly alive. gh says 194 issues are open right now, and a large share of the closed ones are that shape. When the artifact is text, diffing text is the only review that scales.\n8. Five rules I would keep if I started over Research before main.go. Six doc commits before one line of Go paid for itself all month. Write down what the peer tools actually do, with a verdict per feature \u2014 not &ldquo;they&rsquo;re heavy&rdquo; but &ldquo;they do A, I will do B, because C&rdquo;. One document that must move with the code. Same commit, not same PR. It converts a sprawling history into a readable diary and it is the only reason I can still explain a two-week-old decision. Encode the budget as a failing test. &ldquo;Under 1,000 tokens&rdquo; is a wish. t.Fatalf when it goes over is a constraint. Same for the memory ceiling, same for the theme&rsquo;s mandatory tokens. Bounded everything, and prove it under load. The memory bug that mattered was not in the agent loop; it was in the session loader, at 50k entries. If a queue, a cache, a window or a sink can grow with its input, it will. Fix the shared function once. The gateway&rsquo;s four post-ship commits were all at seams \u2014 the poll loop, the log line, the formatter. That is only possible because there was one of each. 9. What is still not good Saying this is more useful than the numbers:\nThe worst case is not measured. I have not driven a genuine 200k-token session to its floor and watched RSS. The &lt;100 MB is design plus a lot of real sessions, not a proof of the deepest case. The PRD is 3,508 lines and has duplicated sections \u2014 ## 5. Key decisions and ## 6. Links each appear twice. The first time the count went to two was 2026-10-02 (42b235f, a sticky-prompt commit that added 997 lines to the PRD). I know. It is on the list, and there is a diff sitting there that says so. 194 open issues, most of them P2 breadth. Breadth is exactly what I said I would not chase on day 1, and the &ldquo;all of them&rdquo; directive on day 3 re-scoped the skip list. That tension is in the PRD by name, not hidden. No CI gate on pull requests. You run gofmt -l ., go vet .\/..., go test -race .\/... and the six-platform cross matrix yourself. That is a deliberate choice for a single-maintainer repo and it will not survive a second regular contributor. Memory recall is not policy. Recall ranks against the last user turn only, caches for 60 seconds and is capped at ~4 KB \u2014 so a &ldquo;never do X&rdquo; rule that lives only in memory gets truncated or discounted. Standing conventions belong in AGENTS.md or RULES.md. I measured this and wrote the decision down, which is how I found out. 10. Try it curl -fsSL https:\/\/raw.githubusercontent.com\/FreePeak\/xdev\/main\/scripts\/install.sh | sh xdev setup # ~\/.xdev\/agent\/, a starter config, and next steps xdev # the TUI Then xdev connect to reach ~200 hosts with one command, xdev login claude if you have a subscription, or point models.yml at any OpenAI-compatible gateway you already run.\nRepo: github.com\/FreePeak\/xdev \u2014 Apache-2.0, 743 commits, one author, 33 days.\nClosing The first post ended with a question about what a coding tool needs in memory. This one ends with a different observation: five of the last six commits of the 743 are about a Telegram gateway I did not plan on day 1, and the absolute last one is about compaction \u2014 the quiet thing that keeps a long session alive.\nThat is what a full arc looks like, I think. Four days to build the thing you imagined, and then weeks of finding out it wants to be something slightly different \u2014 and keeping the seams clean enough that it can.\n","permalink":"https:\/\/freepeak.github.io\/posts\/xdev-from-day-one-to-where-it-is-now\/","summary":"I wrote the first xdev commit on 2026-09-09 and the 743rd on 2026-10-11. This is everything between: the research-first day, the four-day sprint that closed M0-M15, the weeks where every user report became a PRD stamp, the Telegram gateway, and the numbers I can measure today - 21.8 MB binary, 12 ms startup, 128k lines of Go, 7 direct dependencies.","title":"xdev from day one: 743 commits, 33 days, and what actually shipped"},{"content":" Before you read: every number below I measured on my personal machine (macOS, Apple Silicon) on 2026-09-16, with the command written out. Yours will differ. I am not comparing agent quality \u2014 only weight.\n1) It starts with a stupid question That afternoon I had 3 terminal tabs open: one running omp, one Claude Code, one opencode. All three were &ldquo;thinking&rdquo;.\nI opened htop.\nI sat there looking at the colour bars and asked myself a very stupid question: what does a tool for writing code actually need to keep in memory?\nNot a terminal app. Not an editor. A loop: send text to a model, get text back, call a tool, repeat.\nI answered it, and once I had answered it I couldn&rsquo;t unsee it. So I wrote xdev. 7 days, 403 commits.\nThis is what happened in those 7 days: what I read, what I decided, where I was wrong, and what I measured.\nHere is the thing itself, mid-session \u2014 the real UI, captured from the running program, not a mockup:\n2) Measure first I am not writing this to say the other tools are bad. omp and Claude Code are two things I use daily, and without them I would never have thought about writing my own.\nTheir problem, for me, is not features. It is the price of features.\nHere is what I measured on my machine:\nTool Binary --version (avg of 5) Data dir xdev 20 MB 0.040 s 144 MB omp 186 MB 0.091 s 5.7 GB Claude Code 210 MB 0.060 s 1.1 GB opencode 144 MB 0.358 s 155 MB Binary size: ls -lL ~\/.local\/bin\/xdev. Timing: a 5-iteration loop calling --version, summed with time.time(). I don&rsquo;t have hyperfine, so my numbers are crude \u2014 but crude enough to see the gap.\nThe binary column is the interesting one. omp, Claude Code and opencode are all real Mach-O binaries, not scripts. But run strings on all three and you meet the same relative: bun-v1.4.2, bun-v1.4.3, bun-v1.3.14. What you download is not their program \u2014 it is their program plus an entire JS runtime packed inside.\n20MB versus ~200MB for the same job. This is not a &ldquo;who codes better&rdquo; contest; Go versus TS is not the reason. The reason is whether you need that runtime inside your binary at all, when most of its work is waiting on the network.\n3) Go to school first: pi and omp I did not invent the design. I sat down and read, and after reading I realised I no longer needed to be clever.\npi (github.com\/earendil-works\/pi) is a TypeScript coding agent harness by Mario Zechner, and it is what changed my mind. Its philosophy fits in a few lines I had to sit still after reading:\nA system prompt under 1000 tokens, including tool descriptions. Reason: frontier models are RL-trained to understand coding agents. 10,000 tokens of instructions is dead weight you carry. Exactly 4 core tools: read, write, edit, bash. Four is enough. YOLO by default. No permission theater. Because the read data + execute code + reach the network trifecta cannot be contained by prompting or pattern rules. If you want containment, contain it with a container or a micro-VM, not with a message. No built-in todo tool. Models get confused by state that a tool manages. Want a task list? Write TODO.md. Hand-roll the LLM layer instead of using an SDK. Because the world only has 4 wire APIs that matter: OpenAI Completions, OpenAI Responses, Anthropic Messages, Google GenAI. omp (Oh My Pi) is a fork of pi, and it is what I actually use every day. omp adds a lot of genuinely useful things: a Rust N-API layer for grep\/glob\/AST\/PTY, a shared filesystem-scan cache, an in-process extension system, MCP, a subagent hub, compaction with 6 trigger paths, and a very disciplined session tree.\nThe price: a JS runtime as the floor, extensions loaded in the same process, event queues with no bound, and the whole session living in memory. On my machine ~\/.omp has swollen to 5.7 GB.\nAnd here is the single most important decision of the 7 days, in one line:\nPort the data model. Don&rsquo;t port the code.\nThe JSONL session tree (append-only + one leaf pointer), the unified stream contract, how context is rebuilt, compaction, the OutputSink, the frame-plan TUI \u2014 all of it is design that my own field usage had already stomped on for months. It is correct. My job was to copy the semantics (keeping entry names identical so existing tooling still reads them), not to copy the implementation of the JS era.\nThe research I wrote during those 7 days lives in docs\/research\/: 19 files dissecting omp, pi, Claude Code, opencode, hermes, fx \u2014 with a per-feature verdict table: what to port, what to drop, what to port differently and why. docs\/parity-delta.md records every place I deliberately differ from omp, including the omp flags I accept for compatibility but that mean nothing (like --no-pty, because my bash tool is pipe-based).\n4) Architecture: what I chose, and what I deliberately did not build Module path github.com\/FreePeak\/xdev, Go 1.25, CGO-free, one static binary, exactly 5 direct dependencies (tcell, go-runewidth, the MCP Go SDK, yaml.v3, modernc.org\/sqlite).\nThe session is an append-only JSONL tree with a leaf pointer No entry is ever mutated or deleted. Branching is just moving a pointer. Context is rebuilt by walking parent links. The format is inspectable \u2014 you can jq my session files, and I never had to ship a viewer.\nThis is a semantic port from pi\/omp, and it is the part of the design I sleep best about. Because it allows something a &ldquo;state lives in memory&rdquo; harness cannot: look back and argue with the past.\nEverything is bounded Queues are bounded. Buffers are bounded. The session window is bounded. The output sink is bounded.\nConcretely: debug.SetMemoryLimit(100MB) (overridable with XDEV_MEMLIMIT), and when the live heap reaches 85% of that, the agent forces compaction instead of waiting for the token threshold.\nThe practical meaning: a runaway turn degrades into &ldquo;compact now&rdquo;, not into an OOM kill. Backpressure is a feature, not a bug.\nI measured ~16MB RSS at boot. 30\u201370MB estimated for a normal working session, worst case pinned under 100MB. This is the one number where I admit I have not measured enough: I have not run a genuine 200k-token session to the bottom. The 100MB figure is design plus real tests, not a measurement of the worst case.\n4 core tools, and the rest is optional Prompt + 4 tools sits under 1000 tokens, and here I don&rsquo;t trust my own word \u2014 I test the limit:\n\/\/ cmd\/xdev\/prompt_test.go const maxPromptTokens = 1000 if tokens := len([]rune(got)) \/ 4; tokens &gt;= maxPromptTokens { t.Fatalf(&#34;system prompt is ~%d tokens (budget %d): %d chars across %d tools&#34;+ &#34; \u2014 trim a description or make a deliberate PRD change&#34;, ...) } Estimating tokens as runes \/ 4 is crude. I know. But it is a gate, not a ruler \u2014 its purpose is to force me to amend the PRD consciously every time I want the prompt to grow, instead of letting it grow quietly.\ngrep, glob, lsp, eval, browser, debug, computer, tts, task&hellip; all exist, but they are the layer added after the core 4 already stood. Totals: 544 Go files, ~90k lines excluding tests, ~63k lines of tests \u2014 tests are 41% of the codebase.\nThings I deliberately did not do Saying what you won&rsquo;t do matters more than saying what you did:\nNo permission theater. No popup asking &ldquo;xdev wants to run ls?&rdquo;. YOLO by default, and the harness only documents sandbox patterns (docs\/reference\/container-and-sandbox.md) instead of building a paper wall. No PTY in the bash tool. Pipe-based. omp&rsquo;s --no-pty flag is accepted for script compatibility and is&hellip; a deliberate no-op, recorded in the parity delta. No in-process extension loading. Extensions run as subprocesses talking a JSONL handshake. An extension crashing must not be allowed to kill the agent. What I lose: custom in-process renderers \u2014 an extension only declares a spec (card | table | tree), the host renders it, and a malformed spec degrades to plain text. No claiming to be a clone. omp v18.1.17 ships 131 omp:\/\/ doc pages; I diffed omp --help against xdev -h mechanically and wrote down every gap, with reasons. 5) The TUI: where I spent the most time This is the part I most want to talk about, because it is where I was wrong most often.\ntcell, not bubbletea bubbletea is pretty, easy, well documented. But its Elm model allocates a lot, and in a TUI receiving thousands of streamed tokens per second, allocation churn is exactly what stutter is.\ntcell is rawer, faster, lower-allocation \u2014 and omp&rsquo;s frame-plan model ports cleanly onto it. The trade: you manage everything yourself. I managed everything myself.\nFrame plan: three states of a block Every frame is: mandatory chrome (editor\/status\/HUD\/overlay) + TerminalFramePlan { history?: {id, rows}, viewport: rows[] }.\nAnd transcript blocks have three states:\nState Meaning On resize active still mutable, lives in the viewport redraw settled finalised, can reflow reflow, until capacity pressure committed pushed into the terminal&rsquo;s real scrollback no longer my business The insight I arrived at the expensive way: draw the viewport, not the session. The commit perf(tui): draw the viewport, not the session; trim aged tool output first is the commit I wish I had written on day one.\nResize is the most hateful thing about terminals Alt-screen (?1049h) is only for overlays; for the transcript, any line scrolled off screen goes into the terminal&rsquo;s real scrollback. The reason is simple: once I can no longer see it, there is no reason for it to occupy my RAM.\nThe consequence: when the terminal resizes, my cursor is no longer where I think it is. I have to ask the terminal which row I&rsquo;m on via a DSR anchor and rebuild. DSR-anchor resize recovery was in the PRD from the start, and it is among the most painful lines of text I have ever written.\nThe four TUI bugs I remember Bug 1 \u2014 a real freeze. fix(tui): the tree selector could own the keyboard while painting nothing \u2014 a &quot;frozen TUI&quot; with a live process. A selector that rendered nothing while still holding the keyboard. The user sees a hang; the process is alive. The nasty part: every signal I had for &ldquo;is the process alive&rdquo; said fine.\nBug 2 \u2014 self-deadlock. fix(tui): picker draw must not re-lock a.mu \u2014 self-deadlock hung every draw with content. Drawing re-locked an already-held lock. Hung every frame that had content.\nBug 3 \u2014 a modal that cannot paint must close. fix(tui): a modal that cannot paint must close, and cancel hits the turn. I used to leave the modal open when it couldn&rsquo;t paint. Correct behaviour: if you can&rsquo;t draw it, it disappears. A modal you cannot see but which still eats keystrokes is a trap.\nBug 4 \u2014 the scroll hint painted over content. fix(tui): the scroll hint was painted over the first transcript row. Small. But you see it the first time you open the tool.\nAfter the first three, I added a watchdog: any UI-loop iteration over 5 seconds dumps goroutine stacks to ~\/.xdev\/agent\/dumps\/ (dump capped at 1MB).\nReason: the three hangs I just described, without a dump I could only guess. And guessing about a hung TUI is a waste of time. I happily pay one goroutine to never guess again.\nThe mouse: the thing I redid and redo There is no spec for mouse behaviour in a TUI. There is only a feeling of &ldquo;wrong&rdquo;. And I had to answer that feeling 5 times in 4 hours:\n23:19 fix(tui): Shift hands the drag to the terminal, mid-stroke too 01:07 feat(tui): mouse selection covers the whole screen and stays visible 01:51 feat(tui): one mouse drag can select past the screen 02:19 feat(tui): the modal picker answers the mouse, like omp&#39;s SelectList 02:40 feat(tui): click-to-focus on the live-agent roster The first one stung: the user presses Shift to copy using the terminal&rsquo;s own selection, and I have to release the pointer mid-drag \u2014 even when they&rsquo;re halfway through selecting. No design document teaches you that detail. Only using it does.\nThe last one is funny: I had built an agent roster panel controllable only by keyboard. In a terminal, in 2026.\nThe start screen, and the context dock The start screen is the one place the brand gets to have an opinion \u2014 a pixel wordmark, its binary tagline, and the four real actions with the keys that actually run them. Everything else stays monochrome so the transcript is the only thing competing for attention:\nThe context dock is the answer to &ldquo;where am I in this session?&rdquo;. It is a fixed 42-column panel that only opens when the terminal is wide enough to still leave the transcript its own floor, and its sections are whatever the session actually has in play \u2014 the plan proposal, the task list, the files the diffs touched, the live agents \u2014 each one foldable, and it refuses to rebuild a frame when nothing changed. Here plan mode is armed, so the dock is already carrying its section:\nTheme: 66 colour tokens I ported the Grok CLI theme system (GrokNight\/GrokDay, switching automatically via OSC 11), and made all 66 colour tokens mandatory \u2014 spelled exactly as omp spells them, so an omp theme file paints xdev&rsquo;s chrome unchanged. One token missing is a failing test, not a &ldquo;later&rdquo;.\nI spend all day inside this TUI. Letting it wear the terminal&rsquo;s default colours was not survivable. This is a cost I paid voluntarily, and I think it was worth it.\n6) Testing a thing that only exists as text Sounds silly. But my TUI renders text, and text is not something anyone can diff by eye with discipline.\nSo most of my TUI tests are character-line tests: build a frame on a simulation terminal, then compare the text.\nKeymap (10 tests): every action must resolve, ChordOf must go the right way, a corrupt user keymap file must fall back to defaults rather than crash, \/hotkeys must show every action, and a remap must actually change behaviour. Chrome (15 tests): the status row must say where you are, not list its own keys; the HUD meter must show used\/total of the live context; the session clock must re-base when the session changes, and when there is no anchor it must hide itself rather than display 00:00. Composer: Up\/Down in a multi-line draft must walk visual rows, not logical lines \u2014 obvious until your editor meets a wide character. No hangs: draw_hang_test.go has 5 tests that build frames on a simulation terminal under a timeout \u2014 a selector must not own the keyboard while painting nothing, a modal that cannot paint must close. tree_test.go pins the self-deadlock too: draw must not re-lock the app mutex. The three bugs above, now locked in a cage made of code. 63k lines of tests, many of which only say &ldquo;this line must be identical to yesterday&rdquo;. They cost maintenance. But every time I refactored the renderer, they were the only thing that let me refactor without fear.\n7) The thing models were born to surprise me with One change during the build I&rsquo;m particularly fond of: an unparseable tool call is an error result, not a dead run.\nBefore, if the model returned a tool call whose arguments wouldn&rsquo;t parse, the turn died. That simple, and that stupid.\nAfter: it becomes a tool error that flies back up to the model, and the model fixes it. One error-handling line turned into a self-healing loop. I didn&rsquo;t make the model smarter; I just stopped cutting it off mid-sentence.\nSame idea in edit arg-repair + freshness guard: repair arguments when they&rsquo;re repairable (models are often off-by-one on line numbers), but if the file changed since the agent read it, stop and say so \u2014 don&rsquo;t overwrite.\nThose two are my whole philosophy about harnesses: patch what a machine can patch, stop where patching means losing data.\n8) Three things I learned One: &ldquo;lightweight&rdquo; is not cutting features. It is cutting the runtime.\nxdev ended up with a subagent hub, MCP client, LSP, memory backend, E2E collab, web search, browser over CDP, a DAP debugger. 35 packages under internal\/. I did not cut features. I cut the runtime that came bundled, and pushed the heavy things into child processes.\nTwo: discipline does not live in intention. It lives in tests.\nEvery number I bragged about at the top has something holding it in place. 1000 tokens? prompt_test.go fails if I write longer. 66 colour tokens? m12_test.go. Help must name every subcommand and must not leak @both? usage_test.go \u2014 born after 13 subcommands vanished from the help at the same time.\nDiscipline without a test stops being discipline after 3 days and 100 commits. It becomes a memory.\nThree: don&rsquo;t port code. Port the why.\nWhere I ported both the implementation and the reason, I was fast. Where I ported an implementation without its reason, I spent half a day discovering I had carried along somebody else&rsquo;s decision.\ndocs\/parity-delta.md is therefore worth as much as the code. It is where I wrote: omp does A, I do B, and why B.\n9) Try it if you want curl -fsSL https:\/\/raw.githubusercontent.com\/FreePeak\/xdev\/main\/scripts\/install.sh | sh Then xdev setup to create ~\/.xdev\/agent\/, point models.yml at a gateway you already have, and:\nxdev tui # interactive mode xdev &#34;find every place in this repo that logs a password&#34; xdev --resume 01a0 # resume by session-id prefix xdev bench --turns 5 --model @smol measures TTFT and decode p50\/p95 for your provider \u2014 if you&rsquo;re curious about my numbers.\nRepo: github.com\/FreePeak\/xdev (Apache-2.0).\n10) Closing The question &ldquo;what does a tool for writing code need in memory&rdquo; now has an answer for me: about 16MB, 4 tools, and a session format jq can read.\nThe rest of the 7 days was learning how not to do more than that.\nAnd the other 200MB in the tools you use? Not their fault. They chose breadth over weight, and for a lot of people that choice is right.\nIt&rsquo;s just that this morning I opened 3 terminal tabs that were &ldquo;thinking&rdquo;, looked at htop, and for the first time didn&rsquo;t feel like I was burning RAM to wait for a model to answer.\n","permalink":"https:\/\/freepeak.github.io\/posts\/xdev-how-i-built-a-lightweight-and-fast-agent-coding-cli\/","summary":"I use omp, opencode and Claude Code every day, and I got more and more annoyed by how heavy they are. This is the story of the 7 days I spent writing xdev: reading the pi\/omp architecture, porting the data model to Go, fighting the terminal UI, and the numbers I measured on my own machine \u2014 20MB binary, ~16MB RAM, 40ms startup.","title":"xdev: how I built a lightweight and fast agent coding CLI"},{"content":" N\u00f3i tr\u01b0\u1edbc cho r\u00f5: m\u1ecdi con s\u1ed1 trong b\u00e0i t\u00f4i \u0111o tr\u00ean m\u00e1y c\u00e1 nh\u00e2n (macOS, Apple Silicon) v\u00e0o ng\u00e0y 16\/09\/2026, k\u00e8m \u0111\u00fang c\u00e2u l\u1ec7nh t\u00f4i d\u00f9ng. M\u00e1y b\u1ea1n s\u1ebd ra s\u1ed1 kh\u00e1c. V\u00e0 t\u00f4i kh\u00f4ng so ch\u1ea5t l\u01b0\u1ee3ng agent \u2014 t\u00f4i ch\u1ec9 c\u00e2n \u0111\u1ed9 n\u1eb7ng.\n1) It starts with a stupid question Chi\u1ec1u h\u00f4m \u0111\u00f3 t\u00f4i m\u1edf ba tab terminal: m\u1ed9t tab ch\u1ea1y omp, m\u1ed9t tab Claude Code, m\u1ed9t tab opencode. C\u1ea3 ba \u0111ang &ldquo;ngh\u0129&rdquo;.\nT\u00f4i m\u1edf htop l\u00ean.\nNg\u1ed3i nh\u00ecn m\u1ea5y c\u00e1i thanh m\u00e0u nh\u1ea3y l\u00ean nh\u1ea3y xu\u1ed1ng, t\u00f4i t\u1ef1 h\u1ecfi m\u1ed9t c\u00e2u r\u1ea5t ng\u1edb ng\u1ea9n: m\u1ed9t c\u00f4ng c\u1ee5 \u0111\u1ec3 vi\u1ebft code th\u00ec th\u1eadt ra c\u1ea7n gi\u1eef g\u00ec trong b\u1ed9 nh\u1edb?\nKh\u00f4ng ph\u1ea3i terminal app. C\u0169ng kh\u00f4ng ph\u1ea3i tr\u00ecnh so\u1ea1n th\u1ea3o. Ch\u1ec9 l\u00e0 m\u1ed9t v\u00f2ng l\u1eb7p: g\u1eedi text l\u00ean model, nh\u1eadn text v\u1ec1, g\u1ecdi tool, l\u1eb7p l\u1ea1i.\nT\u00f4i t\u1ef1 tr\u1ea3 l\u1eddi \u0111\u01b0\u1ee3c c\u00e2u \u0111\u00f3. V\u00e0 tr\u1ea3 l\u1eddi xong th\u00ec kh\u00f4ng qu\u00ean \u0111i \u0111\u01b0\u1ee3c n\u1eefa.\nTh\u1ebf l\u00e0 t\u00f4i vi\u1ebft xdev. 7 ng\u00e0y, 403 commit.\nB\u00e0i n\u00e0y k\u1ec3 l\u1ea1i \u0111\u00fang 7 ng\u00e0y \u0111\u00f3: t\u00f4i \u0111\u1ecdc g\u00ec, quy\u1ebft \u0111\u1ecbnh g\u00ec, sai \u1edf \u0111\u00e2u, v\u00e0 \u0111o \u0111\u01b0\u1ee3c g\u00ec.\n\u0110\u00e2y l\u00e0 n\u00f3, \u0111ang ch\u1ea1y gi\u1eefa m\u1ed9t session \u2014 UI th\u1eadt, ch\u1ee5p t\u1eeb ch\u01b0\u01a1ng tr\u00ecnh \u0111ang ch\u1ea1y, kh\u00f4ng ph\u1ea3i mockup:\n2) Measure first, then talk T\u00f4i kh\u00f4ng vi\u1ebft b\u00e0i n\u00e0y \u0111\u1ec3 b\u1ea3o m\u1ea5y tool kia t\u1ec7. omp v\u00e0 Claude Code l\u00e0 hai th\u1ee9 t\u00f4i d\u00f9ng h\u1eb1ng ng\u00e0y; n\u1ebfu kh\u00f4ng c\u00f3 ch\u00fang th\u00ec t\u00f4i \u0111\u00e3 kh\u00f4ng bao gi\u1edd ngh\u0129 t\u1edbi chuy\u1ec7n t\u1ef1 vi\u1ebft m\u1ed9t c\u00e1i.\nV\u1ea5n \u0111\u1ec1 c\u1ee7a ch\u00fang v\u1edbi t\u00f4i kh\u00f4ng n\u1eb1m \u1edf t\u00ednh n\u0103ng. N\u1eb1m \u1edf c\u00e1i gi\u00e1 ph\u1ea3i tr\u1ea3 cho t\u00ednh n\u0103ng.\nS\u1ed1 \u0111o tr\u00ean m\u00e1y t\u00f4i:\nTool Binary --version (TB 5 l\u1ea7n) Data dir xdev 20 MB 0.040 s 144 MB omp 186 MB 0.091 s 5.7 GB Claude Code 210 MB 0.060 s 1.1 GB opencode 144 MB 0.358 s 155 MB C\u1ed9t binary \u0111o b\u1eb1ng ls -lL ~\/.local\/bin\/xdev. C\u1ed9t th\u1eddi gian th\u00ec g\u1ecdi --version 5 l\u1ea7n r\u1ed3i c\u1ed9ng l\u1ea1i b\u1eb1ng time.time(). T\u00f4i kh\u00f4ng c\u00f3 hyperfine, n\u00ean s\u1ed1 th\u00f4 \u2014 nh\u01b0ng th\u00f4 c\u0169ng \u0111\u1ee7 \u0111\u1ec3 th\u1ea5y kho\u1ea3ng c\u00e1ch.\nC\u1ed9t &ldquo;binary&rdquo; m\u1edbi l\u00e0 ch\u1ed7 \u0111\u00e1ng n\u00f3i. omp, Claude Code v\u00e0 opencode \u0111\u1ec1u l\u00e0 binary Mach-O th\u1eadt, kh\u00f4ng ph\u1ea3i script. Nh\u01b0ng strings c\u1ea3 ba th\u00ec g\u1eb7p chung m\u1ed9t h\u1ecd h\u00e0ng: bun-v1.4.2, bun-v1.4.3, bun-v1.3.14. Th\u1ee9 b\u1ea1n t\u1ea3i v\u1ec1 kh\u00f4ng ph\u1ea3i ch\u01b0\u01a1ng tr\u00ecnh c\u1ee7a h\u1ecd \u2014 n\u00f3 l\u00e0 ch\u01b0\u01a1ng tr\u00ecnh c\u1ee7a h\u1ecd c\u1ed9ng th\u00eam c\u1ea3 m\u1ed9t JS runtime b\u1ecb nh\u00e9t v\u00e0o trong.\n20MB v\u1edbi ~200MB, cho c\u00f9ng m\u1ed9t vi\u1ec7c. \u0110\u00e2y kh\u00f4ng ph\u1ea3i cu\u1ed9c thi &ldquo;ai code gi\u1ecfi h\u01a1n ai&rdquo;; Go hay TS kh\u00f4ng ph\u1ea3i l\u00fd do. L\u00fd do l\u00e0 b\u1ea1n c\u00f3 th\u1eadt s\u1ef1 c\u1ea7n c\u00e1i runtime \u0111\u00f3 n\u1eb1m trong binary c\u1ee7a m\u00ecnh kh\u00f4ng, khi ph\u1ea7n l\u1edbn th\u1eddi gian n\u00f3 ch\u1ec9 ng\u1ed3i ch\u1edd network.\n3) Go to school first: pi and omp T\u00f4i kh\u00f4ng t\u1ef1 ngh\u0129 ra thi\u1ebft k\u1ebf. T\u00f4i ng\u1ed3i \u0111\u1ecdc. V\u00e0 \u0111\u1ecdc xong th\u00ec th\u1ea5y m\u00ecnh kh\u00f4ng c\u1ea7n ph\u1ea3i th\u00f4ng minh n\u1eefa.\npi (github.com\/earendil-works\/pi) l\u00e0 m\u1ed9t coding agent harness b\u1eb1ng TypeScript c\u1ee7a Mario Zechner, v\u00e0 ch\u00ednh n\u00f3 l\u00e0m t\u00f4i \u0111\u1ed5i c\u00e1ch ngh\u0129. Tri\u1ebft l\u00fd c\u1ee7a n\u00f3 g\u00f3i trong v\u00e0i d\u00f2ng m\u00e0 \u0111\u1ecdc xong t\u00f4i ph\u1ea3i ng\u1ed3i im m\u1ed9t l\u00fac:\nSystem prompt d\u01b0\u1edbi 1000 token, t\u00ednh lu\u00f4n c\u1ea3 m\u00f4 t\u1ea3 tool. L\u00fd do: model frontier \u0111\u00e3 \u0111\u01b0\u1ee3c RL-train \u0111\u1ec3 hi\u1ec3u coding agent. Nh\u00e9t 10.000 token h\u01b0\u1edbng d\u1eabn v\u00e0o ch\u1ec9 l\u00e0 mang n\u1eb7ng th\u00eam. \u0110\u00fang 4 tool l\u00f5i: read, write, edit, bash. B\u1ed1n c\u00e1i \u0111\u00f3 l\u00e0 \u0111\u1ee7. YOLO m\u1eb7c \u0111\u1ecbnh. Kh\u00f4ng c\u00f3 s\u00e2n kh\u1ea5u xin quy\u1ec1n. V\u00ec combo \u0111\u1ecdc d\u1eef li\u1ec7u + ch\u1ea1y code + g\u1ecdi m\u1ea1ng th\u00ec kh\u00f4ng c\u00e1ch n\u00e0o nh\u1ed1t b\u1eb1ng prompt hay b\u1eb1ng rule pattern \u0111\u01b0\u1ee3c. Mu\u1ed1n nh\u1ed1t th\u00ec nh\u1ed1t b\u1eb1ng container ho\u1eb7c micro-VM, \u0111\u1eebng nh\u1ed1t b\u1eb1ng l\u1eddi nh\u1eafn. Kh\u00f4ng c\u00f3 todo tool built-in. Model b\u1ecb confuse b\u1edfi state m\u00e0 tool qu\u1ea3n l\u00fd. Mu\u1ed1n list vi\u1ec7c th\u00ec vi\u1ebft ra TODO.md. T\u1ef1 tay vi\u1ebft t\u1ea7ng LLM, kh\u00f4ng d\u00f9ng SDK. V\u00ec th\u1ebf gi\u1edbi ch\u1ec9 c\u00f3 4 wire API \u0111\u00e1ng k\u1ec3: OpenAI Completions, OpenAI Responses, Anthropic Messages, Google GenAI. omp (Oh My Pi) l\u00e0 fork c\u1ee7a pi, v\u00e0 n\u00f3 l\u00e0 th\u1ee9 t\u00f4i d\u00f9ng h\u1eb1ng ng\u00e0y. omp th\u00eam \u0111\u1ee7 th\u1ee9 h\u1eefu \u00edch: t\u1ea7ng Rust N-API cho grep\/glob\/AST\/PTY, filesystem-scan cache d\u00f9ng chung, extension system trong process, MCP, subagent hub, compaction v\u1edbi 6 \u0111\u01b0\u1eddng trigger, session tree r\u1ea5t k\u1ef7 lu\u1eadt.\nC\u00e1i gi\u00e1: runtime JS l\u00e0m n\u1ec1n, extension n\u1ea1p trong c\u00f9ng process, event queue kh\u00f4ng ch\u1eb7n bi\u00ean, v\u00e0 c\u1ea3 session n\u1eb1m trong memory. Tr\u00ean m\u00e1y t\u00f4i ~\/.omp ph\u00ecnh ra 5.7 GB.\nV\u00e0 \u0111\u00e2y l\u00e0 quy\u1ebft \u0111\u1ecbnh quan tr\u1ecdng nh\u1ea5t c\u1ee7a c\u1ea3 7 ng\u00e0y, t\u00f3m trong m\u1ed9t c\u00e2u:\nPort data model. \u0110\u1eebng port code.\nJSONL session tree (append-only + m\u1ed9t con tr\u1ecf l\u00e1), unified stream contract, c\u00e1ch d\u1ef1ng l\u1ea1i context, compaction, OutputSink, frame-plan TUI \u2014 t\u1ea5t c\u1ea3 \u0111\u1ec1u l\u00e0 thi\u1ebft k\u1ebf m\u00e0 hi\u1ec7n tr\u01b0\u1eddng c\u00f4ng vi\u1ec7c c\u1ee7a t\u00f4i \u0111\u00e3 d\u1eabm l\u00ean v\u00e0i th\u00e1ng r\u1ed3i. Ch\u00fang \u0111\u00fang. Vi\u1ec7c c\u1ee7a t\u00f4i l\u00e0 ch\u00e9p ng\u1eef ngh\u0129a (t\u00ean entry gi\u1eef nguy\u00ean \u0111\u1ec3 tooling c\u0169 c\u00f2n \u0111\u1ecdc \u0111\u01b0\u1ee3c), kh\u00f4ng ph\u1ea3i ch\u00e9p implementation c\u1ee7a th\u1eddi JS.\nNghi\u00ean c\u1ee9u t\u00f4i vi\u1ebft ra trong 7 ng\u00e0y n\u1eb1m \u1edf docs\/research\/: 19 file ph\u00e2n t\u00edch omp, pi, Claude Code, opencode, hermes, fx \u2014 k\u00e8m b\u1ea3ng verdict t\u1eebng t\u00ednh n\u0103ng: c\u00e1i n\u00e0o port, c\u00e1i n\u00e0o b\u1ecf, c\u00e1i n\u00e0o port kh\u00e1c \u0111i v\u00e0 t\u1ea1i sao. docs\/parity-delta.md ghi l\u1ea1i m\u1ecdi ch\u1ed7 t\u00f4i c\u1ed1 t\u00ecnh kh\u00e1c omp, v\u00e0 c\u1ea3 nh\u1eefng flag omp t\u00f4i nh\u1eadn cho t\u01b0\u01a1ng th\u00edch nh\u01b0ng kh\u00f4ng c\u00f3 ngh\u0129a (nh\u01b0 --no-pty, v\u00ec bash c\u1ee7a t\u00f4i l\u00e0 pipe-based).\n4) Architecture: what I chose, and what I deliberately did not do Module path github.com\/FreePeak\/xdev, Go 1.25, CGO-free, m\u1ed9t binary t\u0129nh, \u0111\u00fang 5 direct dependency (tcell, go-runewidth, MCP Go SDK, yaml.v3, modernc.org\/sqlite).\nThe session is an append-only JSONL tree with a leaf pointer Kh\u00f4ng c\u00f3 entry n\u00e0o b\u1ecb s\u1eeda hay xo\u00e1. Branch ch\u1ec9 l\u00e0 d\u1eddi m\u1ed9t con tr\u1ecf. Context d\u1ef1ng l\u1ea1i b\u1eb1ng c\u00e1ch \u0111i theo parent link. Format inspectable \u2014 b\u1ea1n jq v\u00e0o file session c\u1ee7a t\u00f4i \u0111\u01b0\u1ee3c, v\u00e0 t\u00f4i kh\u00f4ng c\u1ea7n vi\u1ebft ri\u00eang c\u00e1i viewer n\u00e0o.\n\u0110\u00e2y l\u00e0 port ng\u1eef ngh\u0129a t\u1eeb pi\/omp, v\u00e0 n\u00f3 l\u00e0 th\u1ee9 khi\u1ebfn t\u00f4i y\u00ean t\u00e2m nh\u1ea5t trong thi\u1ebft k\u1ebf. V\u00ec n\u00f3 cho ph\u00e9p m\u1ed9t th\u1ee9 m\u00e0 harness d\u1ea1ng &ldquo;state trong memory&rdquo; kh\u00f4ng cho: nh\u00ecn l\u1ea1i v\u00e0 c\u00e3i nhau v\u1edbi qu\u00e1 kh\u1ee9.\nEverything is bounded Queue c\u00f3 bi\u00ean. Buffer c\u00f3 bi\u00ean. Session window c\u00f3 bi\u00ean. Output sink c\u00f3 bi\u00ean.\nC\u1ee5 th\u1ec3: debug.SetMemoryLimit(100MB) (override b\u1eb1ng XDEV_MEMLIMIT), v\u00e0 khi live heap ch\u1ea1m 85% ng\u01b0\u1ee1ng \u0111\u00f3 th\u00ec agent bu\u1ed9c compaction, kh\u00f4ng \u0111\u1ee3i t\u1edbi ng\u01b0\u1ee1ng token.\n\u00dd ngh\u0129a th\u1ef1c d\u1ee5ng: m\u1ed9t turn m\u1ea5t ki\u1ec3m so\u00e1t s\u1ebd degrade th\u00e0nh &ldquo;compact ngay&rdquo;, ch\u1ee9 kh\u00f4ng th\u00e0nh OOM kill. Backpressure l\u00e0 feature, kh\u00f4ng ph\u1ea3i bug.\nT\u00f4i \u0111o l\u00fac boot: ~16MB RSS. 30\u201370MB \u01b0\u1edbc t\u00ednh cho phi\u00ean l\u00e0m vi\u1ec7c b\u00ecnh th\u01b0\u1eddng, worst case \u00e9p d\u01b0\u1edbi 100MB. \u0110\u00e2y l\u00e0 con s\u1ed1 duy nh\u1ea5t t\u00f4i ph\u1ea3i th\u1eeba nh\u1eadn l\u00e0 m\u00ecnh ch\u01b0a \u0111o \u0111\u1ee7: t\u00f4i ch\u01b0a ch\u1ea1y m\u1ed9t phi\u00ean 200k token th\u1eadt s\u1ef1 t\u1edbi \u0111\u00e1y. Con s\u1ed1 100MB l\u00e0 thi\u1ebft k\u1ebf c\u1ed9ng v\u1edbi c\u00e1c test c\u00f3 th\u1eadt, kh\u00f4ng ph\u1ea3i measurement c\u1ee7a t\u00ecnh hu\u1ed1ng t\u1ec7 nh\u1ea5t.\n4 core tools, and the rest is optional Prompt + 4 tool n\u1eb1m d\u01b0\u1edbi 1000 token, v\u00e0 ch\u1ed7 n\u00e0y t\u00f4i kh\u00f4ng tin l\u1eddi m\u00ecnh n\u00f3i \u2014 t\u00f4i test lu\u00f4n c\u00e1i gi\u1edbi h\u1ea1n \u0111\u00f3:\n\/\/ cmd\/xdev\/prompt_test.go const maxPromptTokens = 1000 if tokens := len([]rune(got)) \/ 4; tokens &gt;= maxPromptTokens { t.Fatalf(&#34;system prompt is ~%d tokens (budget %d): %d chars across %d tools&#34;+ &#34; \u2014 trim a description or make a deliberate PRD change&#34;, ...) } \u01af\u1edbc token b\u1eb1ng runes \/ 4 l\u00e0 th\u00f4. T\u00f4i bi\u1ebft. Nh\u01b0ng n\u00f3 l\u00e0 m\u1ed9t c\u00e1i c\u1ed5ng, kh\u00f4ng ph\u1ea3i c\u00e1i th\u01b0\u1edbc \u2014 m\u1ee5c \u0111\u00edch c\u1ee7a n\u00f3 l\u00e0 b\u1eaft t\u00f4i ph\u1ea3i s\u1eeda PRD m\u1ed9t c\u00e1ch c\u00f3 \u00fd th\u1ee9c m\u1ed7i khi mu\u1ed1n prompt ph\u00ecnh ra, thay v\u00ec \u0111\u1ec3 n\u00f3 ph\u00ecnh l\u00ean trong im l\u1eb7ng.\ngrep, glob, lsp, eval, browser, debug, computer, tts, task&hellip; \u0111\u1ec1u c\u00f3, nh\u01b0ng ch\u00fang l\u00e0 l\u1edbp th\u00eam v\u00e0o sau khi 4 c\u00e1i l\u00f5i \u0111\u00e3 \u0111\u1ee9ng v\u1eefng. T\u1ed5ng: 544 file Go, ~90k d\u00f2ng kh\u00f4ng t\u00ednh test, ~63k d\u00f2ng test \u2014 t\u1ee9c test chi\u1ebfm 41% codebase.\nThe things I deliberately did not do N\u00f3i r\u00f5 c\u00e1i m\u00ecnh kh\u00f4ng l\u00e0m quan tr\u1ecdng h\u01a1n n\u00f3i c\u00e1i m\u00ecnh l\u00e0m:\nKh\u00f4ng permission theater. Kh\u00f4ng c\u00f3 popup &ldquo;xdev mu\u1ed1n ch\u1ea1y ls?&rdquo;. YOLO m\u1eb7c \u0111\u1ecbnh, v\u00e0 harness ch\u1ec9 t\u00e0i li\u1ec7u ho\u00e1 pattern sandbox (docs\/reference\/container-and-sandbox.md), kh\u00f4ng d\u1ef1ng t\u01b0\u1eddng gi\u1ea5y. Kh\u00f4ng PTY trong tool bash. Pipe-based. C\u1edd --no-pty c\u1ee7a omp t\u00f4i nh\u1eadn cho t\u01b0\u01a1ng th\u00edch script, v\u00e0 n\u00f3&hellip; no-op c\u00f3 ch\u1ee7 \u0111\u00edch, ghi r\u00f5 trong parity-delta. Kh\u00f4ng n\u1ea1p extension trong process. Extension ch\u1ea1y subprocess n\u00f3i chuy\u1ec7n v\u1edbi nhau b\u1eb1ng JSONL handshake. M\u1ed9t extension crash kh\u00f4ng \u0111\u01b0\u1ee3c ph\u00e9p l\u00e0m ch\u1ebft agent. C\u00e1i m\u1ea5t: renderer custom trong process \u2014 extension ch\u1ec9 khai b\u00e1o spec (card | table | tree), host render, v\u00e0 spec sai th\u00ec degrade v\u1ec1 plain text. Kh\u00f4ng t\u1ef1 nh\u1eadn l\u00e0 b\u1ea3n sao. omp v18.1.17 c\u00f3 131 trang docs omp:\/\/; t\u00f4i diff c\u01a1 h\u1ecdc omp --help v\u1edbi xdev -h r\u1ed3i ghi l\u1ea1i t\u1eebng th\u1ee9 c\u00f2n thi\u1ebfu, k\u00e8m l\u00fd do. 5) The TUI: where I spent the most time \u0110\u00e2y l\u00e0 ph\u1ea7n t\u00f4i mu\u1ed1n k\u1ec3 nh\u1ea5t, v\u00ec n\u00f3 c\u0169ng l\u00e0 ch\u1ed7 t\u00f4i sai nhi\u1ec1u nh\u1ea5t.\ntcell, not bubbletea bubbletea \u0111\u1eb9p, d\u1ec5 d\u00f9ng, t\u00e0i li\u1ec7u t\u1ed1t. Nh\u01b0ng m\u00f4 h\u00ecnh Elm c\u1ee7a n\u00f3 allocate nhi\u1ec1u, m\u00e0 trong m\u1ed9t c\u00e1i TUI m\u1ed7i gi\u00e2y nh\u1eadn c\u1ea3 ngh\u00ecn token stream th\u00ec allocation churn ch\u00ednh l\u00e0 gi\u1eadt.\ntcell th\u00f4 h\u01a1n, nhanh h\u01a1n, \u00edt c\u1ea5p ph\u00e1t h\u01a1n \u2014 v\u00e0 frame-plan model c\u1ee7a omp port l\u00ean n\u00f3 r\u1ea5t s\u1ea1ch. \u0110\u1ed5i l\u1ea1i, b\u1ea1n ph\u1ea3i t\u1ef1 qu\u1ea3n m\u1ecdi th\u1ee9. T\u00f4i t\u1ef1 qu\u1ea3n m\u1ecdi th\u1ee9.\nFrame plan: three states of a block M\u1ed7i frame l\u00e0: chrome b\u1eaft bu\u1ed9c (editor\/status\/HUD\/overlay) + TerminalFramePlan { history?: {id, rows}, viewport: rows[] }.\nV\u00e0 transcript block c\u00f3 ba tr\u1ea1ng th\u00e1i:\nTr\u1ea1ng th\u00e1i Ngh\u0129a X\u1eed l\u00fd khi resize active c\u00f2n thay \u0111\u1ed5i \u0111\u01b0\u1ee3c, n\u1eb1m trong viewport v\u1ebd l\u1ea1i settled \u0111\u00e3 ch\u1ed1t, reflow \u0111\u01b0\u1ee3c reflow, cho t\u1edbi khi \u00e1p l\u1ef1c dung l\u01b0\u1ee3ng committed \u0111\u00e3 \u0111\u1ea9y v\u00e0o terminal scrollback th\u1eadt kh\u00f4ng c\u00f2n l\u00e0 vi\u1ec7c c\u1ee7a m\u00ecnh C\u00e1i insight n\u00e0y t\u00f4i h\u1ecdc \u0111\u01b0\u1ee3c b\u1eb1ng c\u00e1ch tr\u1ea3 gi\u00e1: b\u1ea1n ph\u1ea3i v\u1ebd viewport, \u0111\u1eebng v\u1ebd session. Commit perf(tui): draw the viewport, not the session; trim aged tool output first l\u00e0 commit t\u00f4i \u01b0\u1edbc g\u00ec m\u00ecnh vi\u1ebft \u0111\u01b0\u1ee3c ngay t\u1eeb ng\u00e0y \u0111\u1ea7u.\nResize is the most hateful thing about terminals Alt-screen (?1049h) ch\u1ec9 d\u00e0nh cho overlay; c\u00f2n transcript th\u00ec d\u00f2ng n\u00e0o cu\u1ed9n m\u1ea5t kh\u1ecfi m\u00e0n h\u00ecnh, t\u00f4i \u0111\u1ea9y v\u00e0o scrollback th\u1eadt c\u1ee7a terminal. L\u00fd do r\u1ea5t \u0111\u01a1n gi\u1ea3n: khi t\u00f4i kh\u00f4ng c\u00f2n nh\u00ecn th\u1ea5y n\u00f3, kh\u00f4ng c\u00f3 l\u00fd do g\u00ec \u0111\u1ec3 n\u00f3 chi\u1ebfm RAM c\u1ee7a t\u00f4i.\nH\u1eadu qu\u1ea3: khi terminal resize, con tr\u1ecf c\u1ee7a t\u00f4i kh\u00f4ng c\u00f2n \u1edf ch\u1ed7 t\u00f4i ngh\u0129 n\u1eefa. Ph\u1ea3i h\u1ecfi l\u1ea1i terminal xem m\u00ecnh \u0111ang \u1edf d\u00f2ng n\u00e0o b\u1eb1ng DSR anchor r\u1ed3i d\u1ef1ng l\u1ea1i. DSR-anchor resize recovery n\u1eb1m trong PRD t\u1eeb \u0111\u1ea7u, v\u00e0 n\u00f3 l\u00e0 m\u1ed9t trong nh\u1eefng d\u00f2ng code \u0111au \u0111\u1edbn nh\u1ea5t t\u00f4i t\u1eebng vi\u1ebft.\nThe four TUI bugs I will never forget Bug 1 \u2014 \u0111\u00f3ng b\u0103ng th\u1eadt s\u1ef1. fix(tui): the tree selector could own the keyboard while painting nothing \u2014 a &quot;frozen TUI&quot; with a live process. M\u1ed9t selector v\u1ebd ra kh\u00f4ng g\u00ec c\u1ea3 nh\u01b0ng v\u1eabn gi\u1eef b\u00e0n ph\u00edm. Ng\u01b0\u1eddi d\u00f9ng th\u1ea5y treo, process v\u1eabn s\u1ed1ng. Gh\u00ea \u1edf ch\u1ed7: m\u1ecdi t\u00edn hi\u1ec7u &ldquo;process c\u00f2n s\u1ed1ng&rdquo; c\u1ee7a t\u00f4i \u0111\u1ec1u b\u00e1o \u1ed5n.\nBug 2 \u2014 self-deadlock. fix(tui): picker draw must not re-lock a.mu \u2014 self-deadlock hung every draw with content. V\u1ebd l\u1ea1i kho\u00e1 l\u1ea1i c\u00e1i lock \u0111\u00e3 c\u00f3. Treo m\u1ecdi frame c\u00f3 n\u1ed9i dung.\nBug 3 \u2014 modal kh\u00f4ng v\u1ebd \u0111\u01b0\u1ee3c th\u00ec ph\u1ea3i \u0111\u00f3ng. fix(tui): a modal that cannot paint must close, and cancel hits the turn. T\u00f4i t\u1eebng \u0111\u1ec3 modal n\u1eb1m l\u1ea1i khi n\u00f3 kh\u00f4ng paint \u0111\u01b0\u1ee3c. \u0110\u00fang ra: kh\u00f4ng v\u1ebd \u0111\u01b0\u1ee3c th\u00ec bi\u1ebfn m\u1ea5t. M\u1ed9t c\u00e1i modal b\u1ea1n kh\u00f4ng th\u1ea5y m\u00e0 v\u1eabn \u0103n ph\u00edm l\u00e0 m\u1ed9t c\u00e1i b\u1eaby.\nBug 4 \u2014 scroll hint \u0111\u00e8 l\u00ean n\u1ed9i dung. fix(tui): the scroll hint was painted over the first transcript row. Nh\u1ecf. Nh\u01b0ng b\u1ea1n th\u1ea5y n\u00f3 ngay l\u1ea7n \u0111\u1ea7u m\u1edf tool.\nSau ba bug \u0111\u1ea7u, t\u00f4i th\u00eam watchdog: UI loop iteration n\u00e0o qu\u00e1 5 gi\u00e2y th\u00ec dump goroutine stack ra ~\/.xdev\/agent\/dumps\/ (gi\u1edbi h\u1ea1n dump 1MB).\nL\u00fd do: ba v\u1ee5 treo t\u00f4i v\u1eeba k\u1ec3, n\u1ebfu kh\u00f4ng c\u00f3 dump th\u00ec t\u00f4i ch\u1ec9 c\u00f2n c\u00e1ch \u0111o\u00e1n. M\u00e0 \u0111o\u00e1n m\u1ed9t c\u00e1i TUI treo l\u00e0 l\u00e3ng ph\u00ed th\u1eddi gian. T\u00f4i ch\u1ea5p nh\u1eadn t\u1ed1n m\u1ed9t goroutine \u0111\u1ec3 \u0111\u1ed5i l\u1ea5y vi\u1ec7c kh\u00f4ng ph\u1ea3i \u0111o\u00e1n n\u1eefa.\nThe mouse: the thing I did and redid Chu\u1ed9t trong TUI kh\u00f4ng c\u00f3 spec. N\u00f3 ch\u1ec9 c\u00f3 c\u1ea3m gi\u00e1c &ldquo;sai&rdquo;. V\u00e0 c\u00e1i c\u1ea3m gi\u00e1c &ldquo;sai&rdquo; \u0111\u00f3 t\u00f4i ph\u1ea3i tr\u1ea3 l\u1eddi 5 l\u1ea7n trong 4 ti\u1ebfng:\n23:19 fix(tui): Shift hands the drag to the terminal, mid-stroke too 01:07 feat(tui): mouse selection covers the whole screen and stays visible 01:51 feat(tui): one mouse drag can select past the screen 02:19 feat(tui): the modal picker answers the mouse, like omp&#39;s SelectList 02:40 feat(tui): click-to-focus on the live-agent roster C\u00e1i \u0111\u1ea7u ti\u00ean \u0111au th\u1eadt: ng\u01b0\u1eddi d\u00f9ng nh\u1ea5n Shift \u0111\u1ec3 copy b\u1eb1ng selection c\u1ee7a ch\u00ednh terminal, v\u00e0 t\u00f4i ph\u1ea3i nh\u1ea3 con tr\u1ecf ngay gi\u1eefa thao t\u00e1c k\u00e9o \u2014 k\u1ec3 c\u1ea3 khi h\u1ecd \u0111\u00e3 k\u00e9o \u0111\u01b0\u1ee3c n\u1eeda \u0111\u01b0\u1eddng. Kh\u00f4ng c\u00f3 design doc n\u00e0o d\u1ea1y b\u1ea1n chi ti\u1ebft \u0111\u00f3. Ch\u1ec9 c\u00f3 d\u00f9ng th\u1eadt m\u1edbi bi\u1ebft.\nC\u00e1i cu\u1ed1i c\u00f9ng th\u00ec bu\u1ed3n c\u01b0\u1eddi: t\u00f4i \u0111\u00e3 d\u1ef1ng m\u1ed9t b\u1ea3ng roster agent ch\u1ec9 \u0111i\u1ec1u khi\u1ec3n \u0111\u01b0\u1ee3c b\u1eb1ng ph\u00edm. Trong terminal, n\u0103m 2026.\nThe start screen, and the context dock M\u00e0n h\u00ecnh b\u1eaft \u0111\u1ea7u l\u00e0 ch\u1ed7 duy nh\u1ea5t th\u01b0\u01a1ng hi\u1ec7u \u0111\u01b0\u1ee3c ph\u00e9p c\u00f3 \u00fd ki\u1ebfn \u2014 m\u1ed9t wordmark pixel, d\u00f2ng tagline nh\u1ecb ph\u00e2n c\u1ee7a n\u00f3, v\u00e0 b\u1ed1n h\u00e0nh \u0111\u1ed9ng th\u1eadt k\u00e8m \u0111\u00fang ph\u00edm ch\u1ea1y \u0111\u01b0\u1ee3c ch\u00fang. M\u1ecdi th\u1ee9 c\u00f2n l\u1ea1i gi\u1eef \u0111\u01a1n s\u1eafc \u0111\u1ec3 transcript l\u00e0 th\u1ee9 duy nh\u1ea5t tranh s\u1ef1 ch\u00fa \u00fd:\nContext dock l\u00e0 c\u00e2u tr\u1ea3 l\u1eddi cho &ldquo;t\u00f4i \u0111ang \u1edf \u0111\u00e2u trong session n\u00e0y?&rdquo;. N\u00f3 l\u00e0 m\u1ed9t panel r\u1ed9ng c\u1ed1 \u0111\u1ecbnh 42 c\u1ed9t, ch\u1ec9 m\u1edf khi terminal \u0111\u1ee7 r\u1ed9ng \u0111\u1ec3 v\u1eabn ch\u1eeba cho transcript kho\u1ea3ng s\u1ed1ng ri\u00eang c\u1ee7a n\u00f3, v\u00e0 c\u00e1c m\u1ee5c c\u1ee7a n\u00f3 l\u00e0 \u0111\u00fang nh\u1eefng g\u00ec session \u0111ang c\u00f3: k\u1ebf ho\u1ea1ch \u0111ang ch\u1edd, danh s\u00e1ch task, nh\u1eefng file m\u00e0 diff \u0111\u00e3 \u0111\u1ee5ng t\u1edbi, c\u00e1c agent \u0111ang ch\u1ea1y \u2014 m\u1ed7i m\u1ee5c g\u1ea5p l\u1ea1i \u0111\u01b0\u1ee3c, v\u00e0 n\u00f3 t\u1eeb ch\u1ed1i d\u1ef1ng l\u1ea1i frame khi kh\u00f4ng c\u00f3 g\u00ec \u0111\u1ed5i. \u1ede \u0111\u00e2y plan mode \u0111ang b\u1eadt, n\u00ean dock \u0111\u00e3 c\u00f3 s\u1eb5n m\u1ee5c c\u1ee7a n\u00f3:\nTheme: 66 colour tokens T\u00f4i port h\u1ec7 theme c\u1ee7a Grok CLI (GrokNight\/GrokDay, t\u1ef1 \u0111\u1ed5i theo OSC 11), v\u00e0 b\u1eaft bu\u1ed9c ph\u1ea3i \u0111\u1ee7 c\u1ea3 66 color token \u2014 vi\u1ebft y h\u1ec7t c\u00e1ch omp vi\u1ebft, \u0111\u1ec3 m\u1ed9t file theme c\u1ee7a omp s\u01a1n \u0111\u01b0\u1ee3c l\u00ean chrome c\u1ee7a xdev m\u00e0 kh\u00f4ng ph\u1ea3i s\u1eeda g\u00ec. Thi\u1ebfu m\u1ed9t token l\u00e0 test fail, kh\u00f4ng c\u00f3 chuy\u1ec7n &ldquo;\u0111\u1ec3 sau&rdquo;.\nC\u1ea3 ng\u00e0y l\u00e0m vi\u1ec7c trong m\u1ed9t c\u00e1i TUI m\u00e0 \u0111\u1ec3 n\u00f3 d\u00f9ng m\u00e0u m\u1eb7c \u0111\u1ecbnh c\u1ee7a terminal th\u00ec t\u00f4i ch\u1ecbu kh\u00f4ng n\u1ed5i. \u0110\u00e2y l\u00e0 chi ph\u00ed t\u00f4i t\u1ef1 nguy\u1ec7n tr\u1ea3, v\u00e0 t\u00f4i ngh\u0129 n\u00f3 \u0111\u00e1ng.\n6) Testing a thing that only exists as text Nghe bu\u1ed3n c\u01b0\u1eddi th\u1eadt. Nh\u01b0ng TUI c\u1ee7a t\u00f4i render ch\u1eef, m\u00e0 ch\u1eef th\u00ec kh\u00f4ng ai diff b\u1eb1ng m\u1eaft m\u1ed9t c\u00e1ch k\u1ef7 lu\u1eadt \u0111\u01b0\u1ee3c.\nN\u00ean ph\u1ea7n l\u1edbn test TUI c\u1ee7a t\u00f4i l\u00e0 test d\u00f2ng k\u00fd t\u1ef1: d\u1ef1ng frame tr\u00ean m\u1ed9t simulterminal, r\u1ed3i so text.\nKeymap (10 test): m\u1ecdi action ph\u1ea3i resolve \u0111\u01b0\u1ee3c, ChordOf \u0111\u00fang chi\u1ec1u, file keymap user h\u1ecfng th\u00ec v\u1ec1 default ch\u1ee9 kh\u00f4ng crash, \/hotkeys ph\u1ea3i hi\u1ec3n th\u1ecb m\u1ecdi action, v\u00e0 remap th\u1eadt s\u1ef1 \u0111\u1ed5i h\u00e0nh vi. Chrome (15 test): status row ph\u1ea3i n\u00f3i b\u1ea1n \u0111ang \u1edf \u0111\u00e2u ch\u1ee9 kh\u00f4ng ph\u1ea3i li\u1ec7t k\u00ea ph\u00edm; HUD meter ph\u1ea3i hi\u1ec7n used\/total c\u1ee7a context s\u1ed1ng; \u0111\u1ed3ng h\u1ed3 phi\u00ean ph\u1ea3i re-base khi \u0111\u1ed5i session, v\u00e0 khi kh\u00f4ng c\u00f3 neo th\u00ec \u1ea9n \u0111i ch\u1ee9 \u0111\u1eebng hi\u1ec3n th\u1ecb 00:00. Composer: Up\/Down trong b\u1ea3n nh\u00e1p nhi\u1ec1u d\u00f2ng ph\u1ea3i \u0111i theo d\u00f2ng hi\u1ec3n th\u1ecb, kh\u00f4ng ph\u1ea3i d\u00f2ng logic \u2014 nghe hi\u1ec3n nhi\u00ean, cho t\u1edbi khi editor c\u1ee7a b\u1ea1n \u0111\u1ee5ng wide character. Kh\u00f4ng treo: draw_hang_test.go c\u00f3 5 test d\u1ef1ng frame tr\u00ean simulterminal r\u1ed3i timeout \u2014 selector kh\u00f4ng \u0111\u01b0\u1ee3c gi\u1eef b\u00e0n ph\u00edm khi v\u1ebd ra ch\u1ed7 tr\u1ed1ng, modal kh\u00f4ng paint \u0111\u01b0\u1ee3c th\u00ec ph\u1ea3i \u0111\u00f3ng. tree_test.go ghim ch\u1eb7t lu\u00f4n v\u1ee5 self-deadlock: draw kh\u00f4ng \u0111\u01b0\u1ee3c re-lock mutex c\u1ee7a app. Ba c\u00e1i bug \u1edf m\u1ee5c tr\u00ean, gi\u1edd b\u1ecb nh\u1ed1t l\u1ea1i b\u1eb1ng code. 63k d\u00f2ng test, nhi\u1ec1u d\u00f2ng ch\u1ec9 \u0111\u1ec3 n\u00f3i &ldquo;d\u00f2ng n\u00e0y ph\u1ea3i gi\u1ed1ng h\u1ec7t h\u00f4m qua&rdquo;. Gi\u1eef ch\u00fang th\u00ec t\u1ed1n c\u00f4ng. Nh\u01b0ng m\u1ed7i l\u1ea7n t\u00f4i refactor renderer, ch\u00fang l\u00e0 th\u1ee9 duy nh\u1ea5t cho t\u00f4i d\u00e1m refactor m\u00e0 kh\u00f4ng s\u1ee3.\n7) The thing the model produced that surprised me Trong qu\u00e1 tr\u00ecnh build c\u00f3 m\u1ed9t thay \u0111\u1ed5i t\u00f4i r\u1ea5t th\u00edch: an unparseable tool call is an error result, not a dead run.\nTr\u01b0\u1edbc \u0111\u00f3, n\u1ebfu model tr\u1ea3 v\u1ec1 tool call v\u1edbi arguments parse kh\u00f4ng \u0111\u01b0\u1ee3c, turn ch\u1ebft. \u0110\u01a1n gi\u1ea3n v\u1eady th\u00f4i, v\u00e0 ngu v\u1eady th\u00f4i.\nSau: n\u00f3 l\u00e0 m\u1ed9t tool error bay ng\u01b0\u1ee3c l\u00ean model, v\u00e0 model t\u1ef1 s\u1eeda. M\u1ed9t d\u00f2ng x\u1eed l\u00fd l\u1ed7i \u0111\u1ed5i th\u00e0nh m\u1ed9t v\u00f2ng t\u1ef1 ch\u1eefa. T\u00f4i kh\u00f4ng d\u1ea1y model th\u00f4ng minh h\u01a1n; t\u00f4i ch\u1ec9 ng\u1eebng c\u1eaft l\u1eddi n\u00f3 gi\u1eefa c\u00e2u.\nT\u01b0\u01a1ng t\u1ef1 v\u1edbi edit arg-repair + freshness guard. Args s\u1eeda \u0111\u01b0\u1ee3c th\u00ec s\u1eeda (model hay off-by-one \u1edf s\u1ed1 d\u00f2ng), c\u00f2n file \u0111\u00e3 \u0111\u1ed5i k\u1ec3 t\u1eeb l\u00fac agent \u0111\u1ecdc th\u00ec d\u1eebng l\u1ea1i v\u00e0 b\u00e1o, \u0111\u1eebng ghi \u0111\u00e8.\nC\u1eb7p n\u00e0y l\u00e0 to\u00e0n b\u1ed9 tri\u1ebft l\u00fd c\u1ee7a t\u00f4i v\u1ec1 harness: ch\u1ed7 n\u00e0o m\u00e1y t\u1ef1 v\u00e1 \u0111\u01b0\u1ee3c th\u00ec v\u00e1, ch\u1ed7 n\u00e0o v\u00e1 l\u00e0 m\u1ea5t d\u1eef li\u1ec7u th\u00ec d\u1eebng.\n8) Three things I learned M\u1ed9t: &ldquo;nh\u1eb9&rdquo; kh\u00f4ng ph\u1ea3i l\u00e0 c\u1eaft t\u00ednh n\u0103ng. L\u00e0 c\u1eaft runtime.\nxdev cu\u1ed1i c\u00f9ng c\u0169ng c\u00f3 subagent hub, MCP client, LSP, memory backend, collab E2E, web search, browser qua CDP, DAP debugger. 35 package trong internal\/. T\u00ednh n\u0103ng t\u00f4i kh\u00f4ng c\u1eaft. T\u00f4i b\u1ecf c\u00e1i runtime b\u1ecb nh\u00e9t theo, v\u00e0 \u0111\u1ec3 c\u00e1c th\u1ee9 n\u1eb7ng ch\u1ea1y \u1edf process con.\nHai: k\u1ef7 lu\u1eadt kh\u00f4ng n\u1eb1m trong \u00fd \u0111\u1ecbnh, n\u00f3 n\u1eb1m trong test.\nM\u1ecdi con s\u1ed1 t\u00f4i khoe \u1edf \u0111\u1ea7u b\u00e0i \u0111\u1ec1u c\u00f3 th\u1ee9 g\u00ec \u0111\u00f3 gi\u1eef l\u1ea1i. 1000 token? C\u00f3 prompt_test.go fail n\u1ebfu t\u00f4i vi\u1ebft d\u00e0i h\u01a1n. 66 color token? C\u00f3 m12_test.go. help ph\u1ea3i n\u00eau t\u00ean m\u1ecdi subcommand v\u00e0 kh\u00f4ng \u0111\u01b0\u1ee3c s\u00f3t @both? C\u00f3 usage_test.go \u2014 sinh ra sau v\u1ee5 13 subcommand bi\u1ebfn m\u1ea5t kh\u1ecfi help c\u00f9ng m\u1ed9t l\u00fac.\nK\u1ef7 lu\u1eadt m\u00e0 kh\u00f4ng c\u00f3 test th\u00ec sau 3 ng\u00e0y v\u00e0 100 commit, n\u00f3 kh\u00f4ng c\u00f2n l\u00e0 k\u1ef7 lu\u1eadt n\u1eefa \u2014 n\u00f3 ch\u1ec9 c\u00f2n l\u00e0 k\u00fd \u1ee9c.\nBa: \u0111\u1eebng port code. Port c\u00e1i v\u00ec sao.\nCh\u1ed7 n\u00e0o t\u00f4i port c\u1ea3 implementation l\u1eabn l\u00fd do, t\u00f4i \u0111i r\u1ea5t nhanh. Ch\u1ed7 n\u00e0o t\u00f4i port implementation m\u00e0 kh\u00f4ng ghi l\u1ea1i l\u00fd do, t\u00f4i m\u1ea5t n\u1eeda ng\u00e0y m\u1edbi ph\u00e1t hi\u1ec7n ra m\u00ecnh v\u1eeba mang theo m\u1ed9t quy\u1ebft \u0111\u1ecbnh c\u1ee7a ng\u01b0\u1eddi kh\u00e1c.\ndocs\/parity-delta.md v\u00ec th\u1ebf c\u00f3 gi\u00e1 tr\u1ecb ngang v\u1edbi code. N\u00f3 l\u00e0 n\u01a1i t\u00f4i ghi: omp l\u00e0m A, t\u00f4i l\u00e0m B, v\u00e0 v\u00ec sao l\u00e0 B.\n9) Try it if you want curl -fsSL https:\/\/raw.githubusercontent.com\/FreePeak\/xdev\/main\/scripts\/install.sh | sh Xong th\u00ec xdev setup \u0111\u1ec3 t\u1ea1o ~\/.xdev\/agent\/, s\u1eeda models.yml tr\u1ecf v\u00e0o gateway b\u1ea1n \u0111ang c\u00f3, r\u1ed3i:\nxdev tui # ch\u1ebf \u0111\u1ed9 t\u01b0\u01a1ng t\u00e1c xdev &#34;t\u00ecm ch\u1ed7 n\u00e0o trong repo n\u00e0y \u0111ang log ra password&#34; xdev --resume 01a0 # resume theo prefix session id xdev bench --turns 5 --model @smol \u0111o TTFT v\u00e0 decode p50\/p95 cho provider c\u1ee7a b\u1ea1n \u2014 n\u1ebfu b\u1ea1n t\u00f2 m\u00f2 v\u1ec1 con s\u1ed1 c\u1ee7a t\u00f4i.\nRepo: github.com\/FreePeak\/xdev (Apache-2.0).\n10) Closing C\u00e2u h\u1ecfi &ldquo;m\u1ed9t c\u00f4ng c\u1ee5 vi\u1ebft code th\u00ec c\u1ea7n g\u00ec trong b\u1ed9 nh\u1edb&rdquo; v\u1edbi t\u00f4i gi\u1edd \u0111\u00e3 c\u00f3 \u0111\u00e1p \u00e1n: kho\u1ea3ng 16MB, 4 c\u00e1i tool, v\u00e0 m\u1ed9t c\u00e1i session format m\u00e0 jq \u0111\u1ecdc \u0111\u01b0\u1ee3c.\nPh\u1ea7n c\u00f2n l\u1ea1i c\u1ee7a 7 ng\u00e0y l\u00e0 h\u1ecdc c\u00e1ch kh\u00f4ng l\u00e0m nhi\u1ec1u h\u01a1n th\u1ebf.\nC\u00f2n 200MB kia c\u1ee7a nh\u1eefng tool b\u1ea1n \u0111ang d\u00f9ng? Kh\u00f4ng ph\u1ea3i l\u1ed7i c\u1ee7a h\u1ecd. H\u1ecd ch\u1ecdn r\u1ed9ng thay v\u00ec nh\u1eb9, v\u00e0 v\u1edbi nhi\u1ec1u ng\u01b0\u1eddi th\u00ec l\u1ef1a ch\u1ecdn \u0111\u00f3 \u0111\u00fang.\nCh\u1ec9 l\u00e0 s\u00e1ng nay, t\u00f4i m\u1edf ba tab terminal &ldquo;\u0111ang ngh\u0129&rdquo;, nh\u00ecn htop, v\u00e0 l\u1ea7n \u0111\u1ea7u ti\u00ean kh\u00f4ng th\u1ea5y m\u00ecnh \u0111ang \u0111\u1ed1t RAM ch\u1ec9 \u0111\u1ec3 ch\u1edd m\u1ed9t c\u00e1i model tr\u1ea3 l\u1eddi.\n","permalink":"https:\/\/freepeak.github.io\/posts\/xdev-cach-toi-viet-agent-coding-cli-nhe-va-nhanh\/","summary":"I use omp, opencode and Claude Code every day, and I got more and more annoyed by how heavy they are. This is the story of the 7 days I spent writing xdev: reading the pi\/omp architecture, porting the data model to Go, fighting the terminal UI, and the numbers I measured on my own machine - a 20MB binary, ~16MB RAM, 40ms startup.","title":"xdev: how I wrote a lightweight, fast agent coding CLI"},{"content":"EJBCA + GCP Cloud KMS: A Practical Installation and Configuration Guide Ng\u00e0y: 2026-02-05\nTr\u1ea1ng th\u00e1i: Th\u00e0nh c\u00f4ng Test\nEJBCA Version: Community Edition 9.3.7\nOverview H\u01b0\u1edbng d\u1eabn n\u00e0y t\u00e0i li\u1ec7u h\u00f3a vi\u1ec7c t\u00edch h\u1ee3p th\u00e0nh c\u00f4ng EJBCA Community Edition v\u1edbi GCP Cloud KMS s\u1eed d\u1ee5ng PKCS#11 library. \u0110i\u1ec3m \u0111\u1ed9t ph\u00e1 ch\u00ednh l\u00e0 s\u1eed d\u1ee5ng t\u00f9y ch\u1ecdn c\u1ea5u h\u00ecnh generate_certs: true.\n[!IMPORTANT] C\u1ea5u h\u00ecnh Quan Tr\u1ecdng: B\u1ea1n PH\u1ea2I set generate_certs: true trong file config kmsp11.yaml. N\u1ebfu kh\u00f4ng c\u00f3 t\u00f9y ch\u1ecdn n\u00e0y, Java SunPKCS11 kh\u00f4ng th\u1ec3 ph\u00e1t hi\u1ec7n c\u00e1c kh\u00f3a GCP KMS.\nPrerequisites GCP Project v\u1edbi Cloud KMS API enabled Cloud HSM keys \u0111\u00e3 t\u1ea1o (EC P-256 recommended cho signing) VM v\u1edbi service account c\u00f3 cloudkms.signerVerifier v\u00e0 cloudkms.viewer roles EJBCA Community Edition deployed qua Docker GCP KMS PKCS#11 library (libkmsp11.so) installed Step-by-Step Configuration Step 1: Create Cloud HSM Keys # Create keyring gcloud kms keyrings create dev-pki-ca-keys \\ --location=us-east1 \\ --project=cb-device-services # Create EC P-256 signing key for Policy CA gcloud kms keys create dev-policy-ca-key-v2 \\ --location=us-east1 \\ --keyring=dev-pki-ca-keys \\ --purpose=asymmetric-signing \\ --default-algorithm=ec-sign-p256-sha256 \\ --protection-level=hsm \\ --project=cb-device-services Step 2: Install PKCS#11 Library # Download and install PKCS11_VERSION=&#34;1.3&#34; wget https:\/\/github.com\/GoogleCloudPlatform\/kms-integrations\/releases\/download\/pkcs11-v${PKCS11_VERSION}\/libkmsp11-${PKCS11_VERSION}-linux-amd64.tar.gz tar -xzf libkmsp11-${PKCS11_VERSION}-linux-amd64.tar.gz sudo mkdir -p \/opt\/kmsp11 sudo cp libkmsp11.so \/opt\/kmsp11\/ sudo chmod 755 \/opt\/kmsp11\/libkmsp11.so Step 3: Configure PKCS#11 (CRITICAL) T\u1ea1o \/etc\/kmsp11\/kmsp11.yaml:\n--- tokens: - key_ring: &#34;projects\/cb-device-services\/locations\/us-east1\/keyRings\/dev-pki-ca-keys&#34; label: &#34;policy-ca-token&#34; generate_certs: true log_directory: &#34;\/var\/log\/kmsp11&#34; [!CAUTION] T\u00f9y ch\u1ecdn generate_certs: true l\u00e0 b\u1eaft bu\u1ed9c! T\u00f9y ch\u1ecdn n\u00e0y t\u1ea1o placeholder X.509 certificates cho m\u1ed7i kh\u00f3a, m\u00e0 Java SunPKCS11 y\u00eau c\u1ea7u \u0111\u1ec3 ph\u00e1t hi\u1ec7n private keys.\nStep 4: Verify Key Discovery # Test with pkcs11-tool export KMS_PKCS11_CONFIG=\/etc\/kmsp11\/kmsp11.yaml pkcs11-tool --module \/opt\/kmsp11\/libkmsp11.so --list-objects Output mong \u0111\u1ee3i s\u1ebd hi\u1ec3n th\u1ecb Certificate Objects c\u00f9ng v\u1edbi keys:\nCertificate Object; type = X.509 cert label: dev-policy-ca-key-v2 subject: DN: CN=dev-policy-ca-key-v2 Private Key Object; EC label: dev-policy-ca-key-v2 Usage: sign Step 5: Configure EJBCA Docker \u0110\u1ea3m b\u1ea3o Docker container mounts PKCS#11 library v\u00e0 config:\n# docker-compose.yml services: ejbca: image: keyfactor\/ejbca-ce:latest volumes: - \/opt\/kmsp11:\/opt\/kmsp11:ro - \/etc\/kmsp11:\/etc\/kmsp11:ro environment: - KMS_PKCS11_CONFIG=\/etc\/kmsp11\/kmsp11.yaml Step 6: Configure PKCS#11 in EJBCA Th\u00eam v\u00e0o \/opt\/keyfactor\/ejbca\/conf\/web.properties:\ncryptotoken.p11.lib.1.name=GCP Cloud HSM cryptotoken.p11.lib.1.file=\/opt\/kmsp11\/libkmsp11.so Restart EJBCA:\ncd \/opt\/ejbca &amp;&amp; sudo docker-compose restart Step 7: Create Crypto Token in EJBCA Go to CA Functions &gt; Crypto Tokens Click Create new&hellip; Configure: Name: CloudHSM-PolicyCA Type: PKCS#11 Crypto Token PKCS#11 Library: GCP Cloud HSM Slot\/Token Label: policy-ca-token Click Save Step 8: Create CA Go to CA Functions &gt; Certificate Authorities Enter CA name: PolicyCA Click Create&hellip; Configure: Crypto Token: CloudHSM-PolicyCA certSignKey: dev-policy-ca-key-v2 Signing Algorithm: SHA256withECDSA Subject DN: CN=Policy CA, O=Crossbar, C=US Signed By: Self Signed Certificate Profile: ROOTCA Validity: 10y Click Create Makefile Commands Command Description make scp-policy-ca ENV=dev Upload install script to Policy CA VM make ssh-policy-ca ENV=dev SSH to Policy CA VM make update-pkcs11-config ENV=dev Update kmsp11.yaml with generate_certs make restart-ejbca ENV=dev Restart EJBCA container make test-keys ENV=dev Test PKCS#11 key discovery make test-ejbca-keys ENV=dev Test EJBCA key discovery Troubleshooting Problem: EJBCA shows &ldquo;CryptoToken does not contain any key pairs&rdquo; Cause: generate_certs: true is not set in kmsp11.yaml\nSolution:\nmake update-pkcs11-config ENV=dev make restart-ejbca ENV=dev Problem: &ldquo;Key with public key hash not on token&rdquo; when importing certificate Cause: Java SunPKCS11 cannot enumerate keys without certificate objects\nSolution: Ensure generate_certs: true is configured. The GCP PKCS#11 library will generate placeholder certificates.\nProblem: &ldquo;CKR_TEMPLATE_INCONSISTENT&rdquo; when generating keys Cause: GCP KMS requires CKA_KMS_ALGORITHM vendor attribute for key generation\nSolution: Create keys via gcloud CLI, not EJBCA. Then use existing keys in EJBCA.\nTechnical Background Why generate_certs: true is Required Java&rsquo;s SunPKCS11 provider requires private keys to have an associated certificate object (CKO_CERTIFICATE) with matching CKA_ID to be discoverable. By default, GCP Cloud KMS PKCS#11 only exposes:\nPrivate key objects Public key objects The generate_certs: true option tells the library to generate placeholder X.509 certificates at runtime for each asymmetric key. These certificates have:\nSubject: CN=&lt;key-label&gt; Matching CKA_ID with the private key This allows Java SunPKCS11 to enumerate the keys and EJBCA to discover them.\nTechnical Architecture &amp; Flow 1. Key Discovery with generate_certs: true This diagram illustrates why the generate_certs: true configuration is critical for EJBCA to discover GCP KMS keys.\nsequenceDiagram participant EJBCA as EJBCA (Java) participant SunP11 as SunPKCS11 Provider participant LibKMS as libkmsp11.so participant GCP as GCP Cloud KMS Note over LibKMS: Config: generate_certs: true EJBCA-&gt;&gt;SunP11: Activate CryptoToken SunP11-&gt;&gt;LibKMS: C_GetAttributeValue(CKA_ID, CKA_LABEL) par Key Retrieval LibKMS-&gt;&gt;GCP: List Keys (CryptoKeyVersions) GCP--&gt;&gt;LibKMS: Returns Asymmetric Keys end Note over LibKMS: CRITICAL STEP:&lt;br\/&gt;Generate Placeholder X.509 Certs&lt;br\/&gt;for each Key with matching CKA_ID LibKMS--&gt;&gt;SunP11: Returns Objects: 1. Private Key (CKO_PRIVATE_KEY) 2. Public Key (CKO_PUBLIC_KEY) 3. Certificate (CKO_CERTIFICATE) Note over SunP11: SunPKCS11 requires CKO_CERTIFICATE&lt;br\/&gt;to &#34;see&#34; the Private Key SunP11--&gt;&gt;EJBCA: Token Activated (Keys Visible) 2. Signing Flow (CA Operations) Once the keys are discovered, EJBCA can use them for signing certificates.\ngraph TD subgraph EJBCA_Container [EJBCA Docker Container] RA[RA\/CA Logic] SunP11[Java SunPKCS11] LibKMS[GCP KMS PKCS#11 Library] end subgraph GCP_Cloud [Google Cloud Platform] KMS[Cloud KMS \/ Cloud HSM] end RA -- &#34;Sign(Hash)&#34; --&gt; SunP11 SunP11 -- &#34;C_Sign(Session, Data)&#34; --&gt; LibKMS LibKMS -- &#34;AsymmetricSign(Key, Digest)&#34; --&gt; KMS KMS -- &#34;Signature (P-256)&#34; --&gt; LibKMS LibKMS -- &#34;Signature&#34; --&gt; SunP11 SunP11 -- &#34;Signature&#34; --&gt; RA Limitations Key Generation: Cannot generate keys from EJBCA (requires GCP-specific attributes) Placeholder Certs: Generated certificates are for compatibility only, not for CA operations Session Restart: EJBCA CE requires server restart if HSM connection is lost References GCP KMS PKCS#11 User Guide EJBCA PKCS#11 Documentation Oracle Java SunPKCS11 Guide Quick Test Commands Verify PKCS#11 Configuration # Test native PKCS#11 export KMS_PKCS11_CONFIG=\/etc\/kmsp11\/kmsp11.yaml pkcs11-tool --module \/opt\/kmsp11\/libkmsp11.so --list-objects # Test EJBCA key discovery sudo docker exec ejbca \/opt\/keyfactor\/bin\/ejbca.sh cryptotoken listkeys &#39;CloudHSM-PolicyCA&#39; # Test CA creation (if previous steps worked) sudo docker exec ejbca \/opt\/keyfactor\/bin\/ejbca.sh ca createca &#39;PolicyCA&#39; &#39;CloudHSM-PolicyCA&#39; Check EJBCA Health # Check EJBCA status curl -s http:\/\/localhost:8080\/ejbca\/publicweb\/healthcheck\/ejbcahealth # Check PKCS#11 config in EJBCA sudo docker exec ejbca cat \/opt\/keyfactor\/ejbca\/conf\/web.properties | grep -i p11 Conclusion B\u00e0i vi\u1ebft \u0111\u00e3 ph\u00e2n t\u00edch chi ti\u1ebft v\u1ec1 kh\u1ea3 n\u0103ng t\u01b0\u01a1ng th\u00edch gi\u1eefa EJBCA Community Edition v\u00e0 GCP Cloud KMS. M\u1eb7c d\u00f9 c\u00f3 gi\u1edbi h\u1ea1n ki\u1ebfn tr\u00fac c\u01a1 b\u1ea3n, nh\u01b0ng v\u1edbi t\u00f9y ch\u1ecdn generate_certs: true, ch\u00fang ta c\u00f3 th\u1ec3 \u0111\u1ea1t \u0111\u01b0\u1ee3c s\u1ef1 t\u00edch h\u1ee3p ho\u1ea1t \u0111\u1ed9ng cho m\u1ed9t s\u1ed1 use cases c\u1ee5 th\u1ec3.\nT\u00e0i li\u1ec7u n\u00e0y \u0111\u01b0\u1ee3c t\u1ea1o \u0111\u1ec3 h\u01b0\u1edbng d\u1eabn c\u00e0i \u0111\u1eb7t v\u00e0 c\u1ea5u h\u00ecnh th\u1ef1c t\u1ebf cho c\u00e1c b\u00ean li\u00ean quan.\n","permalink":"https:\/\/freepeak.github.io\/posts\/ejbca-gcp-kms-huong-dan-cai-dat\/","summary":"A working integration of EJBCA CE with GCP Cloud KMS over PKCS#11, with the generate_certs: true option.","title":"EJBCA + GCP Cloud KMS: A Practical Installation and Configuration Guide"},{"content":"T\u00f4i t\u1eebng ngh\u0129 v\u1ec1 Cryptography (m\u1eadt m\u00e3 h\u1ecdc) thu\u1ea7n t\u00fay l\u00e0 to\u00e1n h\u1ecdc. B\u1ea1n c\u00f3 m\u1ed9t thu\u1eadt to\u00e1n t\u1ed1t (RSA, ECC), b\u1ea1n c\u00f3 m\u1ed9t th\u01b0 vi\u1ec7n chu\u1ea9n (OpenSSL), b\u1ea1n ch\u1ea1y n\u00f3 tr\u00ean m\u1ed9t con server m\u1ea1nh. Th\u1ebf l\u00e0 an to\u00e0n.\nNh\u01b0ng th\u1ebf gi\u1edbi b\u1ea3o m\u1eadt ph\u1ea7n c\u1ee9ng (Hardware Security) l\u1ea1i c\u01b0\u1eddi v\u00e0o m\u1eb7t suy ngh\u0129 \u0111\u00f3.\nV\u1edbi d\u00e2n l\u00e0m ph\u1ea7n c\u1ee9ng, m\u1ed9t con server Linux b\u00ecnh th\u01b0\u1eddng l\u00e0 m\u1ed9t k\u1ebb &ldquo;nhi\u1ec1u chuy\u1ec7n&rdquo; (gossip).\nN\u00f3 \u0111\u1ec3 l\u1ed9 key trong RAM. N\u00f3 &ldquo;h\u00e9t&rdquo; l\u00ean cho hacker bi\u1ebft n\u00f3 \u0111ang t\u00ednh to\u00e1n c\u00e1i g\u00ec th\u00f4ng qua ti\u1ebfng \u1ed3n \u0111i\u1ec7n n\u0103ng ti\u00eau th\u1ee5. V\u00e0 t\u1ec7 nh\u1ea5t: root l\u00e0 ch\u00faa. N\u1ebfu ai \u0111\u00f3 c\u00f3 quy\u1ec1n root (ho\u1eb7c xui h\u01a1n, m\u1ed9t l\u1ed7 h\u1ed5ng ki\u1ec3u Heartbleed \u0111\u1ecdc \u0111\u01b0\u1ee3c b\u1ed9 nh\u1edb), th\u00ec private key c\u1ee7a b\u1ea1n kh\u00f4ng c\u00f2n l\u00e0 c\u1ee7a b\u1ea1n n\u1eefa. \u0110\u00f3 l\u00e0 l\u00fd do HSM (Hardware Security Module) ra \u0111\u1eddi. Kh\u00f4ng ph\u1ea3i \u0111\u1ec3 t\u00ednh to\u00e1n nhanh h\u01a1n. M\u00e0 \u0111\u1ec3 t\u1ea1o ra m\u1ed9t &ldquo;nh\u00e0 t\u00f9&rdquo; v\u1eadt l\u00fd cho c\u00e1c b\u00ed m\u1eadt.\nFIPS 140-2: when the casing costs more than the chip N\u1ebfu b\u1ea1n c\u1ea7m m\u1ed9t con HSM chu\u1ea9n (v\u00ed d\u1ee5 FIPS 140-2 Level 3) l\u00ean, b\u1ea1n s\u1ebd th\u1ea5y n\u00f3 n\u1eb7ng ch\u1ecbch. Kh\u00f4ng ph\u1ea3i v\u00ec nhi\u1ec1u linh ki\u1ec7n, m\u00e0 v\u00ec n\u00f3 \u0111\u01b0\u1ee3c \u0111\u1ed5 \u0111\u1eb7c ru\u1ed9t b\u1eb1ng Epoxy (keo resin c\u1ee9ng).\nT\u1ea1i sao? \u0110\u1ec3 ch\u1ed1ng l\u1ea1i nh\u1eefng g\u00e3 hacker c\u1ea7m khoan v\u00e0 dao m\u1ed5.\n\u1ede Level 3 v\u00e0 Level 4, HSM \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf nh\u01b0 m\u1ed9t qu\u1ea3 bom n\u1ed5 ch\u1eadm (theo ngh\u0129a b\u1ea3o v\u1ec7 d\u1eef li\u1ec7u):\nL\u1edbp v\u1ecf c\u1ea3m \u1ee9ng: N\u1ebfu ph\u00e1t hi\u1ec7n b\u1ecb c\u1ea1y, khoan, ho\u1eb7c thay \u0111\u1ed5i nhi\u1ec7t \u0111\u1ed9\/\u0111i\u1ec7n \u00e1p b\u1ea5t th\u01b0\u1eddng&hellip; C\u01a1 ch\u1ebf Zeroization (T\u1ef1 h\u1ee7y): &hellip;n\u00f3 s\u1ebd ngay l\u1eadp t\u1ee9c x\u00f3a s\u1ea1ch to\u00e0n b\u1ed9 key trong mili-gi\u00e2y. Bi\u1ebfn c\u00e1i c\u1ee5c kim lo\u1ea1i gi\u00e1 $20,000 th\u00e0nh c\u1ee5c g\u1ea1ch (brick) \u0111\u00fang ngh\u0129a \u0111en. \u0110\u00f3 l\u00e0 c\u00e1i gi\u00e1 c\u1ee7a s\u1ef1 an to\u00e0n: th\u00e0 ch\u1ebft (m\u1ea5t key) ch\u1ee9 kh\u00f4ng \u0111\u1ec3 l\u1ecdt v\u00e0o tay gi\u1eb7c.\nThe obsession with randomness (entropy) M\u00e1y t\u00ednh l\u00e0 nh\u1eefng k\u1ebb tu\u00e2n th\u1ee7 quy t\u1eafc tuy\u1ec7t \u0111\u1ed1i. B\u1eaft n\u00f3 &ldquo;ng\u1eabu nhi\u00ean&rdquo; c\u0169ng kh\u00f3 nh\u01b0 b\u1eaft m\u1ed9t \u00f4ng k\u1ebf to\u00e1n gi\u00e0 l\u00e0m th\u01a1 v\u1eady.\nTr\u00ean server th\u00f4ng th\u01b0\u1eddng, khi b\u1ea1n g\u1ecdi sinh key, h\u1ec7 \u0111i\u1ec1u h\u00e0nh s\u1ebd c\u1ed1 g\u1eafng gom g\u00f3p ch\u00fat s\u1ef1 &ldquo;h\u1ed7n lo\u1ea1n&rdquo; (entropy) t\u1eeb b\u1ea5t c\u1ee9 \u0111\u00e2u: ti\u1ebfng g\u00f5 ph\u00edm, di chu\u1ed9t, \u1ed5 c\u1ee9ng quay, g\u00f3i tin m\u1ea1ng \u0111\u1ebfn&hellip;\nNh\u01b0ng v\u1edbi nh\u1eefng c\u1eb7p key g\u1ed1c (Root CA) s\u1ed1ng 20 n\u0103m, tin v\u00e0o s\u1ef1 h\u1ed7n lo\u1ea1n c\u1ee7a chu\u1ed9t v\u00e0 b\u00e0n ph\u00edm l\u00e0 m\u1ed9t canh b\u1ea1c. N\u1ebfu ngu\u1ed3n random b\u1ecb \u0111o\u00e1n tr\u01b0\u1edbc (predictable), th\u00ec key c\u1ee7a b\u1ea1n c\u0169ng v\u1eady. Hacker kh\u00f4ng c\u1ea7n ph\u00e1 kh\u00f3a, h\u1ecd ch\u1ec9 c\u1ea7n t\u00e1i t\u1ea1o l\u1ea1i quy tr\u00ecnh sinh kh\u00f3a.\nHSM gi\u1ea3i quy\u1ebft vi\u1ec7c n\u00e0y b\u1eb1ng TRNG (True Random Number Generator). N\u00f3 kh\u00f4ng d\u00f9ng thu\u1eadt to\u00e1n gi\u1ea3 l\u1eadp. N\u00f3 d\u00f9ng v\u1eadt l\u00fd thu\u1ea7n t\u00fay. B\u00ean trong con chip l\u00e0 c\u00e1c m\u1ea1ch \u0111i\u1ec7n \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf \u0111\u1ec3 \u0111o &ldquo;ti\u1ebfng \u1ed3n&rdquo; v\u1eadt l\u00fd:\nNhi\u1ec7t \u0111\u1ed9ng h\u1ecdc (Thermal noise). Hi\u1ec7u \u1ee9ng th\u00e1c (Avalanche noise) c\u1ee7a diode. \u0110\u00f3 l\u00e0 s\u1ef1 ng\u1eabu nhi\u00ean c\u1ee7a v\u0169 tr\u1ee5, kh\u00f4ng ph\u1ea3i c\u1ee7a thu\u1eadt to\u00e1n. V\u00e0 v\u0169 tr\u1ee5 th\u00ec kh\u00f4ng ai \u0111o\u00e1n tr\u01b0\u1edbc \u0111\u01b0\u1ee3c.\nSide-Channel Attacks: when a hacker solves physics instead of maths \u0110\u00e2y l\u00e0 ph\u1ea7n t\u00f4i th\u00edch nh\u1ea5t. D\u00e2n ph\u1ea7n m\u1ec1m th\u01b0\u1eddng ngh\u0129 hacker s\u1ebd ng\u1ed3i gi\u1ea3i ph\u01b0\u01a1ng tr\u00ecnh to\u00e1n h\u1ecdc \u0111\u1ec3 t\u00ecm Private Key $d$ t\u1eeb Public Key $e$. Nh\u01b0ng hacker ph\u1ea7n c\u1ee9ng th\u1ef1c d\u1ee5ng h\u01a1n nhi\u1ec1u. H\u1ecd kh\u00f4ng t\u1ea5n c\u00f4ng v\u00e0o to\u00e1n h\u1ecdc. H\u1ecd t\u1ea5n c\u00f4ng v\u00e0o&hellip; c\u00e1i b\u00f3ng c\u1ee7a n\u00f3.\nKhi CPU th\u1ef1c hi\u1ec7n ph\u00e9p t\u00ednh crypto (v\u00ed d\u1ee5: nh\u00e2n s\u1ed1 l\u1edbn trong RSA), n\u00f3 ti\u00eau th\u1ee5 \u0111i\u1ec7n n\u0103ng v\u00e0 t\u1ed1n th\u1eddi gian.\nTiming Attacks: N\u1ebfu CPU x\u1eed l\u00fd bit 1 l\u00e2u h\u01a1n bit 0 (d\u00f9 ch\u1ec9 v\u00e0i nano-gi\u00e2y), hacker ch\u1ec9 c\u1ea7n \u0111o th\u1eddi gian ph\u1ea3n h\u1ed3i c\u1ee7a h\u00e0ng tri\u1ec7u request l\u00e0 c\u00f3 th\u1ec3 th\u1ed1ng k\u00ea ra chu\u1ed7i bit c\u1ee7a key.\nPower Analysis (SPA\/DPA): M\u1ed7i l\u1ea7n CPU x\u1eed l\u00fd m\u1ed9t ph\u00e9p t\u00ednh n\u1eb7ng, \u0111i\u1ec7n \u00e1p s\u1ee5t nh\u1eb9 m\u1ed9t c\u00e1i. V\u1edbi thi\u1ebft b\u1ecb \u0111o \u0111\u1ee7 nh\u1ea1y (oscilloscope), hacker nh\u00ecn v\u00e0o \u0111\u1ed3 th\u1ecb ti\u00eau th\u1ee5 \u0111i\u1ec7n l\u00e0 bi\u1ebft server \u0111ang x\u1eed l\u00fd c\u00e1i g\u00ec.\nHSM ch\u1ed1ng l\u1ea1i c\u00e1i n\u00e0y b\u1eb1ng c\u00e1ch&hellip; l\u00e0m m\u00e0u. N\u00f3 d\u00f9ng c\u00e1c thu\u1eadt to\u00e1n Constant-time: x\u1eed l\u00fd bit 0 hay bit 1 c\u0169ng ph\u1ea3i t\u1ed1n th\u1eddi gian y h\u1ec7t nhau. N\u00f3 b\u1ecdc c\u00e1c l\u1edbp l\u00e1 ch\u1eafn nhi\u1ec5u \u0111i\u1ec7n t\u1eeb (shielding) \u0111\u1ec3 t\u00edn hi\u1ec7u kh\u00f4ng l\u1ecdt ra ngo\u00e0i.\nN\u00f3i c\u00e1ch kh\u00e1c, HSM l\u00e0 m\u1ed9t &ldquo;poker face&rdquo; ho\u00e0n h\u1ea3o. D\u00f9 b\u00ean trong \u0111ang g\u00e0o th\u00e9t t\u00ednh to\u00e1n, b\u00ean ngo\u00e0i m\u1eb7t n\u00f3 v\u1eabn l\u1ea1nh tanh, kh\u00f4ng bi\u1ebfn s\u1eafc (kh\u00f4ng \u0111\u1ed5i d\u00f2ng \u0111i\u1ec7n, kh\u00f4ng tr\u1ec5 th\u1eddi gian).\nKey Wrapping: the import-export border rule Nguy\u00ean t\u1eafc v\u00e0ng c\u1ee7a HSM: Private Key kh\u00f4ng bao gi\u1edd \u0111\u01b0\u1ee3c xu\u1ea5t ra d\u01b0\u1edbi d\u1ea1ng plaintext.\nV\u1eady l\u00e0m sao \u0111\u1ec3 backup? Hay chuy\u1ec3n key sang HSM kh\u00e1c?\nCh\u00fang ta d\u00f9ng Key Wrapping. H\u00e3y t\u01b0\u1edfng t\u01b0\u1ee3ng key c\u1ee7a b\u1ea1n l\u00e0 m\u1ed9t b\u1ee9c th\u01b0 m\u1eadt. HSM kh\u00f4ng bao gi\u1edd cho ph\u00e9p b\u1ee9c th\u01b0 \u0111\u00f3 ra kh\u1ecfi c\u1eeda. N\u1ebfu b\u1eaft bu\u1ed9c ph\u1ea3i g\u1eedi \u0111i, HSM s\u1ebd l\u1ea5y m\u1ed9t c\u00e1i k\u00e9t s\u1eaft (Key Encryption Key - KEK), b\u1ecf b\u1ee9c th\u01b0 v\u00e0o, kh\u00f3a l\u1ea1i, r\u1ed3i m\u1edbi qu\u0103ng c\u00e1i k\u00e9t s\u1eaft ra ngo\u00e0i.\nCh\u1ec9 c\u00f3 m\u1ed9t con HSM kh\u00e1c, c\u00f3 \u0111\u00fang ch\u00eca kh\u00f3a c\u1ee7a c\u00e1i k\u00e9t \u0111\u00f3 (th\u01b0\u1eddng \u0111\u01b0\u1ee3c chia s\u1ebb qua quy tr\u00ecnh Smart Card ho\u1eb7c PED - PIN Entry Device), m\u1edbi m\u1edf \u0111\u01b0\u1ee3c.\nKey lu\u00f4n lu\u00f4n \u0111\u01b0\u1ee3c b\u1ecdc. T\u1eeb l\u00fac sinh ra cho \u0111\u1ebfn l\u00fac ch\u1ebft \u0111i.\nClosing: buying peace of mind Cu\u1ed1i c\u00f9ng, khi b\u1ea1n b\u1ecf ti\u1ec1n mua HSM, b\u1ea1n kh\u00f4ng mua t\u00ednh n\u0103ng. B\u1ea1n \u0111ang mua s\u1ef1 \u0111\u1ea3m b\u1ea3o v\u1ec1 v\u1eadt l\u00fd.\nB\u1ea1n mua m\u1ed9t c\u00e1i h\u1ed9p m\u00e0 b\u1ea1n bi\u1ebft ch\u1eafc r\u1eb1ng:\nS\u1ed1 ng\u1eabu nhi\u00ean sinh ra l\u00e0 th\u1eadt s\u1ef1 ng\u1eabu nhi\u00ean. Key n\u1eb1m trong \u0111\u00f3 an to\u00e0n h\u01a1n n\u1eb1m trong tay b\u1ea1n. V\u00e0 n\u1ebfu c\u00f3 ai \u0111\u00f3 c\u1ed1 g\u1eafng c\u1ea1y n\u00f3 ra, b\u00ed m\u1eadt s\u1ebd t\u1ef1 bi\u1ebfn m\u1ea5t tr\u01b0\u1edbc khi k\u1ecbp b\u1ecb nh\u00ecn th\u1ea5y. Trong th\u1ebf gi\u1edbi ph\u1ea7n m\u1ec1m \u0111\u1ea7y r\u1eaby l\u1ed7i v\u00e0 l\u1ed7 h\u1ed5ng, HSM l\u00e0 m\u1ed9t \u0111i\u1ec3m t\u1ef1a v\u1eadt l\u00fd hi\u1ebfm hoi m\u00e0 ch\u00fang ta c\u00f3 th\u1ec3 tin t\u01b0\u1edfng (g\u1ea7n nh\u01b0) tuy\u1ec7t \u0111\u1ed1i.\n\u0110\u1ecdc ti\u1ebfp: N\u1ebfu b\u1ea1n \u0111\u00e3 hi\u1ec3u HSM l\u00e0 g\u00ec, h\u00e3y xem c\u00e1ch \u00e1p d\u1ee5ng n\u00f3 v\u00e0o quy tr\u00ecnh th\u1ef1c t\u1ebf qua b\u00e0i vi\u1ebft: HSM V\u00e0 Nghi L\u1ec5 K\u00fd 3-tr\u00ean-5: Bi\u1ebfn Code Signing T\u1eeb Script Th\u00e0nh Quy Tr\u00ecnh.\n","permalink":"https:\/\/freepeak.github.io\/posts\/hsm-concept-definition\/","summary":"Why a regular Linux server is a terrible place to keep a private key. Decoding the hardcore concepts of HSMs: from self-destructing epoxy shells, to randomness harvested from physical noise, to keeping a poker face under power-analysis attacks.","title":"HSM: The Physical Fortress for Digital Secrets"},{"content":"G\u1ea7n \u0111\u00e2y t\u00f4i ph\u1ea3i build t\u00ednh n\u0103ng m\u1edbi. Kho\u1ea3ng 2-3 l\u1ea7n m\u1ed9t tu\u1ea7n. \u0110\u00f4i khi g\u1ea5p h\u01a1n. C\u00e0ng l\u00e0m c\u00e0ng th\u1ea5y time m\u00ecnh t\u1ed1n v\u00e0o vi\u1ec7c setup, configure, fix bug nhi\u1ec1u h\u01a1n l\u00e0 logic ch\u00ednh.\nT\u00f4i v\u1ed1n l\u00e0 engineer, kh\u00f4ng ph\u1ea3i product manager. Nh\u01b0ng v\u00ec deadline, t\u00f4i ph\u1ea3i t\u1ef1 l\u00e0m h\u1ebft. M\u1ed7i l\u1ea7n nh\u01b0 th\u1ebf l\u1ea1i t\u1ed1n kho\u1ea3ng 1-2 gi\u1edd ch\u1ec9 \u0111\u1ec3 setup environment, install dependencies, ch\u1ea1y test.\nV\u1ea5n \u0111\u1ec1 quan tr\u1ecdng nh\u1ea5t l\u00e0: l\u00e0m sao gi\u1ea3m time setup xu\u1ed1ng 15 ph\u00fat m\u00e0 kh\u00f4ng sacrifice quality? N\u1ebfu sai \u1edf b\u01b0\u1edbc n\u00e0y, m\u1ecdi th\u1ee9 downstream \u0111\u1ec1u sai - deploy ch\u1eadm, bug nhi\u1ec1u, team kh\u00f4ng c\u00f3 momentum.\nTrong AI coding c\u00f3 2 h\u01b0\u1edbng ch\u00ednh: autocomplete vs agent-based. Autocomplete th\u00ec nhanh nh\u01b0 Copilot, nh\u01b0ng ch\u1ec9 help \u1edf level d\u00f2ng code. Agent th\u00ec m\u1ea1nh h\u01a1n nh\u01b0 Cursor, Claude Code, nh\u01b0ng setup ph\u1ee9c t\u1ea1p v\u00e0 hay &ldquo;hallucinate&rdquo;.\nT\u00f4i ch\u1ecdn agent-based v\u00ec:\nProject ph\u1ee9c t\u1ea1p c\u1ea7n hi\u1ec3u context l\u1edbn Task involve nhi\u1ec1u file, nhi\u1ec1u system T\u00f4i mu\u1ed1n delegate c\u1ea3 qu\u00e1 tr\u00ecnh reasoning ch\u1ee9 kh\u00f4ng ch\u1ec9 syntax Nh\u01b0ng r\u1ed3i t\u00f4i nh\u1eadn ra: buyer priorities th\u1ef1c t\u1ebf c\u1ee7a dev team kh\u00e1c h\u1eb3n v\u1edbi nh\u1eefng g\u00ec vendor qu\u1ea3ng c\u00e1o.\nDev team th\u1ef1c t\u1ebf ch\u1ec9 quan t\u00e2m:\nT\u0103ng t\u1ed1c \u0111\u1ed9 ship feature Gi\u1ea3m bug v\u00e0 regression \u0110\u1eebng break existing code Trong khi c\u00e1c AI tool qu\u1ea3ng c\u00e1o: &ldquo;rewrite your entire codebase in minutes&rdquo;, &ldquo;100x productivity&rdquo;, &ldquo;zero bug&rdquo;. Nghe hay, nh\u01b0ng th\u1ef1c t\u1ebf th\u00ec gi\u1ed1ng nh\u01b0 b\u00e1n kh\u00f3a h\u1ecdc n\u00e2ng cao cho ng\u01b0\u1eddi \u0111ang n\u1eb1m li\u1ec7t gi\u01b0\u1eddng - h\u1ecd c\u1ea7n basic tr\u01b0\u1edbc.\nTh\u1eddi gian \u0111\u1ea7u t\u00f4i c\u1ee9 c\u00e0i h\u1ebft. Copilot xong c\u00e0i Cursor, Cursor xong th\u1eed Claude Code, r\u1ed3i l\u1ea1i t\u00ecm Windsurf, Roo, Trae&hellip; M\u1ed7i tool c\u00f3 setup ri\u00eang, key ri\u00eang, workflow ri\u00eang.\nSang th\u00e1ng 4 n\u0103m ngo\u00e1i, t\u00f4i \u0111\u1ecdc m\u1ed9t c\u00e2u trong Hacker News: &ldquo;Best tool is the one you already know how to use&rdquo;.\nNghe c\u00f3 v\u1ebb th\u1eeba. Nh\u01b0ng t\u00f4i nh\u1eadn ra: m\u00ecnh \u0111ang qu\u00e1 t\u1eadp trung v\u00e0o tool ch\u1ee9 kh\u00f4ng v\u00e0o skill.\nSkills.sh ra \u0111\u1eddi v\u1edbi \u00fd t\u01b0\u1edfng: thay v\u00ec c\u00e0i t\u1eebng tool, b\u1ea1n c\u00e0i &ldquo;skill&rdquo; - reusable capability m\u00e0 b\u1ea5t k\u1ef3 agent n\u00e0o c\u0169ng c\u00f3 th\u1ec3 d\u00f9ng. M\u1ed9t l\u1ec7nh:\nnpx skills add &lt;owner\/repo&gt; L\u00fac n\u00e0y m\u1edbi th\u1ea5y r\u00f5: AI agent tools th\u00ec nhi\u1ec1u, nh\u01b0ng skills m\u1edbi l\u00e0 th\u1ee9 th\u1ef1c s\u1ef1 t\u0103ng productivity.\nFramework c\u1ee7a t\u00f4i kh\u00e1 \u0111\u01a1n gi\u1ea3n, ch\u1ec9 3 b\u01b0\u1edbc:\nB\u01b0\u1edbc 1: Define task type\nCoding: web-design-guidelines, react-best-practices Review: code-review, test-driven-development Debug: systematic-debugging Deploy: cicd-workflows, deployment B\u01b0\u1edbc 2: Match v\u1edbi agent strengths\nQuick fix: d\u00f9ng Claude Code (CLI, fast) Long session: d\u00f9ng Cursor (VSCode-based) Parallel tasks: dispatch multiple agents via skills B\u01b0\u1edbc 3: Measure, iterate\nTime before vs after Bug rate before vs after Team satisfaction score L\u00e0m hi\u1ec7u qu\u1ea3 v\u1edbi AI coding tools l\u00e0:\nBi\u1ebft m\u00ecnh \u0111ang \u1edf giai \u0111o\u1ea1n n\u00e0o (exploration vs implementation) Ch\u1ecdn skill ph\u00f9 h\u1ee3p v\u1edbi task \u0111\u00f3 D\u00f9ng agent nh\u01b0 &ldquo;orchestrator&rdquo; ch\u1ee9 kh\u00f4ng ph\u1ea3i &ldquo;writer&rdquo; Anti-pattern t\u00f4i th\u1ea5y nhi\u1ec1u:\nTeam setup 10+ AI tools, nh\u01b0ng m\u1ed7i dev ch\u1ec9 d\u00f9ng 1-2 c\u00e1i. K\u1ebft qu\u1ea3? License ph\u00ed cao, adoption th\u1ea5p, ROI \u00e2m.\nM\u1ed9t v\u00ed d\u1ee5 kh\u00e1c: d\u00f9ng AI \u0111\u1ec3 refactor to\u00e0n b\u1ed9 codebase m\u00e0 kh\u00f4ng c\u00f3 test coverage. Nghe h\u1ee3p l\u00fd, nh\u01b0ng th\u1ef1c t\u1ebf th\u00ec nh\u01b0 s\u1eeda nh\u00e0 m\u00e0 kh\u00f4ng ki\u1ec3m tra n\u1ec1n m\u00f3ng. N\u00f3 s\u1ebd s\u1eadp.\nFramework n\u00e0y kh\u00f4ng ch\u1ec9 \u00e1p d\u1ee5ng cho c\u00e1 nh\u00e2n, m\u00e0 cho c\u1ea3 team, company. Level c\u00e0ng cao th\u00ec c\u00e0ng c\u1ea7n consistency - ai c\u0169ng ph\u1ea3i hi\u1ec3u same process, same expectation.\nCu\u1ed1i c\u00f9ng, chi\u1ebfn l\u01b0\u1ee3c d\u00f9ng AI coding tools l\u00e0 ch\u1ecdn skill c\u1ea7n h\u1ecdc v\u00e0 tool c\u1ea7n d\u00f9ng. Bi\u1ebft m\u00ecnh \u0111ang l\u00e0m g\u00ec, ch\u1ecdn tool ph\u00f9 h\u1ee3p, v\u00e0 measure k\u1ebft qu\u1ea3.\n\u0110\u00f3 l\u00e0 c\u00e1ch t\u00f4i gi\u1ea3m time setup t\u1eeb 2 gi\u1edd xu\u1ed1ng 15 ph\u00fat. Kh\u00f4ng ph\u1ea3i do tool magic, m\u00e0 do m\u00ecnh bi\u1ebft c\u1ea7n skill g\u00ec v\u00e0 d\u00f9ng nh\u01b0 th\u1ebf n\u00e0o.\nAI Agent Coding Tools List D\u01b0\u1edbi \u0111\u00e2y l\u00e0 t\u1ed5ng h\u1ee3p c\u00e1c AI agent coding tools h\u1ed7 tr\u1ee3 b\u1edfi Skills.sh:\nAMP - ampcode.com Antigravity - antigravity.google Claude Code - claude.com ClawdBot - clawd.bot Codex - openai.com Cursor - cursor.sh Droid - factory.ai Gemini - gemini.google.com GitHub Copilot - github.com Goose - block.github.io Kilo - kilo.ai Kiro CLI - clawd.bot OpenCode - opencode.ai Roo - roocode.com Trae - trae.ai Windsurf - codeium.com Popular Skills on Skills.sh Theo leaderboard, nh\u1eefng skill \u0111\u01b0\u1ee3c install nhi\u1ec1u nh\u1ea5t:\nSkill Owner Installs vercel-react-best-practices vercel-labs\/agent-skills 22.0K web-design-guidelines vercel-labs\/agent-skills 16.8K building-ui expo\/skills 1.2K upgrading-expo expo\/skills 1.2K data-fetching expo\/skills 1.1K dev-client expo\/skills 1.0K deployment expo\/skills 975 api-routes expo\/skills 938 cicd-workflows expo\/skills 903 tailwind-setup expo\/skills 874 ","permalink":"https:\/\/freepeak.github.io\/posts\/cach-su-dung-ai-agent-coding-tool-hieu-qua-voi-skills-sh\/","summary":"From installing dozens of tools to using the right tool at the right time - one practical framework","title":"How to Use AI Agent Coding Tools Effectively with Skills.sh"},{"content":"C\u00f3 m\u1ed9t th\u1eddi gian t\u00f4i nh\u00ecn code signing nh\u01b0 m\u1ed9t b\u01b0\u1edbc \u201cph\u1ee5\u201d trong pipeline.\nBuild xong. K\u00fd. \u0110\u1ea9y OTA. Nh\u01b0ng c\u00e0ng l\u00e0m v\u1edbi firmware, t\u00f4i c\u00e0ng th\u1ea5y \u201ck\u00fd\u201d kh\u00f4ng ph\u1ea3i l\u00e0 m\u1ed9t b\u01b0\u1edbc k\u1ef9 thu\u1eadt \u0111\u01a1n l\u1ebb. N\u00f3 l\u00e0 m\u1ed9t quy\u1ebft \u0111\u1ecbnh qu\u1ea3n tr\u1ecb r\u1ee7i ro.\nV\u00ec n\u1ebfu private key k\u00fd firmware b\u1ecb l\u1ed9, th\u1ee9 b\u1ea1n m\u1ea5t kh\u00f4ng ch\u1ec9 l\u00e0 m\u1ed9t artifact. B\u1ea1n m\u1ea5t ni\u1ec1m tin c\u1ee7a c\u1ea3 chu\u1ed7i cung \u1ee9ng.\nThe original question: what am I signing to protect? \u0110\u1ecbnh ngh\u0129a nghe r\u1ea5t \u0111\u1eb9p: \u201ck\u00fd s\u1ed1 \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o t\u00ednh to\u00e0n v\u1eb9n v\u00e0 x\u00e1c th\u1ef1c\u201d.\n\u0110\u1ecdc xong v\u1eabn c\u00f3 c\u1ea3m gi\u00e1c\u2026 tr\u1eebu t\u01b0\u1ee3ng.\n\u0110\u1ebfn khi \u0111\u1eb7t l\u1ea1i c\u00e2u h\u1ecfi cho \u0111\u00fang:\nM\u00ecnh \u0111ang b\u1ea3o v\u1ec7 binary hay b\u1ea3o v\u1ec7 quy\u1ec1n ph\u00e1t h\u00e0nh? K\u1ebb t\u1ea5n c\u00f4ng c\u1ea7n hack build server, hay ch\u1ec9 c\u1ea7n l\u1ea5y \u0111\u01b0\u1ee3c private key? N\u1ebfu private key n\u1eb1m trong m\u1ed9t file .pem tr\u00ean CI runner, th\u00ec \u0111\u00f4i khi c\u00e2u tr\u1ea3 l\u1eddi \u0111\u00e1ng bu\u1ed3n l\u00e0: kh\u00f4ng c\u1ea7n hack g\u00ec ph\u1ee9c t\u1ea1p, ch\u1ec9 c\u1ea7n \u201cl\u1ee1\u201d c\u00f3 ng\u01b0\u1eddi copy key ra kh\u1ecfi \u0111\u00fang ch\u1ed7.\nAn HSM is not for making crypto faster T\u00f4i t\u1eebng t\u01b0\u1edfng HSM l\u00e0 \u0111\u1ec3 t\u0103ng hi\u1ec7u n\u0103ng crypto. Nh\u01b0ng trong b\u1ed1i c\u1ea3nh code signing, gi\u00e1 tr\u1ecb ch\u00ednh c\u1ee7a HSM l\u00e0: (N\u1ebfu b\u1ea1n mu\u1ed1n hi\u1ec3u s\u00e2u h\u01a1n v\u1ec1 l\u1edbp v\u1ecf v\u1eadt l\u00fd, FIPS 140-2 v\u00e0 t\u1ea1i sao n\u00f3 an to\u00e0n \u0111\u1ebfn m\u1ee9c &lsquo;hoang t\u01b0\u1edfng&rsquo;, h\u00e3y \u0111\u1ecdc b\u00e0i HSM: Ph\u00e1o \u0110\u00e0i V\u1eadt L\u00fd Cho Nh\u1eefng B\u00ed M\u1eadt S\u1ed1)\nPrivate key \u0111\u01b0\u1ee3c sinh ra v\u00e0 n\u1eb1m trong ph\u1ea7n c\u1ee9ng. Private key kh\u00f4ng \u0111\u01b0\u1ee3c \u201cexport\u201d theo ngh\u0129a th\u1ef1c d\u1ee5ng (kh\u00f4ng c\u00f3 file \u0111\u1ec3 copy). Ng\u01b0\u1eddi k\u00fd ph\u1ea3i c\u1eafm thi\u1ebft b\u1ecb + nh\u1eadp PIN, t\u1ee9c l\u00e0 c\u00f3 s\u1ef1 hi\u1ec7n di\u1ec7n. N\u00f3i c\u00e1ch kh\u00e1c: HSM bi\u1ebfn \u201ck\u00fd\u201d t\u1eeb m\u1ed9t h\u00e0m trong code th\u00e0nh m\u1ed9t h\u00e0nh vi c\u00f3 ma s\u00e1t.\nMa s\u00e1t n\u00e0y ch\u00ednh l\u00e0 th\u1ee9 c\u1ee9u b\u1ea1n trong nh\u1eefng ng\u00e0y xui.\nThe decision tree: why a portable HSM (instead of a huge one) Khi ch\u1ecdn HSM cho h\u1ec7 th\u1ed1ng k\u00fd firmware, t\u00f4i th\u1ea5y c\u00f3 \u00edt nh\u1ea5t 3 h\u01b0\u1edbng (m\u1ed7i h\u01b0\u1edbng c\u00f3 c\u00e1i gi\u00e1 ri\u00eang):\nHSM d\u1ea1ng appliance (\u0111\u1eb7t trong data center) \u01afu: t\u1eadp trung, ki\u1ec3m so\u00e1t ch\u1eb7t. Nh\u01b0\u1ee3c: v\u1eadn h\u00e0nh n\u1eb7ng; d\u1ec5 tr\u1edf th\u00e0nh \u201csingle bottleneck\u201d cho release. Cloud HSM \u01afu: t\u00edch h\u1ee3p t\u1ed1t v\u1edbi cloud stack. Nh\u01b0\u1ee3c: r\u00e0ng bu\u1ed9c cloud; c\u00e2u chuy\u1ec7n \u201cai gi\u1eef key\u201d \u0111\u00f4i khi kh\u00f3 n\u00f3i. HSM d\u1ea1ng portable cho signer \u01afu: chia quy\u1ec1n k\u00fd cho nhi\u1ec1u ng\u01b0\u1eddi; gi\u1ea3m \u0111i\u1ec3m ch\u1ebft. Nh\u01b0\u1ee3c: ph\u1ea3i qu\u1ea3n l\u00fd ph\u00e2n ph\u1ed1i, quy tr\u00ecnh, audit. Trong m\u1ed9t tri\u1ec3n khai \u0111i\u1ec3n h\u00ecnh, l\u1ef1a ch\u1ecdn \u1edf \u0111\u00e2y l\u00e0 m\u1ed9t HSM d\u1ea1ng portable: nh\u1ecf, c\u00f3 ch\u1ee9ng nh\u1eadn, h\u1ed7 tr\u1ee3 PKCS#11, \u0111\u1ee7 d\u00f9ng cho k\u00fd Ed25519, v\u00e0 quan tr\u1ecdng l\u00e0 c\u00f3 th\u1ec3 ph\u00e1t cho t\u1eebng signer.\nReality check: what do buyers (and the ops team) actually care about? N\u1ebfu b\u1ecf h\u1ebft jargon, t\u00f4i th\u1ea5y y\u00eau c\u1ea7u th\u1ef1c t\u1ebf hay r\u01a1i v\u00e0o 3 nh\u00f3m (v\u00e0 nh\u00f3m n\u00e0o c\u0169ng \u201c\u0111\u00fang\u201d, ch\u1ec9 kh\u00e1c th\u1ee9 t\u1ef1 \u01b0u ti\u00ean):\nGi\u1ea3m r\u1ee7i ro l\u1ed9 key (blast radius nh\u1ecf) Kh\u00f4ng l\u00e0m release b\u1ecb k\u1eb9t (velocity) C\u00f3 audit trail \u0111\u1ec3 gi\u1ea3i tr\u00ecnh (ai k\u00fd, k\u00fd c\u00e1i g\u00ec, l\u00fac n\u00e0o) Nhi\u1ec1u h\u1ec7 th\u1ed1ng k\u00fd s\u1ed1 th\u1ea5t b\u1ea1i v\u00ec c\u1ed1 t\u1ed1i \u01b0u nh\u00f3m (1) nh\u01b0ng l\u00e0m n\u00e1t nh\u00f3m (2): m\u1ecdi th\u1ee9 ph\u1ea3i qua m\u1ed9t \u201c\u00f4ng admin gi\u1eef key\u201d, \u0111\u1ebfn l\u00fac \u00f4ng \u0111\u00f3 \u0111i h\u1ecdp l\u00e0 release \u0111\u1ee9ng h\u00ecnh.\nThe 3-of-5 signing ritual: looks like paperwork, is actually a guardrail Thi\u1ebft k\u1ebf 3-tr\u00ean-5 (3-of-5) nghe c\u00f3 v\u1ebb \u201ccorporate\u201d, nh\u01b0ng n\u00f3 gi\u1ea3i \u0111\u01b0\u1ee3c m\u1ed9t b\u00e0i to\u00e1n r\u1ea5t \u0111\u1eddi th\u01b0\u1eddng:\nKh\u00f4ng mu\u1ed1n 1 ng\u01b0\u1eddi c\u00f3 th\u1ec3 t\u1ef1 \u00fd ph\u00e1t h\u00e0nh firmware. Nh\u01b0ng c\u0169ng kh\u00f4ng th\u1ec3 b\u1eaft \u0111\u1ee7 5 ng\u01b0\u1eddi online c\u00f9ng l\u00fac. M\u1ed9t c\u00e1ch nh\u00ecn \u0111\u01a1n gi\u1ea3n:\nBuild Server -&gt; Signing Server -&gt; (signing request) -&gt; 5 Signers |-&gt; thu \u00edt nh\u1ea5t 3 ch\u1eef k\u00fd h\u1ee3p l\u1ec7 v OTA\/Release \u0110i\u1ec3m hay l\u00e0 b\u1ea1n \u0111ang chia r\u1ee7i ro theo c\u1ea3 hai tr\u1ee5c:\nTr\u1ee5c k\u1ef9 thu\u1eadt: key n\u1eb1m trong HSM, kh\u00f4ng r\u1eddi kh\u1ecfi thi\u1ebft b\u1ecb. Tr\u1ee5c t\u1ed5 ch\u1ee9c: quy\u1ec1n ph\u00e1t h\u00e0nh c\u1ea7n \u0111\u1ed3ng thu\u1eadn, kh\u00f4ng ph\u1ee5 thu\u1ed9c m\u1ed9t ng\u01b0\u1eddi. A 3-step framework for thinking about firmware signing (pragmatic) N\u1ebfu ph\u1ea3i n\u00e9n m\u1ecdi th\u1ee9 l\u1ea1i \u0111\u1ec3 tri\u1ec3n khai \u0111\u01b0\u1ee3c, t\u00f4i d\u00f9ng 3 b\u01b0\u1edbc sau:\nKh\u00f3a (keys) Ch\u1ec9 \u0111\u01b0a private key v\u00e0o n\u01a1i c\u00f3 ki\u1ec3m so\u00e1t m\u1ea1nh nh\u1ea5t. \u01afu ti\u00ean \u201ckh\u00f4ng th\u1ec3 copy\u201d thay v\u00ec \u201ckh\u00f3 copy\u201d. Nghi l\u1ec5 (ceremony) Ai \u0111\u01b0\u1ee3c k\u00fd? K\u00fd c\u00e1i g\u00ec? C\u1eeda s\u1ed5 k\u00fd m\u1edf bao l\u00e2u? Multi-party approval (v\u00ed d\u1ee5 3-tr\u00ean-5) l\u00e0 lu\u1eadt t\u1ed5 ch\u1ee9c, kh\u00f4ng ph\u1ea3i t\u00ednh n\u0103ng. B\u1eb1ng ch\u1ee9ng (audit) Log kh\u00f4ng ph\u1ea3i \u0111\u1ec3 \u201c\u0111\u1eb9p\u201d, m\u00e0 \u0111\u1ec3 khi c\u00f3 s\u1ef1 c\u1ed1 b\u1ea1n tr\u1ea3 l\u1eddi \u0111\u01b0\u1ee3c: chuy\u1ec7n g\u00ec \u0111\u00e3 x\u1ea3y ra. M\u1ed9t m\u1ea3nh gh\u00e9p th\u01b0\u1eddng b\u1ecb xem nh\u1eb9 l\u00e0 chu\u1ea9n giao ti\u1ebfp gi\u1eefa tool v\u00e0 HSM: PKCS#11. B\u1ea1n kh\u00f4ng c\u1ea7n nh\u1edb h\u1ebft API, ch\u1ec9 c\u1ea7n gi\u1eef m\u1ed9t mental model ki\u1ec3u \u201cclient trao \u0111\u1ed5i v\u1edbi HSM\u201d nh\u01b0 d\u01b0\u1edbi \u0111\u00e2y:\nPKCS#11: signing client &lt;-&gt; HSM Signing Client (app\/tool) HSM (PKCS#11 token) ----------------------------------------------------------------- 1) C_Initialize() -&gt; token ready 2) C_OpenSession() -&gt; session handle 3) C_Login(PIN) -&gt; verify PIN \/ policy 4) C_FindObjects*() -&gt; key handle (non-exportable) 5) C_Sign(digest) -&gt; sign with private key digest -----------------------------&gt; signature &lt;-------------------------- 6) C_Logout() + C_CloseSession() -&gt; clear state 7) C_Finalize() -&gt; unload module Key idea: digest goes in, signature comes out; private key never leaves HSM. Anti-pattern: turning a private key into just another secret M\u1ed9t s\u1ed1 ph\u1ea3n x\u1ea1 r\u1ea5t t\u1ef1 nhi\u00ean (v\u00e0 r\u1ea5t nguy hi\u1ec3m):\nNh\u00e9t private key v\u00e0o CI secrets v\u00ec \u201cti\u1ec7n\u201d. Cho build server quy\u1ec1n k\u00fd tr\u1ef1c ti\u1ebfp v\u00ec \u201ct\u1ef1 \u0111\u1ed9ng h\u00f3a\u201d. \u0110\u1ec3 m\u1ed9t ng\u01b0\u1eddi v\u1eeba build v\u1eeba k\u00fd v\u00ec \u201c\u00edt ng\u01b0\u1eddi th\u00ec l\u00e0m g\u00ec c\u00f3 separation-of-duties\u201d. Nh\u1eefng th\u1ee9 n\u00e0y \u0111\u1ec1u c\u00f3 chung m\u1ed9t b\u1ec7nh: n\u00f3 l\u00e0m gi\u1ea3m ma s\u00e1t \u0111\u1ebfn m\u1ee9c k\u1ebb t\u1ea5n c\u00f4ng ch\u1ec9 c\u1ea7n chi\u1ebfm m\u1ed9t h\u1ec7 th\u1ed1ng (CI\/build) l\u00e0 c\u00f3 quy\u1ec1n ph\u00e1t h\u00e0nh.\nHSM kh\u00f4ng l\u00e0m b\u1ea1n mi\u1ec5n nhi\u1ec5m. N\u00f3 ch\u1ec9 gi\u00fap b\u1ea1n bu\u1ed9c h\u1ec7 th\u1ed1ng ph\u1ea3i tr\u1ea3 l\u1eddi c\u00e2u h\u1ecfi: \u201cKey \u0111ang \u1edf \u0111\u00e2u, ai \u0111ang ch\u1ea1m v\u00e0o n\u00f3?\u201d\nClosing T\u00f4i th\u00edch nh\u00ecn HSM nh\u01b0 m\u1ed9t c\u00e1ch \u201c\u0111\u1ecbnh h\u00ecnh h\u00e0nh vi\u201d h\u01a1n l\u00e0 m\u1ed9t m\u00f3n \u0111\u1ed3 crypto.\nKhi b\u1ea1n thi\u1ebft k\u1ebf k\u00fd firmware v\u1edbi HSM + 3-tr\u00ean-5, b\u1ea1n \u0111ang n\u00f3i th\u1eb3ng m\u1ed9t nguy\u00ean t\u1eafc:\nQuy\u1ec1n ph\u00e1t h\u00e0nh kh\u00f4ng thu\u1ed9c v\u1ec1 m\u1ed9t script. N\u00f3 thu\u1ed9c v\u1ec1 m\u1ed9t quy tr\u00ecnh c\u00f3 ng\u01b0\u1eddi ch\u1ecbu tr\u00e1ch nhi\u1ec7m, c\u00f3 \u0111\u1ed3ng thu\u1eadn, v\u00e0 c\u00f3 d\u1ea5u v\u1ebft. V\u00e0 n\u1ebfu ph\u1ea3i nh\u1edb m\u1ed9t c\u00e2u \u0111\u1ec3 mang sang d\u1ef1 \u00e1n kh\u00e1c: \u0111\u1eebng t\u1ed1i \u01b0u s\u1ef1 ti\u1ec7n cho ng\u01b0\u1eddi k\u00fd \u0111\u1ebfn m\u1ee9c qu\u00ean m\u1ea5t s\u1ef1 an to\u00e0n cho ng\u01b0\u1eddi d\u00f9ng.\nQuick definitions (so you do not get lost) Thu\u1eadt ng\u1eef Ngh\u0129a trong b\u00e0i n\u00e0y OTA Over-The-Air: k\u00eanh ph\u00e1t h\u00e0nh\/c\u1eadp nh\u1eadt firmware t\u1eeb server xu\u1ed1ng thi\u1ebft b\u1ecb qua m\u1ea1ng. HSM (Hardware Security Module) Thi\u1ebft b\u1ecb ph\u1ea7n c\u1ee9ng gi\u1eef private key v\u00e0 th\u1ef1c hi\u1ec7n thao t\u00e1c k\u00fd; private key kh\u00f4ng r\u1eddi kh\u1ecfi thi\u1ebft b\u1ecb. Code signing K\u00fd s\u1ed1 l\u00ean firmware \u0111\u1ec3 thi\u1ebft b\u1ecb ki\u1ec3m tra \u201cai ph\u00e1t h\u00e0nh\u201d v\u00e0 \u201cc\u00f3 b\u1ecb s\u1eeda kh\u00f4ng\u201d. Signer Ng\u01b0\u1eddi \u0111\u01b0\u1ee3c c\u1ea5p quy\u1ec1n k\u00fd (m\u1ed7i ng\u01b0\u1eddi gi\u1eef 1 HSM). Signing ceremony Quy tr\u00ecnh\/\u201cnghi l\u1ec5\u201d t\u1ed5 ch\u1ee9c vi\u1ec7c k\u00fd: ai k\u00fd, k\u00fd c\u00e1i g\u00ec, trong c\u1eeda s\u1ed5 th\u1eddi gian n\u00e0o, audit ra sao. 3-of-5 C\u1ea7n \u00edt nh\u1ea5t 3 ch\u1eef k\u00fd h\u1ee3p l\u1ec7 trong 5 signer \u0111\u1ec3 ph\u00e1t h\u00e0nh. Digest Gi\u00e1 tr\u1ecb b\u0103m (v\u00ed d\u1ee5 SHA-256) \u0111\u1ea1i di\u1ec7n cho n\u1ed9i dung image; th\u01b0\u1eddng k\u00fd tr\u00ean digest thay v\u00ec k\u00fd c\u1ea3 file. Ed25519 Thu\u1eadt to\u00e1n ch\u1eef k\u00fd (ECC) cho ch\u1eef k\u00fd 64 bytes, nhanh v\u00e0 g\u1ecdn cho firmware. PKCS#11 Chu\u1ea9n API \u0111\u1ec3 app n\u00f3i chuy\u1ec7n v\u1edbi HSM (open session, login, sign&hellip;). mTLS Mutual TLS: client v\u00e0 server \u0111\u1ec1u x\u00e1c th\u1ef1c l\u1eabn nhau b\u1eb1ng certificate khi k\u1ebft n\u1ed1i. Signing request (trong b\u00e0i n\u00e0y) Y\u00eau c\u1ea7u k\u00fd (payload + metadata). Tr\u00e1nh nh\u1ea7m v\u1edbi Certificate Signing Request. ","permalink":"https:\/\/freepeak.github.io\/posts\/hsm-3-tren-5-ky-so-firmware-yubihsm2\/","summary":"An HSM is not just a hardware crypto box. It is a way to force digital signing - so often reduced to a script in CI - back into a ritual with constraints: the key never leaves the device, the signer shows up in person, and the signature needs enough people to agree.","title":"HSM and the 3-of-5 Signing Ritual: Turning Code Signing From a Script Into a Process"},{"content":"About money Th\u00f4ng b\u00e1o l\u01b0\u01a1ng v\u1ec1 l\u00fac 9:03 s\u00e1ng.\nM\u1ed9t c\u00e1i rung nh\u1eb9, m\u1ed9t d\u00f2ng s\u1ed1 nh\u1ea3y l\u00ean, v\u00e0 t\u1ef1 nhi\u00ean c\u1ea3 tu\u1ea7n t\u00f4i bi\u1ebft c\u01b0\u1eddi l\u1ecbch s\u1ef1 h\u01a1n. T\u00f4i hay g\u1ecdi \u0111\u00f3 l\u00e0 \u201cti\u1ec1n an th\u1ea7n\u201d: n\u00f3 kh\u00f4ng l\u00e0m m\u00ecnh th\u00f4ng minh h\u01a1n, nh\u01b0ng l\u00e0m m\u00ecnh d\u1ec5 \u0111\u1ec3 y\u00ean nh\u1eefng c\u00e2u h\u1ecfi kh\u00f3.\nT\u00f4i bi\u1ebft sai v\u1eabn l\u00e0m.\nC\u00e1i sai \u1edf \u0111\u00e2y kh\u00f4ng ph\u1ea3i l\u00e0 \u201c\u0111i l\u00e0m\u201d (\u0111i l\u00e0m c\u00f3 g\u00ec sai). C\u00e1i sai l\u00e0 c\u00e1i kho\u1ea3nh kh\u1eafc m\u00ecnh gi\u1ea3 b\u1ed9 nh\u01b0 kh\u00f4ng c\u00f3 giao d\u1ecbch n\u00e0o \u0111ang x\u1ea3y ra: m\u00ecnh \u0111\u01b0a 8 ti\u1ebfng m\u1ed7i ng\u00e0y, \u0111\u1ed5i l\u1ea1i m\u1ed9t ph\u1ea7n an t\u00e2m.\nSpoiler: n\u1ebfu ai \u0111\u1ed5i \u201can t\u00e2m\u201d b\u1eb1ng ti\u1ec1n, th\u00ec an t\u00e2m \u0111\u00f3 th\u01b0\u1eddng l\u00e0 h\u00e0ng c\u00f3 h\u1ea1n s\u1eed d\u1ee5ng.\nWhy we work N\u1ebfu g\u1ecdi th\u1eb3ng ra, t\u00f4i th\u1ea5y ch\u00fang ta \u0111i l\u00e0m v\u00ec ba th\u1ee9 r\u1ea5t ng\u01b0\u1eddi, v\u00e0 r\u1ea5t d\u1ec5 hi\u1ec3u.\nTh\u1ee9 nh\u1ea5t: v\u00ec c\u1ea7n s\u1ed1ng.\nThu\u00ea nh\u00e0, ti\u1ec1n s\u1eeda r\u0103ng, ti\u1ec1n thu\u1ed1c, ti\u1ec1n b\u1ecb b\u1ec7nh, ti\u1ec1n cho b\u1ed1 m\u1eb9, ti\u1ec1n h\u1ecdc c\u1ee7a con. Con ng\u01b0\u1eddi kh\u00f4ng \u0103n l\u00fd t\u01b0\u1edfng \u0111\u01b0\u1ee3c.\nTh\u1ee9 hai: v\u00ec c\u1ea7n \u0111\u01b0\u1ee3c c\u00f4ng nh\u1eadn.\n\u0110i l\u00e0m kh\u00f4ng ch\u1ec9 l\u00e0 b\u00e1n s\u1ee9c lao \u0111\u1ed9ng. N\u00f3 l\u00e0 mua m\u1ed9t c\u00e1i nh\u00e3n: \u201ct\u00f4i c\u00f3 \u00edch\u201d. M\u1ed9t c\u00e1i badge, m\u1ed9t c\u00e1i title, m\u1ed9t c\u00e1i email domain, l\u00e0 t\u1ef1 nhi\u00ean m\u00ecnh th\u1ea5y m\u00ecnh c\u00f3 ch\u1ed7 \u0111\u1ee9ng tr\u00ean \u0111\u1eddi.\nTh\u1ee9 ba: v\u00ec s\u1ee3 b\u1ecb b\u1ecf l\u1ea1i.\n\u1ede nh\u00e0 qu\u00e1 l\u00e2u, m\u00ecnh s\u1ebd nghe r\u00f5 ti\u1ebfng \u0111\u1ed3ng h\u1ed3 v\u00e0 ti\u1ebfng nh\u1eefng c\u00e2u h\u1ecfi. \u0110i l\u00e0m l\u00e0 c\u00e1ch m\u00ecnh l\u00e0m \u1ed3n, t\u01b0\u1edfng nh\u01b0 \u0111ang ti\u1ebfn l\u00ean. \u0110\u01b0\u1eddng th\u1eb3ng hay v\u00f2ng kh\u00f4ng quan tr\u1ecdng. Quan tr\u1ecdng l\u00e0 m\u00ecnh v\u1eabn \u0111ang \u201c\u0111i\u201d.\nBa l\u00fd do \u0111\u00f3 \u0111\u1ec1u h\u1ee3p l\u00fd. V\u00ec n\u00f3 h\u1ee3p l\u00fd n\u00ean n\u00f3 c\u00e0ng kh\u00f3 tho\u00e1t.\nSelling yourself to capital is selling what N\u00f3i \u201cb\u00e1n m\u00ecnh cho t\u01b0 b\u1ea3n\u201d nghe nh\u01b0 m\u1ed9t c\u00e2u kh\u1ea9u hi\u1ec7u. Nh\u01b0ng n\u1ebfu b\u1ecf ch\u1eef ngh\u0129a \u0111i, n\u00f3 ch\u1ec9 l\u00e0 m\u1ed9t m\u00f4 t\u1ea3 \u0111\u1eddi th\u01b0\u1eddng: ta \u0111em m\u1ed9t ph\u1ea7n \u0111\u1eddi m\u00ecnh ra \u0111\u1ed5i l\u1ea5y ti\u1ec1n.\nV\u1ea5n \u0111\u1ec1 l\u00e0 ta kh\u00f4ng b\u00e1n m\u1ed9t l\u1ea7n. Ta cho thu\u00ea theo th\u00e1ng.\nCho thu\u00ea th\u1eddi gian.\nCho thu\u00ea s\u1ef1 ch\u00fa \u00fd.\nCho thu\u00ea s\u1ef1 ki\u00ean nh\u1eabn.\nCho thu\u00ea c\u00e1i m\u1eb7t \u201ckh\u00f4ng sao \u0111\u00e2u\u201d \u0111\u1ec3 gi\u1eef h\u00f2a kh\u00ed.\nV\u00e0 v\u00ec l\u00e0 cho thu\u00ea n\u00ean n\u00f3 c\u00f3 \u0111i\u1ec1u kho\u1ea3n. \u0110i\u1ec1u kho\u1ea3n th\u01b0\u1eddng kh\u00f4ng vi\u1ebft ra, nh\u01b0ng ai c\u0169ng ng\u1ea7m hi\u1ec3u:\nB\u1ea1n s\u1ebd c\u00f3 nh\u1eefng ng\u00e0y ch\u00e1n vi\u1ec7c, nh\u01b0ng v\u1eabn ph\u1ea3i t\u1ecf ra \u201cprofessional\u201d. B\u1ea1n s\u1ebd c\u00f3 nh\u1eefng c\u00e2u h\u1ecfi \u0111\u1ea1o \u0111\u1ee9c, nh\u01b0ng \u01b0u ti\u00ean c\u1ee7a b\u1ea1n l\u00e0 h\u00f3a \u0111\u01a1n cu\u1ed1i th\u00e1ng. B\u1ea1n s\u1ebd th\u1ea5y h\u1ec7 th\u1ed1ng c\u00f3 v\u1ea5n \u0111\u1ec1, nh\u01b0ng h\u1ec7 th\u1ed1ng kh\u00f4ng tr\u1ea3 l\u01b0\u01a1ng cho \u201cth\u1ea5y\u201d. T\u01b0 b\u1ea3n, \u1edf m\u1ee9c \u0111\u1eddi th\u01b0\u1eddng nh\u1ea5t, kh\u00f4ng ph\u1ea3i m\u1ed9t \u00f4ng ch\u1ee7 ng\u1ed3i vu\u1ed1t r\u00e2u c\u01b0\u1eddi. N\u00f3 l\u00e0 m\u1ed9t c\u01a1 ch\u1ebf c\u00f3 n\u0103ng l\u1ef1c bi\u1ebfn th\u1eddi gian s\u1ed1ng th\u00e0nh chi ph\u00ed v\u1eadn h\u00e0nh.\nC\u00f2n ch\u00fang ta c\u0169ng c\u00f3 m\u1ed9t n\u0103ng l\u1ef1c kh\u00f4ng k\u00e9m: t\u1ef1 thuy\u1ebft ph\u1ee5c m\u00ecnh r\u1eb1ng \u201c\u0111\u00e2y l\u00e0 b\u00ecnh th\u01b0\u1eddng\u201d.\nT\u00f4i hay t\u1ef1 gi\u1ec5u r\u1eb1ng trong \u0111\u1ea7u m\u00ecnh c\u00f3 m\u1ed9t startup v\u00f4 h\u00ecnh, chuy\u00ean g\u1ecdi v\u1ed1n b\u1eb1ng c\u00e2u: \u201cR\u00e1ng th\u00eam ch\u00fat n\u1eefa l\u00e0 \u1ed5n.\u201d Startup \u0111\u00f3 ch\u01b0a bao gi\u1edd IPO, nh\u01b0ng g\u1ecdi v\u1ed1n r\u1ea5t \u0111\u1ec1u.\nWhy people split into camps and hate each other N\u1ebfu ch\u1ec9 c\u00f3 chuy\u1ec7n \u201c\u0111i l\u00e0m \u0111\u1ec3 s\u1ed1ng\u201d, ta \u0111\u00e3 c\u00f3 th\u1ec3 th\u01b0\u01a1ng nhau h\u01a1n. Nh\u01b0ng kh\u00f4ng. Ta chia phe.\nPhe ng\u01b0\u1eddi l\u00e0m v\u0103n ph\u00f2ng c\u01b0\u1eddi ng\u01b0\u1eddi l\u00e0m tay ch\u00e2n. Phe \u201cng\u00e0nh hot\u201d c\u01b0\u1eddi phe \u201cng\u00e0nh l\u01b0\u01a1ng th\u1ea5p\u201d. Phe c\u00f3 t\u00e0i s\u1ea3n c\u01b0\u1eddi phe thu\u00ea nh\u00e0.\nR\u1ed3i trong c\u00f4ng ty: team n\u00e0y gh\u00e9t team kia, nh\u00e2n vi\u00ean gh\u00e9t s\u1ebfp, s\u1ebfp gh\u00e9t nh\u00e2n vi\u00ean.\nT\u00f4i ngh\u0129 c\u00f3 ba \u0111\u1ed9ng c\u01a1 ch\u00ednh.\nTh\u1ee9 nh\u1ea5t: khan hi\u1ebfm t\u1ea1o ra cu\u1ed9c chi\u1ebfn ngang.\nKhi t\u00e0i nguy\u00ean khan hi\u1ebfm (ti\u1ec1n, c\u01a1 h\u1ed9i, ch\u1ed7 \u0111\u1ee9ng), con ng\u01b0\u1eddi c\u00f3 xu h\u01b0\u1edbng \u0111\u00e1nh nhau v\u1edbi ng\u01b0\u1eddi \u0111\u1ee9ng c\u1ea1nh m\u00ecnh.\nTrong m\u1ed9t c\u0103n ph\u00f2ng thi\u1ebfu oxy, ng\u01b0\u1eddi ta gi\u00e0nh nhau c\u00e1i b\u00ecnh th\u1edf, ch\u1ee9 kh\u00f4ng c\u00f3 th\u1eddi gian \u0111i h\u1ecfi v\u00ec sao c\u1eeda ph\u00f2ng b\u1ecb kh\u00f3a.\nKhi layoff r\u00ecnh r\u1eadp, th\u0103ng ti\u1ebfn \u00edt \u0111i, th\u01b0\u1edfng gi\u1ea3m, ng\u01b0\u1eddi ta nh\u00ecn \u0111\u1ed3ng nghi\u1ec7p nh\u01b0 m\u1ed9t bi\u1ebfn s\u1ed1. Kh\u00f4ng c\u00f2n l\u00e0 \u201cng\u01b0\u1eddi c\u00f9ng ch\u1ecbu\u201d, m\u00e0 l\u00e0 \u201c\u0111\u1ed1i th\u1ee7 c\u00f9ng ph\u00f2ng\u201d.\nTh\u1ee9 hai: b\u1ea3n s\u1eafc l\u00e0 thu\u1ed1c gi\u1ea3m \u0111au.\nCon ng\u01b0\u1eddi ch\u1ecbu \u0111au gi\u1ecfi h\u01a1n khi n\u1ed7i \u0111au c\u00f3 t\u00ean. \u201cT\u00f4i thu\u1ed9c phe ch\u0103m ch\u1ec9\u201d, \u201ct\u00f4i thu\u1ed9c phe t\u1ec9nh th\u1ee9c\u201d, \u201ct\u00f4i thu\u1ed9c phe th\u1ef1c t\u1ebf\u201d, \u201ct\u00f4i thu\u1ed9c phe n\u1ea1n nh\u00e2n\u201d, \u201ct\u00f4i thu\u1ed9c phe \u0111\u1ea1o \u0111\u1ee9c\u201d.\nPhe ph\u00e1i \u0111\u00f4i khi kh\u00f4ng ph\u1ea3i l\u00e0 l\u00fd tr\u00ed. N\u00f3 l\u00e0 m\u1ed9t lo\u1ea1i thu\u1ed1c gi\u1ea3m \u0111au.\nV\u00e0 thu\u1ed1c n\u00e0o c\u0169ng c\u00f3 t\u00e1c d\u1ee5ng ph\u1ee5: n\u00f3 l\u00e0m ta b\u1edbt nh\u00ecn ng\u01b0\u1eddi kh\u00e1c nh\u01b0 ng\u01b0\u1eddi.\nTh\u1ee9 ba: h\u1ec7 th\u1ed1ng r\u1ea5t th\u00edch ch\u00fang ta gh\u00e9t nhau.\nKh\u00f4ng c\u1ea7n \u00e2m m\u01b0u. Ch\u1ec9 c\u1ea7n c\u01a1 ch\u1ebf. Khi ng\u01b0\u1eddi lao \u0111\u1ed9ng b\u1eadn \u0111\u00e1nh nhau v\u1edbi nhau, h\u1ecd \u00edt th\u1eddi gian nh\u00ecn l\u00ean.\nCu\u1ed9c chi\u1ebfn ngang gi\u00fap h\u1ec7 th\u1ed1ng r\u1ebb \u0111i. R\u1ebb chi ph\u00ed th\u01b0\u01a1ng l\u01b0\u1ee3ng. R\u1ebb chi ph\u00ed thay th\u1ebf. R\u1ebb c\u1ea3 chi ph\u00ed \u0111\u1ea1o \u0111\u1ee9c, v\u00ec ng\u01b0\u1eddi ta t\u1ef1 \u0111\u1ed5 l\u1ed7i cho nhau thay v\u00ec h\u1ecfi: \u201cT\u1ea1i sao m\u00ecnh ph\u1ea3i s\u1ed1ng nh\u01b0 v\u1eady?\u201d\nWhat the benefit actually is L\u1ee3i \u00edch c\u00f3 hai ph\u00eda.\nV\u1edbi h\u1ec7 th\u1ed1ng: con ng\u01b0\u1eddi \u0111\u01b0\u1ee3c n\u00e9n th\u00e0nh nh\u1eefng th\u1ee9 d\u1ec5 \u0111o l\u01b0\u1eddng.\nB\u1ea1n th\u00e0nh headcount. B\u1ea1n th\u00e0nh resource. B\u1ea1n th\u00e0nh KPI.\nKhi con ng\u01b0\u1eddi th\u00e0nh s\u1ed1, vi\u1ec7c c\u1eaft gi\u1ea3m tr\u1edf n\u00ean \u201ch\u1ee3p l\u00fd\u201d. Khi con ng\u01b0\u1eddi th\u00e0nh KPI, vi\u1ec7c ki\u1ec7t s\u1ee9c tr\u1edf n\u00ean \u201cb\u00ecnh th\u01b0\u1eddng\u201d.\nV\u1edbi c\u00e1 nh\u00e2n: ta mua \u0111\u01b0\u1ee3c m\u1ed9t th\u1ee9 r\u1ea5t kh\u00f3 mua: c\u1ea3m gi\u00e1c ki\u1ec3m so\u00e1t.\nL\u01b0\u01a1ng v\u1ec1, ta th\u1ea5y m\u00ecnh ki\u1ec3m so\u00e1t \u0111\u01b0\u1ee3c th\u00e1ng n\u00e0y. C\u00f3 phe, ta th\u1ea5y m\u00ecnh ki\u1ec3m so\u00e1t \u0111\u01b0\u1ee3c th\u1ebf gi\u1edbi. C\u00f3 k\u1ebb \u0111\u1ec3 gh\u00e9t, ta th\u1ea5y m\u00ecnh ki\u1ec3m so\u00e1t \u0111\u01b0\u1ee3c s\u1ef1 b\u1ea5t l\u1ef1c.\nT\u00f4i kh\u00f4ng n\u00f3i v\u1eady \u0111\u1ec3 m\u1eafng ai. T\u00f4i c\u0169ng l\u00e0m y nh\u01b0 th\u1ebf.\nThe escape hatch for an ordinary employee T\u00f4i hay g\u1eb7p m\u1ed9t c\u00e2u t\u1ef1 tr\u00e1ch ki\u1ec3u n\u00e0y:\n\u201cM\u00ecnh ch\u1ec9 l\u00e0 nh\u00e2n vi\u00ean b\u00ecnh th\u01b0\u1eddng. M\u00ecnh kh\u00f4ng ham tranh gi\u00e0nh. M\u00ecnh kh\u00f4ng mu\u1ed1n leo l\u00ean team lead. V\u1eady m\u00ecnh s\u1ed1ng sao cho \u0111\u1ee1 kh\u1ed5?\u201d\nT\u00f4i ngh\u0129 \u0111\u00e2y l\u00e0 m\u1ed9t l\u1ef1a ch\u1ecdn t\u1eed t\u1ebf, ch\u1ee9 kh\u00f4ng ph\u1ea3i m\u1ed9t s\u1ef1 thi\u1ebfu tham v\u1ecdng.\nNh\u01b0ng \u0111\u1ec3 l\u1ef1a ch\u1ecdn \u0111\u00f3 s\u1ed1ng \u0111\u01b0\u1ee3c, m\u00ecnh c\u1ea7n m\u1ed9t th\u1ee9 kh\u00e1c thay cho \u0111\u1ecba v\u1ecb. N\u1ebfu kh\u00f4ng, m\u00ecnh s\u1ebd r\u01a1i v\u00e0o ki\u1ec3u \u201ckh\u00f4ng mu\u1ed1n leo\u201d nh\u01b0ng v\u1eabn b\u1ecb so s\u00e1nh gi\u1ebft ch\u1ebft m\u1ed7i ng\u00e0y.\nT\u00f4i t\u00ecm \u0111\u01b0\u1ee3c m\u1ed9t c\u00e1i khung kh\u00e1 h\u1ee3p khi \u0111\u1ecdc m\u1ed9t b\u00e0i v\u1ec1 chuy\u1ec7n \u201creset cu\u1ed9c \u0111\u1eddi trong 1 ng\u00e0y\u201d (link: https:\/\/tramdoc.vn\/tin-tuc\/cach-sua-lai-toan-bo-cuoc-doi-ban-chi-trong-1-ngay-nGGl6W.html).\n\u00dd t\u00f4i r\u00fat ra, n\u00f3i ng\u1eafn g\u1ecdn:\nThay v\u00ec c\u1ed1 s\u1eeda h\u00e0nh vi, h\u00e3y s\u1eeda c\u00e1i \u201cki\u1ec3u ng\u01b0\u1eddi\u201d m\u00ecnh \u0111ang tin l\u00e0 m\u00ecnh ph\u1ea3i tr\u1edf th\u00e0nh. M\u1ee5c ti\u00eau kh\u00f4ng ch\u1ec9 l\u00e0 \u0111\u00edch \u0111\u1ebfn, n\u00f3 l\u00e0 m\u1ed9t \u201cl\u0103ng k\u00ednh\u201d khi\u1ebfn ta nh\u00ecn \u0111\u1eddi theo m\u1ed9t ki\u1ec3u. V\u00e0 \u1edf \u0111\u00e2y t\u00f4i m\u01b0\u1ee3n th\u00eam m\u1ed9t m\u1ea9u Ph\u1eadt ph\u00e1p theo ngh\u0129a th\u1ef1c d\u1ee5ng: gi\u1ea3i tho\u00e1t l\u00e0 b\u1edbt d\u00ednh.\nKh\u00f4ng ph\u1ea3i b\u1edbt d\u00ednh \u0111\u1ec3 th\u00e0nh m\u1ed9t ng\u01b0\u1eddi v\u00f4 c\u1ea3m. L\u00e0 b\u1edbt d\u00ednh \u0111\u1ec3 c\u00e1i t\u00e2m m\u00ecnh kh\u00f4ng b\u1ecb l\u00f4i \u0111i b\u1eb1ng m\u1ed7i l\u1eddi khen ch\u00ea.\nB\u1ea1n c\u00f3 th\u1ec3 l\u00e0m m\u1ed9t nh\u00e2n vi\u00ean \u201cb\u00ecnh th\u01b0\u1eddng\u201d, nh\u01b0ng kh\u00f4ng t\u1ea7m th\u01b0\u1eddng:\nL\u00e0m vi\u1ec7c c\u00f3 tay ngh\u1ec1, \u0111\u00e1ng tin. Kh\u00f4ng g\u00e2y drama. V\u1ec1 nh\u00e0 v\u1eabn c\u00f2n ph\u1ea7n \u0111\u1eddi cho m\u00ecnh. L\u1ed1i tho\u00e1t, v\u1edbi t\u00f4i, c\u00f3 ba h\u01b0\u1edbng. B\u1ea1n c\u00f3 th\u1ec3 ch\u1ecdn c\u1ea3 ba, nh\u01b0ng \u01b0u ti\u00ean kh\u00e1c nhau.\n1) Keep the job, lose the anguish \u0110\u00e2y l\u00e0 \u201cgi\u1ea3i tho\u00e1t\u201d c\u1ea5p \u0111\u1ed9 m\u1ed9t: v\u1eabn l\u00e0m, v\u1eabn nh\u1eadn l\u01b0\u01a1ng, nh\u01b0ng b\u1edbt b\u1ecb k\u00e9o b\u1edfi so s\u00e1nh.\nVi\u1ec7c kh\u00f3 nh\u1ea5t kh\u00f4ng ph\u1ea3i l\u00e0 c\u00f4ng vi\u1ec7c. Vi\u1ec7c kh\u00f3 nh\u1ea5t l\u00e0 c\u00e1i t\u00e2m l\u00fac ng\u1ed3i trong c\u00f4ng vi\u1ec7c.\nM\u1ed9t v\u00e0i nguy\u00ean t\u1eafc t\u00f4i th\u1ea5y h\u1eefu \u00edch:\nPh\u00e2n bi\u1ec7t r\u00f5: \u201cT\u00f4i l\u00e0m t\u1ed1t\u201d kh\u00e1c \u201cT\u00f4i c\u00f3 gi\u00e1 tr\u1ecb\u201d. T\u1ef1 nh\u1eafc: c\u1ea3m x\u00fac kh\u00f3 ch\u1ecbu l\u00e0 m\u1ed9t hi\u1ec7n t\u01b0\u1ee3ng, kh\u00f4ng ph\u1ea3i m\u1ed9t b\u1ea3n \u00e1n. Khi b\u1ecb k\u00edch ho\u1ea1t (b\u1ecb ch\u00ea, b\u1ecb coi th\u01b0\u1eddng, b\u1ecb b\u1ecf qua), h\u00e3y ch\u1eadm l\u1ea1i 10 gi\u00e2y tr\u01b0\u1edbc khi ph\u1ea3n \u1ee9ng. N\u1ebfu nghe gi\u1ed1ng thi\u1ec1n, th\u00ec \u0111\u00fang l\u00e0 thi\u1ec1n. Nh\u01b0ng phi\u00ean b\u1ea3n c\u00f4ng s\u1edf c\u1ee7a thi\u1ec1n ch\u1ec9 l\u00e0: \u0111\u1eebng \u0111\u1ec3 b\u1ea3n ng\u00e3 l\u00e1i m\u00e1y.\n2) Optimise for more time (cut demand, gain freedom) N\u1ebfu b\u1ea1n kh\u00f4ng mu\u1ed1n leo thang \u0111\u1ecba v\u1ecb, b\u1ea1n v\u1eabn c\u1ea7n \u201c\u0111\u00f2n b\u1ea9y\u201d kh\u00e1c. \u0110\u00f2n b\u1ea9y c\u1ee7a ng\u01b0\u1eddi kh\u00f4ng leo l\u00e0: gi\u1ea3m m\u1ee9c l\u1ec7 thu\u1ed9c.\nV\u00e0i vi\u1ec7c r\u1ea5t \u0111\u1eddi:\nBi\u1ebft m\u00ecnh c\u1ea7n bao nhi\u00eau ti\u1ec1n \u0111\u1ec3 \u201c\u0111\u1ee7\u201d (kh\u00f4ng ph\u1ea3i \u0111\u1ec3 khoe). T\u1ea1o m\u1ed9t qu\u1ef9 d\u1ef1 ph\u00f2ng \u0111\u1ec3 b\u1ea1n c\u00f3 quy\u1ec1n n\u00f3i \u201ckh\u00f4ng\u201d khi c\u1ea7n. N\u00e2ng tay ngh\u1ec1 \u1edf m\u1ee9c \u0111\u1ee7 \u0111\u1ec3 kh\u00f4ng b\u1ecb l\u1ec7 thu\u1ed9c m\u1ed9t n\u01a1i. \u0110\u00e2y kh\u00f4ng ph\u1ea3i \u201ct\u1ef1 do t\u00e0i ch\u00ednh\u201d. \u0110\u00e2y l\u00e0 \u201ct\u1ef1 do t\u1ed1i thi\u1ec3u\u201d: \u0111\u1ee7 \u0111\u1ec3 th\u1edf.\nTrong Ph\u1eadt ph\u00e1p, kh\u1ed5 nhi\u1ec1u khi \u0111\u1ebfn t\u1eeb tham. Nh\u01b0ng \u201ctham\u201d kh\u00f4ng ch\u1ec9 l\u00e0 tham ti\u1ec1n. N\u00f3 l\u00e0 tham c\u1ea3m gi\u00e1c an to\u00e0n tuy\u1ec7t \u0111\u1ed1i.\nAn to\u00e0n tuy\u1ec7t \u0111\u1ed1i kh\u00f4ng c\u00f3. Ch\u1ec9 c\u00f3 b\u1edbt ph\u1ee5 thu\u1ed9c.\n3) Dare to change workplace (without burning bridges) Kh\u00f4ng leo ch\u1ee9c kh\u00f4ng c\u00f3 ngh\u0129a l\u00e0 b\u1ea1n ph\u1ea3i ch\u1ecbu m\u1ecdi m\u00f4i tr\u01b0\u1eddng.\nC\u00f3 nh\u1eefng n\u01a1i v\u0103n h\u00f3a \u0111\u1ed9c h\u1ea1i, KPI d\u00f9ng \u0111\u1ec3 \u0111\u00e1nh ng\u01b0\u1eddi, v\u00e0 \u201ct\u1eadn t\u00e2m\u201d \u0111\u01b0\u1ee3c hi\u1ec3u l\u00e0 \u201ckh\u00f4ng \u0111\u01b0\u1ee3c quy\u1ec1n m\u1ec7t\u201d.\nTrong nh\u1eefng n\u01a1i \u0111\u00f3, th\u1ef1c h\u00e0nh t\u00e2m linh ch\u1ec9 gi\u00fap b\u1ea1n ch\u1ecbu \u0111\u1ef1ng gi\u1ecfi h\u01a1n. Ch\u1ecbu \u0111\u1ef1ng gi\u1ecfi h\u01a1n ch\u01b0a ch\u1eafc l\u00e0 gi\u1ea3i tho\u00e1t.\n\u0110\u1ed5i m\u00f4i tr\u01b0\u1eddng l\u00e0m vi\u1ec7c l\u00e0 m\u1ed9t h\u00e0nh \u0111\u1ed9ng c\u00f3 th\u1ec3 r\u1ea5t t\u1ec9nh:\nB\u1ea1n kh\u00f4ng b\u1ecf \u0111i trong t\u1ee9c gi\u1eadn. B\u1ea1n chu\u1ea9n b\u1ecb \u0111\u01b0\u1eddng lui. B\u1ea1n gi\u1eef quan h\u1ec7 t\u1eed t\u1ebf. B\u1ea1n r\u1eddi \u0111i v\u00ec hi\u1ec3u gi\u1edbi h\u1ea1n c\u1ee7a m\u00ecnh. Gi\u1ea3i tho\u00e1t kh\u00f4ng ph\u1ea3i l\u00e0 th\u1eafng. Gi\u1ea3i tho\u00e1t l\u00e0 bi\u1ebft l\u00fac n\u00e0o kh\u00f4ng c\u1ea7n \u0111\u00e1nh n\u1eefa.\nClosing Th\u00f4ng b\u00e1o l\u01b0\u01a1ng v\u1eabn s\u1ebd rung.\nT\u00f4i v\u1eabn s\u1ebd m\u1eebng, ki\u1ec3u m\u1eebng c\u1ee7a ng\u01b0\u1eddi v\u1eeba \u0111\u01b0\u1ee3c th\u1edf th\u00eam m\u1ed9t th\u00e1ng.\nNh\u01b0ng n\u1ebfu c\u00f3 th\u1ec3, t\u00f4i mu\u1ed1n m\u00ecnh nh\u1edb m\u1ed9t \u0111i\u1ec1u: m\u00ecnh \u0111i l\u00e0m \u0111\u1ec3 s\u1ed1ng, kh\u00f4ng ph\u1ea3i s\u1ed1ng \u0111\u1ec3 \u0111i l\u00e0m.\nV\u00e0 n\u1ebfu \u0111\u00e3 ph\u1ea3i cho thu\u00ea th\u1eddi gian, th\u00ec \u00edt nh\u1ea5t \u0111\u1eebng cho thu\u00ea lu\u00f4n c\u00e1i t\u00e2m.\nCu\u1ed9c \u0111\u1eddi nhi\u1ec1u khi kh\u00f4ng t\u00e0n nh\u1eabn. N\u00f3 ch\u1ec9 r\u1ea5t gi\u1ecfi b\u1eaft m\u00ecnh t\u00e0n nh\u1eabn v\u1edbi nhau.\nT\u00f4i th\u00ec ch\u1eafc v\u1eabn \u0111i l\u00e0m. Nh\u01b0ng c\u1ed1 g\u1eafng \u0111\u1eebng bi\u1ebfn m\u00ecnh th\u00e0nh m\u1ed9t ng\u01b0\u1eddi ch\u1ec9 bi\u1ebft c\u01b0\u1eddi khi ti\u1ec1n v\u1ec1.\n","permalink":"https:\/\/freepeak.github.io\/posts\/chung-ta-di-lam-vi-dieu-gi\/","summary":"<h2 id=\"about-money\">About money<\/h2>\n<p>Th\u00f4ng b\u00e1o l\u01b0\u01a1ng v\u1ec1 l\u00fac 9:03 s\u00e1ng.<\/p>\n<p>M\u1ed9t c\u00e1i rung nh\u1eb9, m\u1ed9t d\u00f2ng s\u1ed1 nh\u1ea3y l\u00ean, v\u00e0 t\u1ef1 nhi\u00ean c\u1ea3 tu\u1ea7n t\u00f4i bi\u1ebft c\u01b0\u1eddi l\u1ecbch s\u1ef1 h\u01a1n.\nT\u00f4i hay g\u1ecdi \u0111\u00f3 l\u00e0 \u201cti\u1ec1n an th\u1ea7n\u201d: n\u00f3 kh\u00f4ng l\u00e0m m\u00ecnh th\u00f4ng minh h\u01a1n, nh\u01b0ng l\u00e0m m\u00ecnh d\u1ec5\n\u0111\u1ec3 y\u00ean nh\u1eefng c\u00e2u h\u1ecfi kh\u00f3.<\/p>\n<p>T\u00f4i bi\u1ebft sai v\u1eabn l\u00e0m.<\/p>\n<p>C\u00e1i sai \u1edf \u0111\u00e2y kh\u00f4ng ph\u1ea3i l\u00e0 \u201c\u0111i l\u00e0m\u201d (\u0111i l\u00e0m c\u00f3 g\u00ec sai). C\u00e1i sai l\u00e0 c\u00e1i kho\u1ea3nh kh\u1eafc m\u00ecnh\ngi\u1ea3 b\u1ed9 nh\u01b0 kh\u00f4ng c\u00f3 giao d\u1ecbch n\u00e0o \u0111ang x\u1ea3y ra: m\u00ecnh \u0111\u01b0a 8 ti\u1ebfng m\u1ed7i ng\u00e0y, \u0111\u1ed5i l\u1ea1i m\u1ed9t\nph\u1ea7n an t\u00e2m.<\/p>","title":"Why We Work"},{"content":"T\u00f4i l\u00e0m backend.\nN\u00ean t\u00f4i t\u1eebng \u0111i qua m\u1ed9t giai \u0111o\u1ea1n r\u1ea5t \u201cth\u1eb3ng\u201d: query ch\u1eadm th\u00ec th\u00eam index.\nN\u00f3 c\u0169ng gi\u1ed1ng nh\u01b0 l\u00fac b\u1ea1n th\u1ea5y \u0111\u01b0\u1eddng k\u1eb9t xe, b\u1ea1n ngh\u0129 \u201cth\u00eam m\u1ed9t l\u00e0n n\u1eefa l\u00e0 xong\u201d. Th\u1ec9nh tho\u1ea3ng \u0111\u00fang. Nh\u01b0ng \u0111a ph\u1ea7n l\u00e0\u2026 b\u1ea1n ch\u1ec9 d\u1eddi \u0111i\u1ec3m k\u1eb9t t\u1eeb ch\u1ed7 n\u00e0y sang ch\u1ed7 kh\u00e1c, v\u00e0 t\u1ef1 nhi\u00ean chi ph\u00ed b\u1ea3o tr\u00ec \u0111\u01b0\u1eddng t\u0103ng l\u00ean.\nMySQL index c\u0169ng v\u1eady.\nN\u00f3 l\u00e0m query nhanh l\u00ean th\u1eadt. Nh\u01b0ng n\u00f3 kh\u00f4ng mi\u1ec5n ph\u00ed. V\u00e0 quan tr\u1ecdng h\u01a1n: n\u00f3 ch\u1ec9 nhanh khi query \u0111i \u0111\u00fang \u0111\u01b0\u1eddng.\nThe original question: in what order does your query want to travel? M\u1ed9t query ph\u1ed5 bi\u1ebfn trong backend th\u01b0\u1eddng l\u00e0m 3 vi\u1ec7c:\nL\u1ecdc d\u1eef li\u1ec7u (WHERE) S\u1eafp x\u1ebfp (ORDER BY) L\u1ea5y \u00edt th\u00f4i (LIMIT, ph\u00e2n trang) N\u1ebfu kh\u00f4ng c\u00f3 index ph\u00f9 h\u1ee3p, MySQL s\u1ebd ph\u1ea3i:\nqu\u00e9t nhi\u1ec1u d\u00f2ng h\u01a1n c\u1ea7n thi\u1ebft ho\u1eb7c l\u1ecdc xong m\u1edbi sort (Using filesort) ho\u1eb7c v\u1eeba sort v\u1eeba \u0111\u1ecdc b\u1ea3ng qu\u00e1 nhi\u1ec1u (I\/O t\u0103ng, CPU t\u0103ng) N\u00f3i cho g\u1ecdn: v\u1ea5n \u0111\u1ec1 kh\u00f4ng n\u1eb1m \u1edf vi\u1ec7c \u201cc\u00f3 index hay kh\u00f4ng\u201d, m\u00e0 n\u1eb1m \u1edf vi\u1ec7c \u201cindex hi\u1ec7n t\u1ea1i c\u00f3 \u0111\u00fang v\u1edbi \u0111\u01b0\u1eddng l\u1ecdc\/sort c\u1ee7a query hay kh\u00f4ng\u201d.\nEvery choice has a cost (the backend constraint) T\u00f4i hay g\u1eb7p 3 ki\u1ec3u \u201c\u0111\u1eddi s\u1ed1ng\u201d khi \u0111\u1ee5ng index:\nRead-heavy: API ph\u1ea3i nhanh, p95 quan tr\u1ecdng. Write-heavy: insert\/update nhi\u1ec1u, index th\u00eam v\u00e0o l\u00e0 write ch\u1eadm th\u1ea5y r\u00f5. B\u1ea3ng l\u1edbn d\u1ea7n: query \u0111ang \u1ed5n s\u1ebd t\u1ef1 nhi\u00ean xu\u1ed1ng c\u1ea5p theo th\u1eddi gian. V\u00e0 v\u00ec m\u1ed7i l\u1ef1a ch\u1ecdn \u0111\u1ec1u c\u00f3 gi\u00e1, n\u00ean index kh\u00f4ng n\u00ean \u0111\u01b0\u1ee3c t\u1ea1o theo c\u1ea3m gi\u00e1c.\nB\u1ea1n t\u1ea1o index l\u00e0 b\u1ea1n \u0111ang k\u00fd v\u00e0o m\u1ed9t \u201ch\u1ee3p \u0111\u1ed3ng\u201d:\nnhanh h\u01a1n cho m\u1ed9t nh\u00f3m query \u0111\u1ed5i l\u1ea1i t\u1ed1n dung l\u01b0\u1ee3ng v\u00e0 t\u1ed1n chi ph\u00ed ghi cho m\u1ecdi mutation In practice users only care about 3 things N\u1ebfu b\u1ecf h\u1ebft thu\u1eadt ng\u1eef \u0111i th\u00ec cu\u1ed1i c\u00f9ng v\u1eabn l\u00e0:\nAPI tr\u1ea3 nhanh h\u01a1n Gi\u1ea3m chi ph\u00ed v\u1eadn h\u00e0nh Gi\u1ea3m nguy c\u01a1 incident B\u1ea1n c\u00f3 th\u1ec3 gi\u1ea3i th\u00edch B-Tree v\u1edbi \u0111\u1ed3ng nghi\u1ec7p c\u1ea3 bu\u1ed5i. Nh\u01b0ng n\u1ebfu endpoint list \u0111\u01a1n h\u00e0ng v\u1eabn 3\u20134 gi\u00e2y th\u00ec s\u1ea3n ph\u1ea9m v\u1eabn \u0111au.\nDefinitions that sound good, reality that traps you MySQL 8+ sometimes skips an index on its own (low selectivity) C\u00f3 m\u1ed9t c\u1ea3m gi\u00e1c r\u1ea5t d\u1ec5 g\u00e2y hoang mang: b\u1ea1n \u0111\u00e3 t\u1ea1o index r\u1ed3i, nh\u01b0ng EXPLAIN v\u1eabn cho th\u1ea5y MySQL qu\u00e9t b\u1ea3ng.\nV\u1edbi MySQL 8 tr\u1edf l\u00ean, chuy\u1ec7n n\u00e0y l\u1ea1i c\u00e0ng \u201cb\u00ecnh th\u01b0\u1eddng\u201d h\u01a1n, v\u00ec optimizer c\u00f3 nhi\u1ec1u th\u00f4ng tin\/cost model t\u1ed1t h\u01a1n \u0111\u1ec3 t\u1ef1 quy\u1ebft.\nTr\u01b0\u1eddng h\u1ee3p hay g\u1eb7p nh\u1ea5t l\u00e0 \u0111\u1ed9 ch\u1ecdn l\u1ecdc th\u1ea5p.\nV\u00ed d\u1ee5 c\u1ed9t status ch\u1ec9 c\u00f3 v\u00e0i gi\u00e1 tr\u1ecb ki\u1ec3u PAID | PENDING | CANCELLED. N\u1ebfu h\u1ec7 th\u1ed1ng c\u1ee7a b\u1ea1n c\u00f3 30% \u0111\u01a1n h\u00e0ng \u1edf tr\u1ea1ng th\u00e1i PAID, th\u00ec query:\nSELECT id, status, created_at FROM orders WHERE status = &#39;PAID&#39;; c\u00f3 th\u1ec3 ph\u1ea3i \u0111\u1ecdc m\u1ed9t ph\u1ea7n r\u1ea5t l\u1edbn c\u1ee7a b\u1ea3ng.\nTrong t\u00ecnh hu\u1ed1ng \u0111\u00f3, \u0111i theo index status \u0111\u00f4i khi c\u00f2n t\u1ec7 h\u01a1n:\nMySQL \u0111\u1ecdc index \u0111\u1ec3 l\u1ea5y r\u1ea5t nhi\u1ec1u row_id. Sau \u0111\u00f3 ph\u1ea3i &ldquo;quay l\u1ea1i&rdquo; b\u1ea3ng \u0111\u1ec3 \u0111\u1ecdc d\u1eef li\u1ec7u th\u1eadt (random I\/O). N\u00ean optimizer c\u00f3 th\u1ec3 ch\u1ecdn qu\u00e9t b\u1ea3ng (sequential I\/O) v\u00e0 filter trong qu\u00e1 tr\u00ecnh \u0111\u1ecdc.\nD\u1ea5u hi\u1ec7u nh\u1eadn bi\u1ebft trong EXPLAIN:\npossible_keys c\u00f3 index (v\u00ed d\u1ee5 idx_status) nh\u01b0ng key = NULL type = ALL rows \u01b0\u1edbc l\u01b0\u1ee3ng l\u1edbn \u0110\u1ecbnh ngh\u0129a ki\u1ec3u s\u00e1ch gi\u00e1o khoa: index gi\u00fap t\u0103ng t\u1ed1c truy v\u1ea5n.\n\u0110\u00fang.\nNh\u01b0ng \u0111\u1eddi th\u1eadt l\u00e0: index ch\u1ec9 gi\u00fap n\u1ebfu query c\u00f3 th\u1ec3 d\u00f9ng index \u0111\u00f3 m\u1ed9t c\u00e1ch \u201ct\u1eed t\u1ebf\u201d.\nV\u00e0 c\u00f3 v\u00e0i th\u1ee9 khi\u1ebfn MySQL \u201cb\u00f3 tay\u201d, d\u00f9 b\u1ea1n c\u00f3 index:\nB\u1ecdc c\u1ed9t b\u1eb1ng h\u00e0m trong WHERE \u00c9p ki\u1ec3u l\u1ed9n x\u1ed9n LIKE '%keyword%' OR t\u00f9y ti\u1ec7n OFFSET ph\u00e2n trang qu\u00e1 l\u1edbn Nh\u1eefng th\u1ee9 n\u00e0y l\u00e0m b\u1ea1n c\u1ea3m gi\u00e1c \u201cm\u00ecnh \u0111\u00e3 c\u00f3 index r\u1ed3i m\u00e0 v\u1eabn ch\u1eadm\u201d.\nTh\u1ef1c ra l\u00e0 query \u0111ang \u0111i sai \u0111\u01b0\u1eddng.\nOne lens that is easy to use: start from the important query, not the table \u0110\u1eebng h\u1ecfi: \u201cB\u1ea3ng orders c\u1ea7n index g\u00ec?\u201d\nH\u00e3y h\u1ecfi:\nEndpoint n\u00e0o g\u1ecdi nhi\u1ec1u nh\u1ea5t? Query n\u00e0o n\u00f3ng nh\u1ea5t (top slow queries \/ APM)? N\u00f3 l\u1ecdc theo c\u1ed9t n\u00e0o? N\u00f3 sort theo c\u1ed9t n\u00e0o? N\u00f3 ph\u00e2n trang ki\u1ec3u g\u00ec? Khi b\u1ea1n tr\u1ea3 l\u1eddi \u0111\u01b0\u1ee3c 4\u20135 c\u00e2u \u0111\u00f3, index t\u1ef1 nhi\u00ean \u201chi\u1ec7n h\u00ecnh\u201d.\nA 3-step framework (enough for backend developers) Step 1: Write the query the way MySQL can use an index M\u1ed9t anti-pattern kinh \u0111i\u1ec3n:\nWHERE DATE(created_at) = &#39;2026-01-01&#39; B\u1ea1n nh\u00ecn th\u1ea5y \u201ch\u1ee3p l\u00fd\u201d v\u00ec b\u1ea1n \u0111ang ngh\u0129 theo ng\u00f4n ng\u1eef ng\u01b0\u1eddi. Nh\u01b0ng MySQL th\u00ec th\u1ea5y: \u201cb\u1ea1n b\u1eaft t\u00f4i t\u00ednh DATE() cho m\u1ecdi d\u00f2ng, r\u1ed3i m\u1edbi so s\u00e1nh\u201d.\nC\u00e1ch vi\u1ebft t\u1ed1t h\u01a1n:\nWHERE created_at &gt;= &#39;2026-01-01&#39; AND created_at &lt; &#39;2026-01-02&#39; Ng\u1eafn g\u1ecdn: mu\u1ed1n d\u00f9ng index th\u00ec \u0111\u1eebng b\u1ecdc c\u1ed9t b\u1eb1ng h\u00e0m trong \u0111i\u1ec1u ki\u1ec7n l\u1ecdc.\nStep 2: Design the index in the real filter\/sort order Gi\u1ea3 s\u1eed backend c\u00f3 endpoint list \u0111\u01a1n h\u00e0ng c\u1ee7a user:\nSELECT id, status, created_at, total_amount FROM orders WHERE user_id = ? AND status = ? ORDER BY created_at DESC LIMIT 20; Index h\u1ee3p l\u00fd th\u01b0\u1eddng l\u00e0 index gh\u00e9p:\nCREATE INDEX idx_orders_user_status_created ON orders(user_id, status, created_at DESC); L\u00fd do:\nuser_id v\u00e0 status l\u00e0 \u0111i\u1ec1u ki\u1ec7n = gi\u00fap thu h\u1eb9p t\u1eadp d\u1eef li\u1ec7u nhanh created_at ph\u1ee5c v\u1ee5 ORDER BY ... DESC \u0111\u1ec3 tr\u00e1nh sort v\u00e0 tr\u1ea3 nhanh LIMIT 20 M\u1ed9t l\u1ed7i hay g\u1eb7p l\u00e0 t\u1ea1o index theo ki\u1ec3u \u201cm\u00ecnh th\u1ea5y c\u1ed9t created_at quan tr\u1ecdng\u201d r\u1ed3i \u0111\u1eb7t n\u00f3 l\u00ean \u0111\u1ea7u. Nh\u01b0ng n\u1ebfu query lu\u00f4n b\u1eaft \u0111\u1ea7u b\u1eb1ng user_id, b\u1ea1n \u0111\u1eb7t user_id l\u00ean tr\u01b0\u1edbc th\u01b0\u1eddng \u0111\u00fang h\u01a1n.\nB\u1ea1n kh\u00f4ng c\u1ea7n nh\u1edb qu\u00e1 nhi\u1ec1u l\u00fd thuy\u1ebft. Ch\u1ec9 c\u1ea7n nh\u1edb quy t\u1eafc \u201cleftmost prefix\u201d c\u1ee7a index gh\u00e9p:\n(user_id, status, created_at) d\u00f9ng t\u1ed1t khi query c\u00f3 user_id tr\u01b0\u1edbc thi\u1ebfu user_id th\u00ec c\u00e1c c\u1ed9t sau kh\u00f3 ph\u00e1t huy Step 3: Use EXPLAIN to confirm, not faith Sau khi t\u1ea1o index, ch\u1ea1y:\nEXPLAIN SELECT ... Nh\u1eefng d\u1ea5u hi\u1ec7u b\u1ea1n mu\u1ed1n th\u1ea5y:\nkey l\u00e0 index b\u1ea1n v\u1eeba t\u1ea1o (kh\u00f4ng ph\u1ea3i NULL) type kh\u00f4ng ph\u1ea3i ALL rows \u01b0\u1edbc l\u01b0\u1ee3ng gi\u1ea3m m\u1ea1nh h\u1ea1n ch\u1ebf Using filesort khi b\u1ea1n \u0111\u00e3 thi\u1ebft k\u1ebf index \u0111\u1ec3 \u0103n ORDER BY Th\u00f3i quen t\u1ed1t: \u201ct\u1ea1o index xong l\u00e0 ph\u1ea3i ki\u1ec3m ch\u1ee9ng\u201d, kh\u00f4ng ph\u1ea3i \u201cc\u1ea3m gi\u00e1c th\u1ea5y \u1ed5n\u201d.\nAnti-pattern: adding an index out of fear, and the price behind it Nhi\u1ec1u team \u0111i v\u00e0o v\u00f2ng l\u1eb7p:\nQuery ch\u1eadm \u2192 th\u00eam index L\u1ea1i c\u00f3 query kh\u00e1c ch\u1eadm \u2192 th\u00eam index M\u1ed9t th\u1eddi gian sau: write ch\u1eadm, replication lag, disk ph\u00ecnh, buffer pool c\u0103ng Index ki\u1ec3u n\u00e0y gi\u1ed1ng mua th\u00eam \u0111\u1ed3 ngh\u1ec1 v\u00ec s\u1ee3 thi\u1ebfu. L\u00fac \u0111\u1ea7u c\u00f3 t\u00e1c d\u1ee5ng. Nh\u01b0ng v\u1ec1 sau n\u00f3 th\u00e0nh g\u00e1nh n\u1eb7ng v\u1eadn h\u00e0nh.\nM\u1ed9t c\u00e2u h\u1ecfi n\u00ean t\u1ef1 h\u1ecfi tr\u01b0\u1edbc khi th\u00eam index:\n\u201cIndex n\u00e0y c\u1ee9u endpoint n\u00e0o, t\u1ea7n su\u1ea5t bao nhi\u00eau, v\u00e0 \u0111\u00e1nh \u0111\u1ed5i g\u00ec cho write?\u201d\nPagination: large OFFSET is a performance killer Pagination ki\u1ec3u:\nLIMIT 20 OFFSET 20000 OFFSET c\u00e0ng l\u1edbn th\u00ec MySQL c\u00e0ng ph\u1ea3i \u0111\u1ecdc\/\u0111i qua nhi\u1ec1u d\u00f2ng r\u1ed3i m\u1edbi tr\u1ea3 20 d\u00f2ng b\u1ea1n c\u1ea7n.\nN\u1ebfu endpoint quan tr\u1ecdng v\u00e0 d\u1eef li\u1ec7u l\u1edbn, c\u00e2n nh\u1eafc keyset pagination:\nSELECT id, status, created_at, total_amount FROM orders WHERE user_id = ? AND status = ? AND created_at &lt; ? ORDER BY created_at DESC LIMIT 20; Khi \u0111\u00f3 index (user_id, status, created_at) g\u1ea7n nh\u01b0 \u201c\u0111\u00fang s\u00e1ch\u201d.\nA quick checklist (for backend developers) B\u1eaft \u0111\u1ea7u t\u1eeb query th\u1eadt (hot path), kh\u00f4ng b\u1eaft \u0111\u1ea7u t\u1eeb \u201cb\u1ea3ng n\u00e0y n\u00ean c\u00f3 g\u00ec\u201d. Tr\u00e1nh \u0111i\u1ec1u ki\u1ec7n ph\u00e1 index: h\u00e0m tr\u00ean c\u1ed9t, \u00e9p ki\u1ec3u, LIKE '%...%'. Index gh\u00e9p: \u01b0u ti\u00ean c\u1ed9t l\u1ecdc = tr\u01b0\u1edbc, r\u1ed3i \u0111\u1ebfn c\u1ed9t ph\u1ee5c v\u1ee5 sort\/range. ORDER BY + LIMIT l\u00e0 c\u01a1 h\u1ed9i t\u1ed1i \u01b0u r\u1ea5t l\u1edbn n\u1ebfu index \u0111\u00fang. OFFSET l\u1edbn: c\u00e2n nh\u1eafc keyset pagination. M\u1ed7i index l\u00e0 chi ph\u00ed ghi + dung l\u01b0\u1ee3ng + b\u1ea3o tr\u00ec. \u0110\u1eebng t\u1ea1o cho y\u00ean t\u00e2m. Closing on one principle Index kh\u00f4ng ph\u1ea3i b\u00f9a.\nIndex l\u00e0 \u0111\u01b0\u1eddng \u0111i.\nMu\u1ed1n query nhanh, b\u1ea1n kh\u00f4ng c\u1ea7n nhi\u1ec1u \u0111\u01b0\u1eddng. B\u1ea1n c\u1ea7n \u0111\u00fang \u0111\u01b0\u1eddng, v\u00e0 vi\u1ebft query \u0111\u1ec3 \u0111i \u0111\u00fang \u0111\u01b0\u1eddng \u0111\u00f3.\nN\u1ebfu b\u1ea1n mu\u1ed1n, g\u1eedi m\u00ecnh 1\u20132 query \u0111ang ch\u1eadm (k\u00e8m schema c\u00e1c c\u1ed9t li\u00ean quan v\u00e0 \u01b0\u1edbc l\u01b0\u1ee3ng s\u1ed1 b\u1ea3n ghi). T\u00f4i s\u1ebd g\u1ee3i \u00fd index c\u1ee5 th\u1ec3 v\u00e0 ch\u1ec9 ra \u0111i\u1ec3m n\u00e0o khi\u1ebfn optimizer \u0111ang ch\u1ecdn plan kh\u00f4ng nh\u01b0 b\u1ea1n k\u1ef3 v\u1ecdng.\n","permalink":"https:\/\/freepeak.github.io\/posts\/mysql-index-duong-di-cho-query\/","summary":"An index is only fast when the query takes the right path. A practical lens for backend developers: start from the queries that matter, write sargable conditions, design composite indexes in the real filter\/sort order, and verify with EXPLAIN.","title":"MySQL Index: The Path a Query Takes (Written for Backend Developers)"},{"content":"Trong h\u1ec7 sinh th\u00e1i Cloud Native ng\u00e0y nay, vi\u1ec7c qu\u1ea3n l\u00fd traffic \u0111i v\u00e0o (Ingress) v\u00e0 giao ti\u1ebfp gi\u1eefa c\u00e1c services (East-West) l\u00e0 b\u00e0i to\u00e1n c\u1ed1t l\u00f5i. \u0110\u1ed1i v\u1edbi c\u00e1c h\u1ec7 th\u1ed1ng ch\u1ea1y tr\u00ean Google Kubernetes Engine (GKE), m\u1eb7c d\u00f9 GCP cung c\u1ea5p Ingress Controller m\u1eb7c \u0111\u1ecbnh (GCE Ingress), nh\u01b0ng nhi\u1ec1u \u0111\u1ed9i ng\u0169 k\u1ef9 thu\u1eadt v\u1eabn l\u1ef1a ch\u1ecdn Kong Open Source.\nB\u00e0i vi\u1ebft n\u00e0y s\u1ebd \u0111i s\u00e2u v\u00e0o l\u00fd do t\u1ea1i sao Kong l\u1ea1i l\u00e0 l\u1ef1a ch\u1ecdn \u01b0u vi\u1ec7t v\u1ec1 m\u1eb7t ki\u1ebfn tr\u00fac, \u0111\u1ed3ng th\u1eddi chia s\u1ebb c\u00e1c Best Practices \u0111\u00fac k\u1ebft t\u1eeb th\u1ef1c t\u1ebf \u0111\u1ec3 tri\u1ec3n khai Kong hi\u1ec7u qu\u1ea3 tr\u00ean GKE.\n1. Introduction: Kong Gateway in the K8s-on-GCP picture Kong Open Source l\u00e0 m\u1ed9t API Gateway ph\u1ed5 bi\u1ebfn nh\u1ea5t th\u1ebf gi\u1edbi, \u0111\u01b0\u1ee3c x\u00e2y d\u1ef1ng d\u1ef1a tr\u00ean NGINX v\u00e0 m\u1edf r\u1ed9ng b\u1eb1ng Lua (ho\u1eb7c Go\/Rust qua WASM). Trong m\u00f4i tr\u01b0\u1eddng Kubernetes, Kong \u0111\u00f3ng vai tr\u00f2 k\u00e9p:\nIngress Controller: \u0110i\u1ec1u h\u01b0\u1edbng traffic t\u1eeb b\u00ean ngo\u00e0i v\u00e0o cluster tu\u00e2n theo chu\u1ea9n Kubernetes Ingress resource. API Gateway: Th\u1ef1c hi\u1ec7n c\u00e1c ch\u1ee9c n\u0103ng n\u00e2ng cao nh\u01b0 Authentication, Rate Limiting, Logging, Transformation, v.v. Kh\u00e1c v\u1edbi c\u00e1c Load Balancer layer 4 \u0111\u01a1n thu\u1ea7n, Kong ho\u1ea1t \u0111\u1ed9ng \u1edf Layer 7, cho ph\u00e9p x\u1eed l\u00fd logic nghi\u1ec7p v\u1ee5 ph\u1ee9c t\u1ea1p ngay t\u1ea1i &ldquo;c\u1eeda ng\u00f5&rdquo; c\u1ee7a h\u1ec7 th\u1ed1ng.\nIts role in the GKE architecture Tr\u00ean GKE, Kong th\u01b0\u1eddng \u0111\u1ee9ng sau Google Cloud Load Balancer. M\u00f4 h\u00ecnh ph\u1ed5 bi\u1ebfn l\u00e0: Client -&gt; GCP L4 Load Balancer -&gt; Kong Proxy Service -&gt; K8s Services\nM\u00f4 h\u00ecnh n\u00e0y t\u1eadn d\u1ee5ng \u0111\u01b0\u1ee3c s\u1ee9c m\u1ea1nh h\u1ea1 t\u1ea7ng m\u1ea1ng to\u00e0n c\u1ea7u c\u1ee7a Google (Global Load Balancing) \u0111\u1ed3ng th\u1eddi gi\u1eef \u0111\u01b0\u1ee3c s\u1ef1 linh ho\u1ea1t trong x\u1eed l\u00fd logic c\u1ee7a Kong.\n2. Why choose Kong over the default GCP Ingress? GCP cung c\u1ea5p GCE Ingress Controller t\u00edch h\u1ee3p s\u1eb5n r\u1ea5t t\u1ed1t, nh\u01b0ng n\u00f3 th\u01b0\u1eddng ch\u1ec9 gi\u1ea3i quy\u1ebft \u0111\u01b0\u1ee3c b\u00e0i to\u00e1n routing c\u01a1 b\u1ea3n. Khi h\u1ec7 th\u1ed1ng l\u1edbn d\u1ea7n, c\u00e1c h\u1ea1n ch\u1ebf b\u1eaft \u0111\u1ea7u l\u1ed9 di\u1ec7n. D\u01b0\u1edbi \u0111\u00e2y l\u00e0 l\u00fd do c\u00e1c ki\u1ebfn tr\u00fac s\u01b0 ph\u1ea7n m\u1ec1m chuy\u1ec3n sang Kong:\nThe weaknesses of GCP Ingress (GCE) H\u1ea1n ch\u1ebf v\u1ec1 t\u00ednh n\u0103ng: Ch\u1ee7 y\u1ebfu t\u1eadp trung v\u00e0o L7 Load Balancing c\u01a1 b\u1ea3n (Path-based routing). C\u00e1c t\u00ednh n\u0103ng nh\u01b0 rate limiting, authentication, request transformation g\u1ea7n nh\u01b0 kh\u00f4ng c\u00f3 ho\u1eb7c r\u1ea5t kh\u00f3 c\u1ea5u h\u00ecnh. \u0110\u1ed9 tr\u1ec5 (Latency): V\u1edbi c\u00e1c rule ph\u1ee9c t\u1ea1p, \u0111\u1ed9 tr\u1ec5 c\u00f3 th\u1ec3 t\u0103ng l\u00ean. Vendor Lock-in: C\u1ea5u h\u00ecnh ph\u1ee5 thu\u1ed9c ch\u1eb7t ch\u1ebd v\u00e0o Annotation c\u1ee7a Google Cloud. Kh\u00f3 mang sang AWS hay Azure n\u1ebfu c\u1ea7n chi\u1ebfn l\u01b0\u1ee3c Multi-cloud. Kong&rsquo;s standout advantages H\u1ec7 sinh th\u00e1i Plugin kh\u1ed5ng l\u1ed3: \u0110\u00e2y l\u00e0 &ldquo;v\u0169 kh\u00ed b\u00ed m\u1eadt&rdquo; c\u1ee7a Kong. B\u1ea1n c\u1ea7n Rate Limiting? C\u00f3 plugin. C\u1ea7n OAuth2\/JWT Auth? C\u00f3 plugin. C\u1ea7n log request ra Kafka\/ELK? C\u00f3 plugin. T\u1ea5t c\u1ea3 ch\u1ec9 c\u1ea7n b\u1eadt\/t\u1eaft qua config. Hi\u1ec7u n\u0103ng cao: Kong \u0111\u01b0\u1ee3c build tr\u00ean NGINX v\u00e0 s\u1eed d\u1ee5ng OpenResty (Lua JIT), cho ph\u00e9p x\u1eed l\u00fd h\u00e0ng ch\u1ee5c ngh\u00ecn request\/gi\u00e2y v\u1edbi \u0111\u1ed9 tr\u1ec5 c\u1ef1c th\u1ea5p (&lt; 10ms). Unified Gateway: Kong c\u00f3 th\u1ec3 x\u1eed l\u00fd c\u1ea3 traffic t\u1eeb ngo\u00e0i v\u00e0o (North-South) v\u00e0 traffic gi\u1eefa c\u00e1c service (East-West) trong m\u00f4 h\u00ecnh Service Mesh (Kong Mesh). Vendor Agnostic: C\u1ea5u h\u00ecnh Kong l\u00e0 chu\u1ea9n Kubernetes CRD ho\u1eb7c YAML. B\u1ea1n c\u00f3 th\u1ec3 b\u00ea nguy\u00ean b\u1ed9 config n\u00e0y ch\u1ea1y tr\u00ean AWS EKS, Azure AKS hay On-premise m\u00e0 kh\u00f4ng c\u1ea7n s\u1eeda \u0111\u1ed5i nhi\u1ec1u. When should you use Kong? Khi b\u1ea1n c\u1ea7n c\u00e1c t\u00ednh n\u0103ng API Management n\u00e2ng cao (Auth, Quota, Monetization). Khi h\u1ec7 th\u1ed1ng c\u00f3 l\u01b0\u1ee3ng traffic l\u1edbn v\u00e0 y\u00eau c\u1ea7u \u0111\u1ed9 tr\u1ec5 th\u1ea5p. Khi b\u1ea1n mu\u1ed1n \u0111\u1ed3ng nh\u1ea5t c\u00f4ng ngh\u1ec7 Gateway tr\u00ean nhi\u1ec1u m\u00f4i tr\u01b0\u1eddng (Hybrid Cloud). 3. Best Practices: Running Kong on GKE \u0110\u1ec3 v\u1eadn h\u00e0nh Kong \u1ed5n \u0111\u1ecbnh tr\u00ean m\u00f4i tr\u01b0\u1eddng Production, \u0111\u1eebng ch\u1ec9 d\u1eebng l\u1ea1i \u1edf helm install. D\u01b0\u1edbi \u0111\u00e2y l\u00e0 c\u00e1c th\u1ef1c ti\u1ec5n t\u1ed1t nh\u1ea5t b\u1ea1n n\u00ean \u00e1p d\u1ee5ng.\na. Preparation and overall architecture 1. Lu\u00f4n s\u1eed d\u1ee5ng Helm Charts Kh\u00f4ng n\u00ean c\u00e0i \u0111\u1eb7t Kong b\u1eb1ng c\u00e1c file YAML r\u1eddi r\u1ea1c (manifests). H\u00e3y s\u1eed d\u1ee5ng Official Kong Helm Chart. Helm gi\u00fap b\u1ea1n d\u1ec5 d\u00e0ng qu\u1ea3n l\u00fd version, rollback khi c\u00f3 s\u1ef1 c\u1ed1 v\u00e0 t\u00f9y bi\u1ebfn values.yaml m\u1ed9t c\u00e1ch c\u00f3 c\u1ea5u tr\u00fac.\n2. T\u00e1ch bi\u1ec7t Namespace \u0110\u1eebng c\u00e0i Kong v\u00e0o default namespace. H\u00e3y t\u1ea1o m\u1ed9t namespace ri\u00eang bi\u1ec7t, v\u00ed d\u1ee5 kong-gateway ho\u1eb7c ingress-controller. \u0110i\u1ec1u n\u00e0y gi\u00fap qu\u1ea3n l\u00fd Resource Quota v\u00e0 RBAC (ph\u00e2n quy\u1ec1n) t\u1ed1t h\u01a1n, tr\u00e1nh vi\u1ec7c m\u1ed9t developer v\u00f4 t\u00ecnh x\u00f3a nh\u1ea7m Ingress Controller.\n3. Ki\u1ebfn tr\u00fac Load Balancing Tr\u00ean GKE, h\u00e3y c\u1ea5u h\u00ecnh Service c\u1ee7a Kong Proxy l\u00e0 LoadBalancer. Google s\u1ebd t\u1ef1 \u0111\u1ed9ng c\u1ea5p ph\u00e1t m\u1ed9t External IP v\u00e0 m\u1ed9t L4 Load Balancer tr\u1ecf v\u00e0o c\u00e1c Pod Kong.\nTip: S\u1eed d\u1ee5ng Annotation cloud.google.com\/load-balancer-type: &quot;External&quot; \u0111\u1ec3 ch\u1ec9 \u0111\u1ecbnh r\u00f5 lo\u1ea1i LB. b. Config and plugin management done right 1. &ldquo;Configuration as Code&rdquo; v\u1edbi CRDs Kong cung c\u1ea5p c\u00e1c Custom Resource Definitions (CRDs) nh\u01b0 KongPlugin, KongIngress, KongConsumer. H\u00e3y s\u1eed d\u1ee5ng ch\u00fang thay v\u00ec g\u1ecdi Admin API b\u1eb1ng tay.\nL\u1ee3i \u00edch: To\u00e0n b\u1ed9 c\u1ea5u h\u00ecnh \u0111\u01b0\u1ee3c l\u01b0u trong Git, c\u00f3 th\u1ec3 review v\u00e0 audit (GitOps). 2. Scope c\u1ee7a Plugin H\u1ea1n ch\u1ebf d\u00f9ng Global Plugin (\u00e1p d\u1ee5ng cho to\u00e0n b\u1ed9 cluster) tr\u1eeb khi th\u1ef1c s\u1ef1 c\u1ea7n thi\u1ebft (v\u00ed d\u1ee5: Log correlation ID). H\u00e3y apply plugin \u1edf m\u1ee9c Ingress ho\u1eb7c Service c\u1ee5 th\u1ec3. V\u00ed d\u1ee5: Service Payment c\u1ea7n Rate Limit kh\u1eaft khe h\u01a1n Service Product Catalog.\n3. Centralized Logging \u0110\u1eebng \u0111\u1ec3 log &ldquo;ch\u1ebft&rdquo; trong pod. H\u00e3y s\u1eed d\u1ee5ng plugin tcp-log, udp-log ho\u1eb7c file-log \u0111\u1ec3 \u0111\u1ea9y log v\u1ec1 h\u1ec7 th\u1ed1ng gi\u00e1m s\u00e1t t\u1eadp trung. Tr\u00ean GCP, b\u1ea1n c\u00f3 th\u1ec3 \u0111\u1ea9y th\u1eb3ng v\u1ec1 Google Cloud Logging (Stackdriver).\nc. Optimisation and security 1. B\u1ea3o v\u1ec7 Kong Admin API \u0110\u00e2y l\u00e0 nguy\u00ean t\u1eafc s\u1ed1ng c\u00f2n. Kong Admin API (m\u1eb7c \u0111\u1ecbnh port 8001\/8444) cho ph\u00e9p thay \u0111\u1ed5i to\u00e0n b\u1ed9 c\u1ea5u h\u00ecnh Gateway.\nAction: Ch\u1ec9 expose Admin API qua ClusterIP (n\u1ed9i b\u1ed9 cluster). N\u1ebfu c\u1ea7n truy c\u1eadp t\u1eeb ngo\u00e0i, h\u00e3y d\u00f9ng kubectl port-forward ho\u1eb7c b\u1ea3o v\u1ec7 n\u00f3 b\u1eb1ng m\u1ed9t Ingress ri\u00eang c\u00f3 Authentication c\u1ef1c m\u1ea1nh. 2. Qu\u1ea3n l\u00fd Secrets Kh\u00f4ng bao gi\u1edd hardcode API Key hay Certificate trong file c\u1ea5u h\u00ecnh.\nD\u00f9ng Kubernetes Secrets \u0111\u1ec3 l\u01b0u SSL Certificate. T\u00edch h\u1ee3p GCP Secret Manager v\u1edbi External Secrets Operator \u0111\u1ec3 sync secret v\u00e0o K8s an to\u00e0n. 3. HTTPS Everywhere S\u1eed d\u1ee5ng Cert-Manager k\u1ebft h\u1ee3p v\u1edbi Let&rsquo;s Encrypt \u0111\u1ec3 t\u1ef1 \u0111\u1ed9ng h\u00f3a vi\u1ec7c c\u1ea5p ph\u00e1t v\u00e0 gia h\u1ea1n SSL Certificate cho t\u1ea5t c\u1ea3 c\u00e1c domain. C\u1ea5u h\u00ecnh Kong \u0111\u1ec3 force redirect HTTP sang HTTPS.\nd. CI\/CD and DevOps automation \u0110\u1ec3 \u0111\u1ea1t \u0111\u01b0\u1ee3c s\u1ef1 linh ho\u1ea1t t\u1ed1i \u0111a, h\u00e3y \u00e1p d\u1ee5ng m\u00f4 h\u00ecnh GitOps:\nSource Code: Ch\u1ee9a code \u1ee9ng d\u1ee5ng v\u00e0 file values.yaml cho Helm Chart c\u1ee7a \u1ee9ng d\u1ee5ng. Infrastructure Repo: Ch\u1ee9a c\u1ea5u h\u00ecnh Kong (Plugins, Consumers, Global Configs). CD Tool (ArgoCD\/Flux): T\u1ef1 \u0111\u1ed9ng \u0111\u1ed3ng b\u1ed9 tr\u1ea1ng th\u00e1i t\u1eeb Git v\u00e0o Cluster. Khi b\u1ea1n commit m\u1ed9t file KongPlugin m\u1edbi l\u00ean Git, ArgoCD s\u1ebd t\u1ef1 \u0111\u1ed9ng apply n\u00f3 v\u00e0o K8s. 4. Real production lessons Trong qu\u00e1 tr\u00ecnh v\u1eadn h\u00e0nh Kong tr\u00ean GKE cho c\u00e1c h\u1ec7 th\u1ed1ng l\u1edbn, \u0111\u00e2y l\u00e0 nh\u1eefng &ldquo;chi\u1ebfn tr\u01b0\u1eddng&rdquo; m\u00e0 ch\u00fang t\u00f4i \u0111\u00e3 \u0111i qua:\nDB-less Mode kh\u00f4ng ph\u1ea3i l\u00fac n\u00e0o c\u0169ng l\u00e0 \u201cbest practice\u201d: DB-less c\u00f3 th\u1ec3 r\u1ea5t ph\u00f9 h\u1ee3p v\u1edbi GitOps v\u00e0 tri\u1ec3n khai b\u1ea5t bi\u1ebfn (immutable deployments), nh\u01b0ng n\u1ebfu c\u1ea5u h\u00ecnh kh\u00f4ng \u0111\u00fang (kh\u00f4ng c\u00f3 fallback declarative_config, kh\u00f4ng persist LMDB cache, ch\u1ec9 ch\u1ea1y 1 replica), b\u1ea1n c\u00f3 th\u1ec3 g\u1eb7p r\u1ee7i ro m\u1ea5t c\u1ea5u h\u00ecnh sau s\u1ef1 c\u1ed1 ho\u1eb7c khi pod restart. H\u00e3y ch\u1ecdn mode theo nhu c\u1ea7u (GitOps vs runtime changes vs enterprise scale), kh\u00f4ng n\u00ean m\u1eb7c \u0111\u1ecbnh \u201cDB-less l\u00e0 ch\u00e2n \u00e1i\u201d cho m\u1ecdi b\u00e0i to\u00e1n.\nC\u1ea9n th\u1eadn v\u1edbi Health Checks: C\u1ea5u h\u00ecnh Liveness v\u00e0 Readiness Probe cho Kong r\u1ea5t quan tr\u1ecdng. N\u1ebfu c\u1ea5u h\u00ecnh sai, K8s s\u1ebd restart Kong li\u00ean t\u1ee5c khi traffic t\u0103ng \u0111\u1ed9t bi\u1ebfn (do Kong x\u1eed l\u00fd ch\u1eadm l\u1ea1i), g\u00e2y ra th\u1ea3m h\u1ecda d\u00e2y chuy\u1ec1n.\nPlugin Ordering: Th\u1ee9 t\u1ef1 ch\u1ea1y c\u1ee7a c\u00e1c Plugin r\u1ea5t quan tr\u1ecdng (v\u00ed d\u1ee5: Rate Limit ph\u1ea3i ch\u1ea1y tr\u01b0\u1edbc hay sau Auth?). H\u00e3y n\u1eafm v\u1eefng &ldquo;Priority&rdquo; c\u1ee7a t\u1eebng plugin \u0111\u1ec3 tr\u00e1nh c\u00e1c l\u1ed7 h\u1ed5ng logic.\nBest practices by use case (DB-less \/ PostgreSQL \/ Hybrid) D\u01b0\u1edbi \u0111\u00e2y l\u00e0 khung tham chi\u1ebfu \u0111\u1ec3 ch\u1ecdn v\u00e0 v\u1eadn h\u00e0nh Kong an to\u00e0n trong Production. M\u1ee5c ti\u00eau l\u00e0: n\u00eau r\u00f5 trade-off, gi\u1ea3m r\u1ee7i ro m\u1ea5t c\u1ea5u h\u00ecnh, v\u00e0 ph\u00f9 h\u1ee3p c\u00e1ch deploy c\u1ee7a team.\n1) DB-less Mode (suits GitOps \/ simple setups) kong.conf essentials:\ndatabase = off declarative_config = \/kong-config\/kong.yaml # ALWAYS set a fallback lmdb_map_size = 2048m # tune based on config size G\u1ee3i \u00fd v\u1eadn h\u00e0nh:\nL\u01b0u declarative config trong Git: version control cho kong.yaml (review\/audit\/rollback). Lu\u00f4n set declarative_config: l\u00e0m \u201cphao c\u1ee9u sinh\u201d n\u1ebfu LMDB cache b\u1ecb m\u1ea5t. Persist LMDB b\u1eb1ng PersistentVolume: gi\u00fap survive pod restarts (\u0111\u1eb7c bi\u1ec7t khi b\u1ea1n mu\u1ed1n kh\u1edfi \u0111\u1ed9ng \u1ed5n \u0111\u1ecbnh, h\u1ea1n ch\u1ebf ph\u1ee5 thu\u1ed9c cache t\u1ea1m). Validate tr\u01b0\u1edbc khi deploy: kong config parse kong.yaml ho\u1eb7c deck gateway validate. Ch\u1ea1y nhi\u1ec1u replica: kh\u00f4ng ph\u1ee5 thu\u1ed9c 1 node duy nh\u1ea5t. V\u00ed d\u1ee5 Kubernetes (persist LMDB + mount declarative config):\nvolumes: - name: kong-cache persistentVolumeClaim: claimName: kong-lmdb-pvc # Persist dbless.lmdb - name: kong-config configMap: name: kong-declarative-config # Fallback config 2) PostgreSQL Mode (suits enterprise \/ runtime changes via API or UI) HA PostgreSQL: Patroni, CrunchyData, ho\u1eb7c managed service. Read replicas (n\u1ebfu c\u1ea7n): d\u00f9ng read-only endpoint\/host (t\u00f9y theo version\/feature set) \u0111\u1ec3 offload reads. Connection pooler: PgBouncer khi c\u00f3 nhi\u1ec1u Kong nodes. Backup \u0111\u1ecbnh k\u1ef3 + PITR (point-in-time recovery). Tune cache: db_update_frequency, db_cache_ttl (c\u1ea7n test theo traffic th\u1ef1c t\u1ebf). 3) Hybrid Mode (best of both) Control Plane (c\u00f3 DB) + Data Planes (DB-less): CP qu\u1ea3n l\u00fd config t\u1eadp trung (PostgreSQL). DPs nh\u1eb9, cache config t\u1eeb CP. DPs c\u00f3 th\u1ec3 ti\u1ebfp t\u1ee5c ch\u1ea1y khi CP outage nh\u1edd LMDB cache local (t\u00f9y c\u00e1ch deploy). Decision framework N\u1ebfu b\u1ea1n c\u1ea7n&hellip; N\u00ean d\u00f9ng GitOps, immutable deployments DB-less Thay \u0111\u1ed5i config runtime qua API\/UI PostgreSQL Large scale, enterprise features PostgreSQL hoac Hybrid Minimal ops overhead DB-less Cluster-wide rate limiting (ph\u1ee5 thu\u1ed9c DB) PostgreSQL V\u1eeba mu\u1ed1n central control v\u1eeba mu\u1ed1n nodes nh\u1eb9 Hybrid TL;DR DB-less an to\u00e0n n\u1ebfu c\u1ea5u h\u00ecnh \u0111\u00fang: persist LMDB + set declarative_config fallback + nhi\u1ec1u replicas. N\u1ebfu thi\u1ebfu c\u00e1c safeguard n\u00e0y: \u0111\u00fang, c\u1ea5u h\u00ecnh c\u00f3 th\u1ec3 b\u1ecb m\u1ea5t sau crash\/restart. Production l\u1edbn: \u01b0u ti\u00ean Hybrid, ho\u1eb7c PostgreSQL n\u1ebfu c\u1ea7n runtime changes v\u00e0 c\u00e1c nhu c\u1ea7u enterprise. 5. Conclusion S\u1eed d\u1ee5ng Kong Open Source tr\u00ean GKE mang l\u1ea1i s\u1ee9c m\u1ea1nh ki\u1ec3m so\u00e1t traffic tuy\u1ec7t v\u1eddi m\u00e0 Ingress m\u1eb7c \u0111\u1ecbnh kh\u00f3 so s\u00e1nh \u0111\u01b0\u1ee3c. Tuy nhi\u00ean, &ldquo;s\u1ee9c m\u1ea1nh l\u1edbn \u0111i k\u00e8m tr\u00e1ch nhi\u1ec7m l\u1edbn&rdquo;. Vi\u1ec7c l\u00e0m ch\u1ee7 Kong \u0111\u00f2i h\u1ecfi team c\u1ee7a b\u1ea1n ph\u1ea3i hi\u1ec3u s\u00e2u v\u1ec1 c\u00e1ch Kong ho\u1ea1t \u0111\u1ed9ng c\u0169ng nh\u01b0 c\u00e1c m\u00f4 h\u00ecnh qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh hi\u1ec7n \u0111\u1ea1i nh\u01b0 GitOps.\nT\u00f3m l\u1ea1i:\nCh\u1ecdn Kong n\u1ebfu b\u1ea1n c\u1ea7n Flexibility v\u00e0 Plugins. Ch\u1ecdn GCP Ingress n\u1ebfu b\u1ea1n c\u1ea7n s\u1ef1 \u0110\u01a1n gi\u1ea3n v\u00e0 \u00cdt v\u1eadn h\u00e0nh. Hy v\u1ecdng b\u00e0i vi\u1ebft n\u00e0y gi\u00fap b\u1ea1n c\u00f3 c\u00e1i nh\u00ecn r\u00f5 r\u00e0ng h\u01a1n cho ki\u1ebfn tr\u00fac h\u1ec7 th\u1ed1ng s\u1eafp t\u1edbi c\u1ee7a m\u00ecnh. Happy Coding!\nTham kh\u1ea3o:\nKong Official Documentation Kong Ingress Controller for Kubernetes ","permalink":"https:\/\/freepeak.github.io\/posts\/kong-opensource-k8s-gcp\/","summary":"Why choose Kong over the default GCP Ingress? Architecture, the reasoning behind the choice, and real-world best practices for running Kong Open Source on GKE efficiently, securely and cost-effectively.","title":"Architecture and Best Practices: Running Kong Open Source as an API Gateway on GKE"},{"content":"N\u1ebfu mu\u1ed1n l\u00e0m m\u1ed9t h\u1ec7 th\u1ed1ng s\u1eadp, \u0111\u00f4i khi b\u1ea1n kh\u00f4ng c\u1ea7n DDoS.\nCh\u1ec9 c\u1ea7n m\u1ed9t ch\u1ed7 \u0111\u1ee9ng \u0111\u1ee7 g\u1ea7n &ldquo;c\u1eeda&rdquo;.\nV\u00e0 m\u1ed9t c\u1ea5u h\u00ecnh \u0111\u1ee7 ng\u00e2y th\u01a1.\nTr\u00ean AWS EKS, c\u00e1i &ldquo;c\u1eeda&rdquo; \u0111\u00f3 th\u01b0\u1eddng l\u00e0 Ingress.\nC\u00e1i ng\u00e2y th\u01a1 th\u01b0\u1eddng l\u00e0: &ldquo;ALB Ingress l\u00e0 \u0111\u1ee7 r\u1ed3i&rdquo;.\nT\u00f4i c\u0169ng t\u1eebng tin nh\u01b0 v\u1eady.\nCho \u0111\u1ebfn khi b\u00e0i to\u00e1n kh\u00f4ng c\u00f2n l\u00e0 routing n\u1eefa, m\u00e0 l\u00e0 ki\u1ec3m so\u00e1t h\u00e0nh vi.\nC\u1ee5 th\u1ec3: rate limiting theo tenant.\nB\u1ea1n c\u00f3 1 API. Nh\u01b0ng b\u1ea1n c\u00f3 nhi\u1ec1u kh\u00e1ch h\u00e0ng. M\u1ed9t s\u1ed1 kh\u00e1ch h\u00e0ng tr\u1ea3 ti\u1ec1n nhi\u1ec1u. M\u1ed9t s\u1ed1 tr\u1ea3 ti\u1ec1n \u00edt. M\u1ed9t s\u1ed1 tr\u1ea3 ti\u1ec1n r\u1ea5t \u00edt, nh\u01b0ng request r\u1ea5t nhi\u1ec1u.\nN\u1ebfu b\u1ea1n gi\u1edbi h\u1ea1n theo IP, b\u1ea1n \u0111ang ph\u1ea1t nh\u1ea7m ng\u01b0\u1eddi v\u00f4 t\u1ed9i (NAT gateway l\u00e0m \u0111i\u1ec1u \u0111\u00f3 gi\u00fap b\u1ea1n).\nN\u1ebfu b\u1ea1n gi\u1edbi h\u1ea1n theo path, b\u1ea1n \u0111ang gi\u1ea3 v\u1edd nh\u01b0 tenant kh\u00f4ng t\u1ed3n t\u1ea1i.\nB\u1ea1n ph\u1ea3i gi\u1edbi h\u1ea1n theo identity: API key, JWT claim, consumer id\u2026 n\u00f3i chung l\u00e0 theo &ldquo;ng\u01b0\u1eddi \u0111ang g\u1ecdi&rdquo;, kh\u00f4ng ph\u1ea3i theo &ldquo;\u0111\u1ecba ch\u1ec9 nh\u00e0 h\u1ecd&rdquo;.\n\u0110\u1ebfn \u0111\u00e2y, ALB b\u1eaft \u0111\u1ea7u l\u1ed9 v\u1ebb m\u1eb7t: t\u00f4i l\u00e0 load balancer, \u0111\u1eebng b\u1eaft t\u00f4i l\u00e0m gateway.\n0) Quick contents The real problem: rate limiting by identity Decision tree: ALB\/WAF\/Lambda vs Kong Why DB-less fits EKS The proposed EKS architecture Operational guardrails (best practices) A minimal configuration example Closing 1) The real problem: rate limiting by identity (not by IP) Nghe th\u00ec \u0111\u01a1n gi\u1ea3n: &ldquo;gi\u1edbi h\u1ea1n request&rdquo;.\nNh\u01b0ng trong c\u00e1c h\u1ec7 th\u1ed1ng SaaS nghi\u00eam t\u00fac, gi\u1edbi h\u1ea1n \u1edf \u0111\u00e2u v\u00e0 theo c\u00e1i g\u00ec m\u1edbi l\u00e0 ph\u1ea7n l\u00e0m b\u1ea1n m\u1ea5t ng\u1ee7.\nV\u00ec gateway l\u00e0 m\u1ed9t th\u1ee9 gi\u1ed1ng nh\u01b0 b\u1ec7nh vi\u1ec7n trong b\u00e0i c\u1ee7a vnhacker: ai c\u0169ng \u0111i qua, d\u1eef li\u1ec7u\/traffic c\u1ef1c nh\u1ea1y c\u1ea3m c\u1ee9 th\u1ebf ch\u1ea3y v\u00e0o, c\u00f2n b\u00ean trong th\u00ec kh\u00f4ng ai mu\u1ed1n ngh\u0129 s\u00e2u.\nCho \u0111\u1ebfn khi c\u00f3 s\u1ef1 c\u1ed1.\nGi\u1edbi h\u1ea1n theo IP: d\u1ec5 l\u00e0m, nh\u01b0ng sai m\u00f4 h\u00ecnh. M\u1ed9t NAT gateway c\u00f3 th\u1ec3 l\u00e0m b\u1ea1n ph\u1ea1t nh\u1ea7m c\u1ea3 c\u00f4ng ty. Gi\u1edbi h\u1ea1n theo path: c\u0169ng d\u1ec5 l\u00e0m, nh\u01b0ng kh\u00f4ng ph\u00e2n bi\u1ec7t \u0111\u01b0\u1ee3c tenant. Gi\u1edbi h\u1ea1n theo identity: \u0111\u00fang b\u00e0i. Nh\u01b0ng identity l\u1ea1i \u0111\u1ebfn t\u1eeb nhi\u1ec1u ngu\u1ed3n: API key, JWT claim (sub\/tenant_id), header do upstream inject, mTLS client cert&hellip; L\u00fac n\u00e0y, th\u1ee9 b\u1ea1n c\u1ea7n kh\u00f4ng ph\u1ea3i l\u00e0 \u201cm\u1ed9t con ALB \u0111\u1ee9ng tr\u01b0\u1edbc Ingress\u201d. B\u1ea1n c\u1ea7n m\u1ed9t \u0111i\u1ec3m quy\u1ebft \u0111\u1ecbnh \u1edf Layer 7, n\u01a1i request \u0111\u01b0\u1ee3c hi\u1ec3u theo ng\u1eef ngh\u0129a: ai g\u1ecdi, g\u00f3i n\u00e0o, quota n\u00e0o, v\u00e0 n\u1ebfu v\u01b0\u1ee3t th\u00ec tr\u1ea3 v\u1ec1 429 m\u1ed9t c\u00e1ch nh\u1ea5t qu\u00e1n.\nN\u00f4m na: b\u1ea1n c\u1ea7n API Gateway h\u01a1n l\u00e0 Ingress.\n2) An engineer decision tree: ALB\/WAF\/Lambda or a real gateway? T\u00f4i t\u1eebng \u0111i qua \u0111\u1ee7 c\u00e1c nh\u00e1nh, n\u00ean xin k\u1ec3 theo ki\u1ec3u \u201c\u0111\u01b0\u1eddng n\u00e0o c\u0169ng c\u00f3 gi\u00e1\u201d.\nBranch A: Squeeze the logic into ALB Ingress ALB Ingress m\u1ea1nh \u1edf ch\u1ed7: routing, TLS termination, integration v\u1edbi AWS ecosystem.\nNh\u01b0ng khi b\u1ea1n \u0111\u00f2i rate limiting theo tenant, b\u1ea1n s\u1ebd b\u1eaft \u0111\u1ea7u th\u1ea5y m\u00ecnh vi\u1ebft th\u00eam th\u1ee9 m\u00e0 b\u1ea1n kh\u00f4ng \u0111\u1ecbnh v\u1eadn h\u00e0nh:\nM\u1ed9t l\u1edbp \u201ct\u1ef1 nh\u1eadn di\u1ec7n tenant\u201d (parse JWT, map API key -&gt; tenant) M\u1ed9t n\u01a1i l\u01b0u state\/quota (counter, window, redis\/elasticache?) M\u1ed9t ch\u1ed7 enforce + tr\u1ea3 l\u1ed7i chu\u1ea9n T\u1ee9c l\u00e0 b\u1ea1n \u0111ang l\u1eafp m\u1ed9t c\u00e1i gateway b\u1eb1ng\u2026 c\u00e1c m\u1ea3nh kh\u00e1c nhau.\nBranch B: Use AWS WAF WAF l\u00e0m t\u1ed1t m\u1ed9t s\u1ed1 th\u1ee9: IP reputation, bot control, rule matching.\nNh\u01b0ng v\u1edbi rate limiting theo identity, WAF th\u01b0\u1eddng khi\u1ebfn b\u1ea1n r\u01a1i v\u00e0o 2 t\u00ecnh hu\u1ed1ng:\nQuy t\u1eafc tr\u1edf n\u00ean kh\u00f3 \u0111\u1ecdc\/kh\u00f3 qu\u1ea3n: \u0111\u1ed9i app kh\u00f4ng hi\u1ec3u, \u0111\u1ed9i platform \u00f4m h\u1ebft. Chi ph\u00ed v\u00e0 v\u1eadn h\u00e0nh b\u1eaft \u0111\u1ea7u t\u0103ng theo traffic, v\u00e0 m\u1ed7i thay \u0111\u1ed5i l\u1ea1i gi\u1ed1ng \u201cxin ph\u00e9p m\u1ed9t b\u1ed9 ph\u1eadn kh\u00e1c\u201d. WAF kh\u00f4ng t\u1ec7. Ch\u1ec9 l\u00e0 n\u00f3 kh\u00f4ng sinh ra \u0111\u1ec3 tr\u1edf th\u00e0nh \u201cquota engine theo tenant\u201d.\nBranch C: Write a Lambda\/custom authorizer \u0110\u00e2y l\u00e0 con \u0111\u01b0\u1eddng h\u1ea5p d\u1eabn nh\u1ea5t, v\u00ec n\u00f3 cho b\u1ea1n c\u1ea3m gi\u00e1c \u201cm\u00ecnh ki\u1ec3m so\u00e1t \u0111\u01b0\u1ee3c h\u1ebft\u201d.\nNh\u01b0ng n\u00f3 c\u0169ng l\u00e0 con \u0111\u01b0\u1eddng d\u1ec5 bi\u1ebfn th\u00e0nh n\u1ee3 d\u00e0i h\u1ea1n:\nB\u1ea1n t\u1ef1 ch\u1ecbu tr\u00e1ch nhi\u1ec7m latency (cold start, retry, error handling) B\u1ea1n t\u1ef1 x\u00e2y observability (metrics, logs, correlation) B\u1ea1n t\u1ef1 \u0111\u1ecbnh ngh\u0129a chu\u1ea9n h\u00e0nh vi (429, headers, backoff hints) T\u1edbi m\u1ed9t ng\u00e0y, b\u1ea1n nh\u1eadn ra: b\u1ea1n v\u1eeba d\u1ef1ng m\u1ed9t API Gateway mini, nh\u01b0ng kh\u00f4ng c\u00f3 \u0111\u1ed9i ng\u0169 c\u1ee7a Kong.\nBranch D: Run Kong DB-less on EKS Kong gi\u1ea3i \u0111\u00fang c\u00e1i b\u1ea1n \u0111ang thi\u1ebfu: m\u1ed9t gateway layer 7 v\u1edbi model \u201cconsumer + credential + plugin\u201d.\nRate limiting l\u00e0 plugin, kh\u00f4ng ph\u1ea3i d\u1ef1 \u00e1n. Nh\u1eadn di\u1ec7n tenant l\u00e0 c\u1ea5u h\u00ecnh (theo key-auth\/jwt\/oauth2), kh\u00f4ng ph\u1ea3i m\u1ed7i service t\u1ef1 ch\u1ebf. H\u00e0nh vi th\u1ed1ng nh\u1ea5t: 429, headers, policy, metrics. V\u00e0 quan tr\u1ecdng: DB-less cho b\u1ea1n m\u1ed9t style v\u1eadn h\u00e0nh ph\u00f9 h\u1ee3p Kubernetes.\n3) DB-less on EKS: why this is usually the best practice T\u00f4i kh\u00f4ng n\u00f3i DB-less l\u00e0 \u201cch\u00e2n l\u00fd cho m\u1ecdi tr\u01b0\u1eddng h\u1ee3p\u201d. Nh\u01b0ng tr\u00ean EKS, v\u1edbi m\u1ee5c ti\u00eau t\u1ed1i gi\u1ea3n v\u1eadn h\u00e0nh, DB-less g\u1ea7n nh\u01b0 l\u00e0 l\u1ef1a ch\u1ecdn m\u1eb7c \u0111\u1ecbnh t\u1ed1t.\nDB-less ngh\u0129a l\u00e0: Kong kh\u00f4ng c\u1ea7n Postgres \u0111\u1ec3 l\u01b0u config runtime. Thay v\u00e0o \u0111\u00f3, config \u0111\u01b0\u1ee3c cung c\u1ea5p theo ki\u1ec3u declarative. Trong Kubernetes, b\u1ea1n k\u00e9o n\u00f3 v\u1ec1 \u201cconfiguration as code\u201d.\nL\u1ee3i \u00edch th\u1ef1c d\u1ee5ng:\nKh\u00f4ng ph\u1ea3i v\u1eadn h\u00e0nh Postgres HA ch\u1ec9 \u0111\u1ec3 ch\u1ee9a config gateway. Kong proxy g\u1ea7n nh\u01b0 stateless: scale ngang d\u1ec5, rollout r\u00f5 r\u00e0ng. H\u1ee3p GitOps: config n\u1eb1m trong Git, review \u0111\u01b0\u1ee3c, audit \u0111\u01b0\u1ee3c. \u0110\u1ed5i l\u1ea1i, b\u1ea1n ch\u1ea5p nh\u1eadn:\nMu\u1ed1n thay \u0111\u1ed5i config \u201cnhanh b\u1eb1ng UI\u201d th\u00ec kh\u00f4ng c\u00f2n vui n\u1eefa; b\u1ea1n commit Git r\u1ed3i deploy. N\u00f3i th\u1eb3ng: n\u1ebfu b\u1ea1n \u0111\u00e3 ch\u1ea1y EKS nghi\u00eam t\u00fac, b\u1ea1n n\u00ean th\u00edch c\u00e1ch l\u00e0m n\u00e0y.\n4) The proposed AWS EKS architecture (minimal but not naive) M\u1ed9t ki\u1ebfn tr\u00fac \u201c\u0111\u1ee7 t\u1ed1t\u201d v\u00e0 d\u1ec5 m\u1edf r\u1ed9ng th\u01b0\u1eddng tr\u00f4ng nh\u01b0 sau:\nClient -&gt; AWS ALB (L7) -&gt; Kong Proxy (K8s Service) -&gt; Services trong cluster\nM\u1ed9t s\u1ed1 \u0111i\u1ec3m ch\u1ed1t:\nALB v\u1eabn c\u00f3 ch\u1ed7 \u0111\u1ee9ng: n\u00f3 lo TLS\/ACM, internet-facing LB, integration v\u1edbi AWS networking. Kong l\u00e0 n\u01a1i ra quy\u1ebft \u0111\u1ecbnh: auth, rate limit, request\/response transform, logging. Services ph\u00eda sau s\u1ea1ch s\u1ebd h\u01a1n: code t\u1eadp trung v\u00e0o business logic. N\u1ebfu b\u1ea1n mu\u1ed1n \u0111i xa h\u01a1n (multi-tenant m\u1ea1nh, internal traffic, east-west), b\u1ea1n c\u00f3 th\u1ec3 t\u00e1ch:\nM\u1ed9t Kong \u201cedge\u201d cho traffic ngo\u00e0i v\u00e0o M\u1ed9t Kong \u201cinternal\u201d cho traffic n\u1ed9i b\u1ed9 (t\u00f9y m\u1ee9c \u0111\u1ed9 ph\u1ee9c t\u1ea1p) Nh\u01b0ng YAGNI: \u0111\u1eebng l\u00e0m hai con gateway ch\u1ec9 v\u00ec\u2026 nh\u00ecn cho gi\u1ed1ng big tech.\n5) Guardrails for running Kong DB-less on EKS (best practices) T\u00f4i g\u1ecdi \u0111\u00e2y l\u00e0 guardrails, kh\u00f4ng ph\u1ea3i best practices.\nV\u00ec best practices nghe nh\u01b0 khuy\u1ebfn ngh\u1ecb.\nC\u00f2n guardrails l\u00e0 th\u1ee9 b\u1ea1n d\u1ef1ng l\u00ean \u0111\u1ec3 gi\u1ea3m blast radius khi c\u00f3 ng\u01b0\u1eddi (ho\u1eb7c m\u1ed9t script) \u0111\u1ea9y nh\u1ea7m config.\n5.1) Treat gateway config like product: GitOps and review before apply N\u1ebfu gateway l\u00e0 c\u1eeda ng\u00f5, th\u00ec config c\u1ee7a n\u00f3 l\u00e0 \u201cpolicy c\u1ee7a c\u00f4ng ty\u201d.\nL\u01b0u to\u00e0n b\u1ed9 Kong config trong Git. M\u1ecdi thay \u0111\u1ed5i \u0111i qua PR review. D\u00f9ng ArgoCD\/Flux \u0111\u1ec3 sync v\u00e0o cluster. \u0110\u1eebng \u0111\u1ec3 gateway tr\u1edf th\u00e0nh n\u01a1i \u201cai c\u0169ng c\u00f3 th\u1ec3 b\u1ea5m\u201d nh\u01b0ng \u201ckh\u00f4ng ai ch\u1ecbu tr\u00e1ch nhi\u1ec7m\u201d.\n5.2) Lock the Admin API down (do not let it live as a public endpoint) Nguy\u00ean t\u1eafc s\u1ed1ng c\u00f2n:\nAdmin API \u0111\u1ec3 ClusterIP. N\u1ebfu c\u1ea7n thao t\u00e1c kh\u1ea9n: d\u00f9ng kubectl port-forward + RBAC. B\u1ea1n c\u00f3 th\u1ec3 c\u00f3 100 l\u1edbp auth cho traffic client. Nh\u01b0ng n\u1ebfu Admin API h\u1edf, th\u00ec coi nh\u01b0 xong.\n5.3) Per-tenant rate limiting: pick a clear identity source Tr\u01b0\u1edbc khi b\u1eadt plugin, h\u00e3y tr\u1ea3 l\u1eddi m\u1ed9t c\u00e2u:\n\u201cTenant identity \u0111\u1ebfn t\u1eeb \u0111\u00e2u?\u201d\nAPI key -&gt; map th\u1eb3ng consumer JWT -&gt; ti\u00eau chu\u1ea9n h\u00f3a claim (v\u00ed d\u1ee5 tenant_id) v\u00e0 enforce \u1edf gateway \u0110\u1eebng \u0111\u1ec3 m\u1ed7i service t\u1ef1 parse theo m\u1ed9t ki\u1ec3u. B\u1ea1n s\u1ebd kh\u00f4ng debug n\u1ed5i khi c\u00f3 incident.\n5.4) Avoid global plugins unless you really need them Global plugin nh\u00ecn r\u1ea5t ti\u1ec7n. Nh\u01b0ng n\u00f3 c\u0169ng l\u00e0 c\u00e1ch nhanh nh\u1ea5t \u0111\u1ec3:\nPh\u1ea1t nh\u1ea7m nh\u1eefng route kh\u00f4ng n\u00ean b\u1ecb ph\u1ea1t T\u1ea1o coupling v\u00f4 h\u00ecnh gi\u1eefa c\u00e1c team Best practice th\u01b0\u1eddng l\u00e0:\nApply plugin theo Ingress\/Service\/Route c\u1ee5 th\u1ec3 Ch\u1ec9 globalize nh\u1eefng th\u1ee9 mang t\u00ednh \u201ch\u1ea1 t\u1ea7ng\u201d (correlation id, baseline logging) 5.5) Observability is not decoration M\u1ed9t gateway kh\u00f4ng c\u00f3 metrics\/logs th\u00ec ch\u1ec9 l\u00e0 m\u1ed9t h\u1ed9p \u0111en bi\u1ebft tr\u1ea3 502.\nB\u1eadt access logs c\u00f3 c\u1ea5u tr\u00fac (JSON) v\u00e0 \u0111\u1ea9y v\u1ec1 h\u1ec7 th\u1ed1ng t\u1eadp trung. Xu\u1ea5t metrics (Prometheus) v\u00e0 \u0111\u1eb7t alert cho 4 th\u1ee9: latency, 429 rate, 5xx rate, upstream timeouts. Rate limiting theo tenant m\u00e0 kh\u00f4ng \u0111o tenant n\u00e0o b\u1ecb 429 nhi\u1ec1u nh\u1ea5t th\u00ec\u2026 b\u1ea1n ch\u1ec9 \u0111ang \u0111o\u00e1n.\n6) A minimal configuration example, for shape D\u01b0\u1edbi \u0111\u00e2y l\u00e0 v\u00ed d\u1ee5 d\u1ea1ng \u201cminh h\u1ecda \u00fd t\u01b0\u1edfng\u201d (t\u00f9y b\u1ea1n \u0111ang d\u00f9ng CRDs hay decK).\nM\u1ed9t consumer \u0111\u1ea1i di\u1ec7n cho tenant M\u1ed9t credential (API key ho\u1eb7c JWT) M\u1ed9t rate limiting plugin g\u1eafn v\u00e0o route\/service # Pseudo-example: illustrative, not a full manifest apiVersion: configuration.konghq.com\/v1 kind: KongPlugin metadata: name: rl-tenant-basic config: minute: 120 policy: local plugin: rate-limiting Ghi ch\u00fa th\u1ef1c d\u1ee5ng:\npolicy: local \u0111\u01a1n gi\u1ea3n nh\u1ea5t (\u0111\u1ebfm theo t\u1eebng pod). N\u1ebfu b\u1ea1n c\u1ea7n quota \u201cto\u00e0n c\u1ee5m\u201d ch\u00ednh x\u00e1c h\u01a1n, b\u1ea1n s\u1ebd c\u00e2n nh\u1eafc Redis. \u0110\u1eebng t\u1ed1i \u01b0u qu\u00e1 s\u1edbm. H\u00e3y b\u1eaft \u0111\u1ea7u v\u1edbi c\u00e1i b\u1ea1n v\u1eadn h\u00e0nh \u0111\u01b0\u1ee3c. 7) Closing ALB Ingress l\u00e0 m\u1ed9t default h\u1ee3p l\u00fd. Nh\u01b0ng n\u00f3 kh\u00f4ng ph\u1ea3i l\u00e0 API Gateway.\nKhi b\u00e0i to\u00e1n c\u1ee7a b\u1ea1n l\u00e0 rate limiting theo tenant, b\u1ea1n \u0111ang ch\u01a1i m\u1ed9t tr\u00f2 kh\u00e1c: tr\u00f2 c\u1ee7a identity, policy, v\u00e0 v\u1eadn h\u00e0nh nh\u1ea5t qu\u00e1n.\nKong DB-less tr\u00ean EKS l\u00e0 m\u1ed9t l\u1ef1a ch\u1ecdn th\u1ef1c d\u1ee5ng v\u00ec n\u00f3 bi\u1ebfn \u201clogic \u1edf c\u1eeda ng\u00f5\u201d th\u00e0nh c\u1ea5u h\u00ecnh c\u00f3 ki\u1ec3m so\u00e1t: review \u0111\u01b0\u1ee3c, audit \u0111\u01b0\u1ee3c, rollout \u0111\u01b0\u1ee3c.\nN\u1ebfu ph\u1ea3i ch\u1ed1t m\u1ed9t c\u00e2u \u0111\u1ec3 nh\u1edb:\nGateway l\u00e0 n\u01a1i b\u1ea1n quy\u1ebft \u0111\u1ecbnh ai \u0111\u01b0\u1ee3c l\u00e0m g\u00ec. \u0110\u1eebng bi\u1ebfn quy\u1ebft \u0111\u1ecbnh \u0111\u00f3 th\u00e0nh m\u1ed9t \u0111\u1ed1ng b\u0103ng keo.\n","permalink":"https:\/\/freepeak.github.io\/posts\/kong-eks-aws-rate-limit-tenant\/","summary":"If you need to rate limit by identity (tenant, API key, JWT claim) on EKS, ALB Ingress pushes you into a spiral of WAF, Lambda and custom code. Kong DB-less gives you one decision point at layer 7: plugins, consumers, config-as-code, GitOps. This post locks down the architecture and the deployment best practices.","title":"Kong DB-less on AWS EKS: Per-Tenant Rate Limiting, and Why ALB Ingress Is Not Enough"},{"content":"Ng\u00e0y b\u1eaft \u0111\u1ea7u d\u1ef1ng AWS cho IaC platform, t\u00f4i t\u01b0\u1edfng network l\u00e0 ph\u1ea7n \u201cnh\u1eb9 \u0111\u00f4\u201d: t\u1ea1o VPC, chia subnet, apply l\u00e0 xong.\nNh\u01b0ng network c\u00f3 m\u1ed9t \u0111\u1eb7c \u0111i\u1ec3m r\u1ea5t k\u1ef3: l\u00fac m\u1edbi l\u00e0m th\u00ec n\u00f3 tr\u00f4ng nh\u01b0 v\u00e0i d\u00f2ng config. \u0110\u1ebfn l\u00fac b\u1ea1n mu\u1ed1n m\u1edf r\u1ed9ng (VPN, peering, multi-account, k\u1ebft n\u1ed1i on-prem, t\u00e1ch m\u00f4i tr\u01b0\u1eddng), t\u1ef1 nhi\u00ean m\u1ecdi th\u1ee9 quay l\u1ea1i c\u1eafn b\u1ea1n.\nV\u00e0 th\u1ee9 hay c\u1eafn nh\u1ea5t l\u1ea1i l\u00e0 m\u1ed9t d\u00f2ng nh\u00ecn v\u00f4 h\u1ea1i: CIDR c\u1ee7a VPC.\nChanging a CIDR is not like changing a variable CIDR nh\u00ecn nh\u01b0 m\u1ed9t l\u1ef1a ch\u1ecdn k\u1ef9 thu\u1eadt thu\u1ea7n t\u00fay:\n10.0.0.0\/16 Nh\u01b0ng th\u1ef1c t\u1ebf n\u00f3 l\u00e0 ranh gi\u1edbi \u0111\u1ecba ch\u1ec9 IP c\u1ee7a c\u1ea3 \u201cth\u00e0nh ph\u1ed1\u201d h\u1ea1 t\u1ea7ng b\u1ea1n \u0111ang x\u00e2y:\nsubnet public\/private sinh ra t\u1eeb \u0111\u00f3 route table, NAT gateway, VPC endpoints b\u00e1m theo \u0111\u00f3 EKS nodes, pods, services\u2026 \u0111\u1ec1u ph\u1ea3i s\u1ed1ng trong kh\u00f4ng gian \u0111\u00f3 peering \/ VPN \/ Transit Gateway ph\u1ea3i th\u01b0\u01a1ng l\u01b0\u1ee3ng v\u1edbi CIDR \u0111\u00f3 L\u00fac m\u1edbi d\u1ef1ng dev, b\u1ea1n \u00edt khi th\u1ea5y v\u1ea5n \u0111\u1ec1. V\u1eabn ping \u0111\u01b0\u1ee3c, v\u1eabn deploy \u0111\u01b0\u1ee3c, v\u1eabn l\u00ean c\u1ee5m.\nR\u1eafc r\u1ed1i ch\u1ec9 l\u1ed9 ra khi b\u1ea1n b\u1eaft \u0111\u1ea7u n\u1ed1i m\u1ea1ng th\u1eadt: VPC-to-VPC, VPC-to-onprem, ho\u1eb7c gom nhi\u1ec1u m\u00f4i tr\u01b0\u1eddng\/t\u00e0i kho\u1ea3n v\u00e0o m\u1ed9t h\u1ec7 th\u1ed1ng.\nT\u1edbi \u0111o\u1ea1n \u0111\u00f3, b\u1ea1n m\u1edbi b\u1eadt ra c\u00e2u h\u1ecfi: \u201cN\u1ebfu CIDR \u0111ang d\u00f9ng b\u1ecb ch\u1ed3ng l\u1ea5p th\u00ec sao?\u201d\nC\u00e2u tr\u1ea3 l\u1eddi th\u01b0\u1eddng l\u00e0: th\u00ec m\u1ec7t.\nB\u1ea1n c\u00f3 th\u1ec3 th\u00eam CIDR th\u1ee9 hai, r\u1ed3i d\u1ecdn d\u1eb9p d\u1ea7n. Ho\u1eb7c b\u1ea1n t\u1ea1o VPC m\u1edbi v\u00e0 migrate. D\u00f9 ch\u1ecdn h\u01b0\u1edbng n\u00e0o, \u0111\u00e2y c\u0169ng kh\u00f4ng ph\u1ea3i lo\u1ea1i vi\u1ec7c b\u1ea1n mu\u1ed1n l\u00e0m v\u00e0o tu\u1ea7n m\u00e0 team \u0111ang b\u1eadn release.\nWhy CIDRs overlap T\u00f4i th\u1ea5y c\u00f3 hai nguy\u00ean nh\u00e2n ph\u1ed5 bi\u1ebfn:\nCopy-paste kinh \u0111i\u1ec3n AWS tutorial n\u00e0o c\u0169ng c\u00f3 v\u00ed d\u1ee5 10.0.0.0\/16. B\u1ea1n copy m\u1ed9t l\u1ea7n th\u00ec kh\u00f4ng sao. Nh\u01b0ng \u0111\u1ebfn l\u00fac b\u1ea1n c\u00f3 3 c\u00e1i VPC, 5 m\u00f4i tr\u01b0\u1eddng, th\u00eam m\u1ed9t m\u1ea1ng office c\u0169ng d\u00f9ng 10.0.0.0\/16\u2026 th\u1ebf l\u00e0 b\u1eaft \u0111\u1ea7u \u201c\u0111\u1ee5ng h\u00e0ng\u201d.\nKh\u00f4ng c\u00f3 \u201cb\u1ea3ng \u0111\u1ecba ch\u1ec9\u201d c\u1ea5p t\u1ed5 ch\u1ee9c M\u1ed7i team t\u1ef1 ch\u1ecdn m\u1ed9t d\u1ea3i. Khi ch\u01b0a k\u1ebft n\u1ed1i li\u00ean m\u1ea1ng th\u00ec v\u1eabn \u1ed5n. Khi c\u1ea7n n\u1ed1i th\u00ec ph\u00e1t hi\u1ec7n d\u1ea3i c\u1ee7a nhau ch\u1ed3ng l\u1ea5p v\u00e0 kh\u00f4ng route \u0111\u01b0\u1ee3c.\nCIDR ch\u1ed3ng l\u1ea5p kh\u00f4ng ph\u1ea3i l\u1ed7i k\u1ef9 thu\u1eadt ph\u1ee9c t\u1ea1p. N\u00f3 gi\u1ed1ng ki\u1ec3u \u201cl\u00fac x\u00e2y nh\u00e0 qu\u00ean ch\u1eeba \u0111\u01b0\u1eddng \u1ed1ng\u201d. Qu\u00ean xong r\u1ed3i, s\u1eeda m\u1edbi \u0111au.\nLock the CIDR early, and lift it to project-level config T\u00f4i kh\u00f4ng ngh\u0129 CIDR l\u00e0 th\u1ee9 c\u1ea7n \u201cch\u1ecdn cho \u0111\u00fang m\u1ed9t l\u1ea7n l\u00e0 xong m\u00e3i m\u00e3i\u201d. Nh\u01b0ng t\u00f4i tin n\u00f3 l\u00e0 th\u1ee9 n\u00ean \u0111\u01b0\u1ee3c qu\u1ea3n tr\u1ecb nh\u01b0 m\u1ed9t quy\u1ebft \u0111\u1ecbnh n\u1ec1n t\u1ea3ng, thay v\u00ec n\u1eb1m r\u1ea3i r\u00e1c trong code.\nC\u00e1ch t\u00f4i l\u00e0m (\u0111\u01a1n gi\u1ea3n, nh\u01b0ng hi\u1ec7u qu\u1ea3) l\u00e0:\nKhai b\u00e1o vpc_cidr \u1edf project.hcl theo t\u1eebng m\u00f4i tr\u01b0\u1eddng. Truy\u1ec1n n\u00f3 xu\u1ed1ng network\/terragrunt.hcl b\u1eb1ng inputs. V\u00ec sao quan tr\u1ecdng?\nCIDR tr\u1edf th\u00e0nh \u201ctham s\u1ed1 c\u1ea5p d\u1ef1 \u00e1n\u201d, review m\u1ed9t ph\u00e1t l\u00e0 th\u1ea5y. M\u1ed7i m\u00f4i tr\u01b0\u1eddng c\u00f3 d\u1ea3i r\u00f5 r\u00e0ng, \u00edt bi\u1ebfn th\u00e0nh \u201cmystery meat config\u201d. V\u1ec1 sau mu\u1ed1n th\u00eam staging\/prod\/multi-account, b\u1ea1n ch\u1ec9 vi\u1ec7c m\u1edf r\u1ed9ng b\u1ea3ng CIDR, tr\u00e1nh ch\u1ed3ng l\u1ea5p t\u1eeb \u0111\u1ea7u. T\u00f3m l\u1ea1i: thay v\u00ec \u0111\u1ec3 CIDR l\u00e0 m\u1ed9t chi ti\u1ebft implementation, t\u00f4i coi n\u00f3 l\u00e0 m\u1ed9t ph\u1ea7n c\u1ee7a h\u1ee3p \u0111\u1ed3ng ki\u1ebfn tr\u00fac.\nA small strategy for a big problem N\u1ebfu \u00e1p d\u1ee5ng c\u00e1ch ngh\u0129 \u201cchi\u1ebfn l\u01b0\u1ee3c b\u1eaft \u0111\u1ea7u t\u1eeb v\u1ea5n \u0111\u1ec1\u201d, th\u00ec v\u1ea5n \u0111\u1ec1 \u1edf \u0111\u00e2y kh\u00f4ng ph\u1ea3i l\u00e0 \u201cch\u1ecdn CIDR n\u00e0o cho \u0111\u1eb9p\u201d.\nV\u1ea5n \u0111\u1ec1 l\u00e0: v\u1ec1 sau b\u1ea1n s\u1ebd ph\u1ea3i k\u1ebft n\u1ed1i nhi\u1ec1u th\u1ee9 l\u1ea1i v\u1edbi nhau, v\u00e0 l\u00fac \u0111\u00f3 CIDR sai s\u1ebd l\u00e0m b\u1ea1n tr\u1ea3 gi\u00e1 cao.\nCh\u1ed1t CIDR t\u1eeb s\u1edbm kh\u00f4ng l\u00e0m b\u1ea1n deploy nhanh h\u01a1n h\u00f4m nay.\nNh\u01b0ng n\u00f3 gi\u00fap b\u1ea1n kh\u1ecfi ph\u1ea3i ch\u1ea1y ng\u01b0\u1ee3c l\u1ea1i v\u00e0o ng\u00e0y mai.\nIllustrations S\u01a1 \u0111\u1ed3 1: CIDR l\u00e0 n\u1ec1n cho m\u1ecdi l\u1edbp h\u1ea1 t\u1ea7ng S\u01a1 \u0111\u1ed3 2: Khi CIDR ch\u1ed3ng l\u1ea5p, \u0111\u01b0\u1eddng n\u1ed1i b\u1ecb \u201ck\u1eb9t\u201d ","permalink":"https:\/\/freepeak.github.io\/posts\/chot-vpc-cidr-tu-som\/","summary":"A VPC CIDR looks like a small technical choice, but it is the foundation of the whole network. Here is why locking it in early and treating it as a project-level decision saves you from rebuilding when you scale.","title":"Lock In VPC CIDR Early: A Small Decision That Prevents Tearing It All Down Later"},{"content":" L\u01b0u \u00fd: H\u00ecnh \u1ea3nh trong b\u00e0i vi\u1ebft \u0111ang \u0111\u01b0\u1ee3c c\u1eadp nh\u1eadt\nCh\u00e0o anh em, m\u00ecnh vi\u1ebft b\u00e0i n\u00e0y \u0111\u1ec3 k\u1ec3 l\u1ea1i h\u00e0nh tr\u00ecnh &ldquo;ch\u01a1i h\u1ec7 AI agents&rdquo; c\u1ee7a m\u1ed9t \u0111\u1ee9a l\u00e0m dev \u0111\u00fang ngh\u0129a: th\u1eed \u0111\u1ee7 ki\u1ec3u tool, tr\u1ea3 ph\u00ed \u0111\u1ee7 n\u01a1i, b\u1ecb limit \u0111\u1ee7 l\u1ea7n, r\u1ed3i cu\u1ed1i c\u00f9ng r\u00fat ra \u0111\u01b0\u1ee3c m\u1ed9t k\u1ebft lu\u1eadn kh\u00e1 th\u1ef1c d\u1ee5ng: m\u1ed7i model\/tool c\u00f3 \u0111i\u1ec3m m\u1ea1nh \u2013 y\u1ebfu ri\u00eang, d\u00f9ng \u0111\u00fang b\u00e0i m\u1edbi th\u1ea5y \u0111\u00e1ng ti\u1ec1n.\nB\u00e0i n\u00e0y m\u00ecnh k\u1ec3 theo tr\u1ea3i nghi\u1ec7m th\u1eadt, v\u00e0 c\u00f3 k\u00e8m m\u1ed9t b\u1ea3ng t\u1ed5ng h\u1ee3p cu\u1ed1i b\u00e0i \u0111\u1ec3 anh em d\u1ec5 ch\u1ecdn.\n1) From ChatGPT to the era of unpaid labour, and the first paid seat M\u00ecnh b\u1eaft \u0111\u1ea7u v\u1edbi ChatGPT ngay t\u1eeb l\u00fac n\u00f3 v\u1eeba ra m\u1eaft. L\u00fac \u0111\u00f3 qu\u00e1 \u0111\u00e3: h\u1ecfi g\u00ec c\u0169ng tr\u1ea3 l\u1eddi, vi\u1ebft email, t\u00f3m t\u1eaft, brainstorm\u2026 \u0111\u1ee7 th\u1ee9. Sau n\u00e0y nhu c\u1ea7u t\u0103ng (v\u00e0 gi\u1edbi h\u1ea1n c\u0169ng t\u0103ng), m\u00ecnh b\u1eaft \u0111\u1ea7u b\u01b0\u1edbc qua c\u00e1c tool chuy\u00ean code.\nC\u00f3 giai \u0111o\u1ea1n m\u00ecnh &ldquo;c\u00e0y&rdquo; b\u1ea3n free c\u1ee7a Cursor b\u1eb1ng c\u00e1ch d\u00f9ng\u2026 5 email. Anh em n\u00e0o t\u1eebng tr\u1ea3i ch\u1eafc hi\u1ec3u c\u1ea3m gi\u00e1c hit limit r\u1ed3i ph\u1ea3i \u0111\u1ed5i account n\u00f3 &ldquo;h\u1ec1&rdquo; th\u1ebf n\u00e0o. Cu\u1ed1i c\u00f9ng m\u00ecnh c\u0169ng xu\u1ed1ng ti\u1ec1n $20\/th\u00e1ng cho Cursor.\n2) As projects grow, I need AI to do real work M\u00ecnh kh\u00f4ng ch\u1ec9 code m\u1ea5y repo CRUD nh\u1ecf. C\u00f4ng vi\u1ec7c\/side project c\u1ee7a m\u00ecnh \u0111i qua \u0111\u1ee7 lo\u1ea1i m\u1ee9c \u0111\u1ed9 ph\u1ee9c t\u1ea1p:\nCRUD\/Monolith: API + DB + auth\/roles + migration. EDA (Event-Driven Architecture): Kafka\/NATS\/RabbitMQ, retry, idempotency, message schema. MCP\/MPC\/Crypto: lu\u1ed3ng k\u00fd\/verify, chia s\u1ebb b\u00ed m\u1eadt, x\u1eed l\u00fd key material. PKI: certificate chain, CSR, rotation, trust store, policy. C\u00e0ng l\u00ean m\u1ea5y t\u1ea7ng n\u00e0y, m\u00ecnh c\u00e0ng quan t\u00e2m 3 th\u1ee9:\nQuality: code ra c\u00f3 \u0111\u00fang kh\u00f4ng, c\u00f3 &ldquo;h\u1ee3p n\u00e3o&rdquo; kh\u00f4ng. Cycle prompt: bao nhi\u00eau v\u00f2ng h\u1ecfi-\u0111\u00e1p \u0111\u1ec3 ho\u00e0n th\u00e0nh task. Stability\/Quota: \u0111ang ch\u1ea1y m\u00e0 b\u1ecb limit th\u00ec m\u1ea5t flow c\u1ef1c k\u1ef3. 3) Cursor + Opus 4.5: the most stable on quality and prompt cycle (but rate limited) N\u1ebfu n\u00f3i thu\u1ea7n v\u1ec1 &ldquo;\u0111\u1ed9 ch\u1eafc tay&rdquo; khi l\u00e0m project l\u1edbn (\u0111\u1ecdc codebase r\u1ed9ng, b\u00e1m ng\u1eef c\u1ea3nh d\u00e0i, \u0111\u1ee5ng nhi\u1ec1u ng\u00f4n ng\u1eef), th\u00ec Cursor + Opus 4.5 l\u00e0 combo m\u00ecnh \u0111\u00e1nh gi\u00e1 \u1ed5n \u0111\u1ecbnh nh\u1ea5t.\nV\u00ed d\u1ee5 ki\u1ec3u task m\u00ecnh hay giao:\n&ldquo;Qu\u00e9t h\u1ebft repo, t\u00ecm lu\u1ed3ng auth hi\u1ec7n t\u1ea1i, th\u00eam mTLS cho service-to-service&rdquo; &ldquo;Refactor module payment th\u00e0nh event-driven, \u0111\u1ea3m b\u1ea3o idempotency v\u00e0 retry&rdquo; &ldquo;\u0110\u1ecdc code crypto \u0111ang d\u00f9ng, vi\u1ebft th\u00eam verify path + test vectors&rdquo; V\u1edbi m\u1ea5y task n\u00e0y, Opus th\u01b0\u1eddng gi\u00fap m\u00ecnh gi\u1ea3m s\u1ed1 v\u00f2ng prompt r\u1ea5t r\u00f5: h\u1ecfi \u00edt h\u01a1n, s\u1eeda \u00edt h\u01a1n, v\u00e0 \u00edt b\u1ecb &ldquo;l\u1ea1c ng\u1eef c\u1ea3nh&rdquo;.\nNh\u01b0ng\u2026 \u0111i\u1ec3m \u0111au duy nh\u1ea5t: limit qu\u00e1 nhi\u1ec1u. D\u00f9ng ki\u1ec3u dev c\u00e0y 4\u20136 ti\u1ebfng\/ng\u00e0y l\u00e0 s\u1ebd d\u00ednh cap, v\u00e0 m\u00ecnh kh\u00f4ng mu\u1ed1n m\u1ed7i l\u1ea7n v\u00e0o gu\u1ed3ng l\u1ea1i b\u1ecb ng\u1eaft.\n4) Because of limits, I moved to GitHub Copilot + Antigravity (Google) Hi\u1ec7n t\u1ea1i m\u00ecnh d\u00f9ng song song:\nGitHub Copilot: v\u1edbi c\u00e1ch t\u00ednh credit cho Opus &ldquo;d\u1ec5 th\u1edf h\u01a1n&rdquo; (m\u00ecnh \u0111ang d\u00f9ng \u1edf m\u1ee9c Opus ch\u1ec9 t\u1ea7m 3x credit) n\u00ean t\u1ed5ng chi ph\u00ed d\u1ec5 ki\u1ec3m so\u00e1t h\u01a1n. Antigravity (Google): m\u00ecnh d\u00f9ng nh\u01b0 m\u1ed9t agent ph\u1ee5 tr\u1ee3 m\u1ea1nh, nh\u01b0ng ki\u1ec3u limit theo chu k\u1ef3 5h n\u00ean c\u1ea7n &ldquo;x\u1ebfp l\u1ecbch&rdquo; l\u00fac n\u00e0o d\u00f9ng cho \u0111\u00e1ng. Th\u00f3i quen c\u1ee7a m\u00ecnh l\u00e0:\nTask c\u1ea7n ho\u00e0n th\u00e0nh nhanh, c\u00f3 deadline, repo l\u1edbn: \u01b0u ti\u00ean Cursor\/Opus (n\u1ebfu quota \u0111\u1ee7). Khi quota g\u1eaft: \u0111\u1ea9y qua Copilot \u0111\u1ec3 gi\u1eef nh\u1ecbp code. Nh\u1eefng \u0111o\u1ea1n c\u1ea7n agent \u0111\u1ecdc\/\u0111i\u1ec1u ph\u1ed1i nhi\u1ec1u b\u01b0\u1edbc (setup, thay config, ch\u1ea1y chu\u1ed7i thay \u0111\u1ed5i): d\u00f9ng Antigravity (Google). 5) Claude Code: many plugins and features, but hard limits push team cost up M\u00ecnh v\u1eabn c\u00f4ng nh\u1eadn h\u1ec7 Claude c\u00f3 nhi\u1ec1u \u0111i\u1ec3m hay: ecosystem plugin\/support kh\u00e1 r\u1ed9ng, tr\u1ea3i nghi\u1ec7m &ldquo;n\u00f3i chuy\u1ec7n \u0111\u1ec3 code&rdquo; m\u01b0\u1ee3t. Nh\u01b0ng v\u1ea5n \u0111\u1ec1 l\u1edbn nh\u1ea5t khi\u1ebfn m\u00ecnh kh\u00f4ng g\u1eafn b\u00f3 l\u00e2u l\u00e0 limit usage m\u1ea1nh, d\u1eabn \u0111\u1ebfn khi quy ra chi ph\u00ed\/kh\u1ea3 n\u0103ng c\u00e0y, th\u00ec c\u1ea3m gi\u00e1c \u0111\u1eaft h\u01a1n c\u00e1c nh\u00e0 kh\u00e1c (v\u00ec m\u00ecnh b\u1ecb bu\u1ed9c ph\u1ea3i ti\u1ebft ki\u1ec7m l\u01b0\u1ee3t).\n6) Small repos, simple tasks: GLM 4.7 is what I use most V\u1edbi nh\u1eefng t\u00e1c v\u1ee5 ki\u1ec3u:\nrepo \u00edt file thay \u0111\u1ed5i nh\u1ecf th\u00eam endpoint CRUD vi\u1ebft script migration \u0111\u01a1n gi\u1ea3n \u2026th\u00ec m\u00ecnh lu\u00f4n \u01b0u ti\u00ean GLM 4.7. L\u00fd do l\u00e0 n\u00f3 nhanh, ra k\u1ebft qu\u1ea3 g\u1ecdn, v\u00e0 m\u00ecnh kh\u00f4ng c\u1ea7n &ldquo;\u0111\u1ed1t&rdquo; Opus cho nh\u1eefng vi\u1ec7c kh\u00f4ng \u0111\u00f2i h\u1ecfi ch\u1ea5t l\u01b0\u1ee3ng qu\u00e1 cao.\n7) Writing and research: give the right job to the right agent M\u00ecnh chia use-case kh\u00e1 r\u00f5:\nVi\u1ebft email, vi\u1ebft blog, so\u1ea1n n\u1ed9i dung: m\u00ecnh d\u00f9ng GPT v\u00ec v\u0103n phong linh ho\u1ea1t, d\u1ec5 ch\u1ec9nh tone. Research\/nghi\u00ean c\u1ee9u: m\u00ecnh th\u01b0\u1eddng d\u00f9ng Gemini v\u00e0 Grok v\u00ec nhanh, h\u1ee3p ki\u1ec3u qu\u00e9t th\u00f4ng tin nhi\u1ec1u h\u01b0\u1edbng. 8) Summary table: which tool for which job Use case Tool\/model m\u00ecnh hay d\u00f9ng V\u00ec sao h\u1ee3p \u0110i\u1ec3m c\u1ea7n l\u01b0u \u00fd Project l\u1edbn, \u0111a ng\u00f4n ng\u1eef, \u0111\u1ed9 ph\u1ee9c t\u1ea1p cao (CRUD \u2192 EDA \u2192 MCP\/MPC \u2192 PKI) Cursor + Opus 4.5 Ch\u1ea5t l\u01b0\u1ee3ng \u1ed5n \u0111\u1ecbnh, \u00edt v\u00f2ng prompt, b\u00e1m ng\u1eef c\u1ea3nh d\u00e0i Limit d\u1ec5 \u0111\u1ee9t m\u1ea1ch Gi\u1eef nh\u1ecbp code h\u1eb1ng ng\u00e0y, teamwork, IDE integration GitHub Copilot (Opus ~3x credit) \u1ed4n \u0111\u1ecbnh, t\u00edch h\u1ee3p t\u1ed1t, cost d\u1ec5 ki\u1ec3m so\u00e1t h\u01a1n V\u1eabn c\u1ea7n prompt r\u00f5 khi l\u00e0m ki\u1ebfn tr\u00fac Agent ch\u1ea1y \u0111a b\u01b0\u1edbc, h\u1ed7 tr\u1ee3 \u0111i\u1ec1u ph\u1ed1i task Antigravity (Google) M\u1ea1nh v\u1ec1 agent flow, ph\u00f9 h\u1ee3p vi\u1ec7c d\u00e0i h\u01a1i Limit theo chu k\u1ef3 5h Repo nh\u1ecf, task \u0111\u01a1n gi\u1ea3n GLM 4.7 Nhanh, g\u1ecdn, \u0111\u1ee7 t\u1ed1t cho vi\u1ec7c nh\u1eb9 Kh\u00f4ng ph\u1ea3i l\u00fac n\u00e0o c\u0169ng &ldquo;deep&rdquo; \u0111\u01b0\u1ee3c Vi\u1ebft l\u00e1ch (mail\/blog) GPT D\u1ec5 \u0111i\u1ec1u ch\u1ec9nh gi\u1ecdng v\u0103n, b\u1ed1 c\u1ee5c t\u1ed1t C\u1ea7n fact-check k\u1ef9 Research \u0111a chi\u1ec1u Gemini, Grok Qu\u00e9t nhanh, g\u1ee3i \u00fd h\u01b0\u1edbng t\u00ecm C\u1ea7n ki\u1ec3m tra ngu\u1ed3n 9) Conclusion: to judge fairly, benchmark the same task Cu\u1ed1i c\u00f9ng, c\u00e1ch m\u00ecnh th\u1ea5y &ldquo;c\u00f4ng b\u1eb1ng&rdquo; nh\u1ea5t \u0111\u1ec3 ch\u1ecdn tool\/model l\u00e0:\nl\u1ea5y \u0111\u00fang m\u1ed9t t\u00e1c v\u1ee5, v\u00ed d\u1ee5 &ldquo;th\u00eam auth + RBAC + audit log cho API&rdquo; ch\u1ea1y l\u1ea7n l\u01b0\u1ee3t tr\u00ean c\u00e1c model so s\u00e1nh \u0111\u1ea7u ra: \u0111\u1ed9 \u0111\u00fang, \u0111\u1ed9 s\u1ea1ch, t\u1ed1c \u0111\u1ed9, s\u1ed1 v\u00f2ng prompt N\u00f3i chung, m\u00ecnh kh\u00f4ng tin v\u00e0o &ldquo;model n\u00e0o b\u00e1 nh\u1ea5t&rdquo; cho m\u1ecdi th\u1ee9. M\u00ecnh tin v\u00e0o vi\u1ec7c ch\u1ecdn \u0111\u00fang model cho \u0111\u00fang b\u00e0i, v\u00e0 s\u1eb5n s\u00e0ng \u0111\u1ed5i tool n\u1ebfu b\u00e0i to\u00e1n \u0111\u1ed5i.\nN\u1ebfu b\u1ea1n mu\u1ed1n, b\u1ea1n \u0111\u01b0a m\u00ecnh 2\u20133 task b\u1ea1n hay l\u00e0m nh\u1ea5t, m\u00ecnh gi\u00fap b\u1ea1n thi\u1ebft k\u1ebf m\u1ed9t checklist benchmark \u0111\u1ec3 test c\u00e1c model m\u1ed9t c\u00e1ch kh\u00e1ch quan.\n","permalink":"https:\/\/freepeak.github.io\/posts\/hanh-trinh-su-dung-ai-agents\/","summary":"A tour and comparison of the popular AI coding agents: from ChatGPT, Cursor and GitHub Copilot to Claude Code and GLM 4.7, judged on real work from CRUD apps through EDA, MCP\/MPC and PKI.","title":"Using AI Coding Agents as a Developer: A 2026 Field Report"},{"content":"","permalink":"https:\/\/freepeak.github.io\/tags\/","summary":"tags","title":"Tags"}]