<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Best-Practices - Nhãn - Luân Dương</title><link>https://blog.luandnh.com/tags/best-practices/</link><description>Best-Practices - Nhãn - Luân Dương</description><generator>Hugo -- gohugo.io</generator><language>vi-VN</language><managingEditor>luandnh98@gmail.com (Dương Nguyễn Hoàng Luân)</managingEditor><webMaster>luandnh98@gmail.com (Dương Nguyễn Hoàng Luân)</webMaster><lastBuildDate>Thu, 28 Aug 2025 10:00:00 +0700</lastBuildDate><atom:link href="https://blog.luandnh.com/tags/best-practices/" rel="self" type="application/rss+xml"/><item><title>Graceful shutdown: lợi ích và lý do phải có</title><link>https://blog.luandnh.com/posts/graceful-shutdown/</link><pubDate>Thu, 28 Aug 2025 10:00:00 +0700</pubDate><author>luandnh98@gmail.com (Dương Nguyễn Hoàng Luân)</author><guid>https://blog.luandnh.com/posts/graceful-shutdown/</guid><description><![CDATA[<div class="featured-image">
                <img src="/images/covers/graceful-shutdown-cover.png" referrerpolicy="no-referrer">
            </div><p>Có lần team mình deploy bản mới lúc 11h đêm. <code>kubectl rollout restart</code> xong, 30 giây sau PagerDuty réo: 200 cái 502 trong 5 giây. Khách hàng đang đặt đồ ăn thì timeout. Mình lật đật rollout undo, xong ngồi check log — hóa ra pod cũ bị SIGTERM, HTTP server tắt ngay lập tức, 50 request đang xử lý dở bị cắt ngang hết.</p>
<p>Lỗi không phải ở Kubernetes. Lỗi ở service mình: <strong>không có graceful shutdown</strong>.</p>]]></description></item><item><title>Quản lý goroutine: errgroup, leak-proof, backpressure</title><link>https://blog.luandnh.com/posts/quan-ly-goroutine/</link><pubDate>Mon, 25 Aug 2025 10:00:00 +0700</pubDate><author>luandnh98@gmail.com (Dương Nguyễn Hoàng Luân)</author><guid>https://blog.luandnh.com/posts/quan-ly-goroutine/</guid><description><![CDATA[<div class="featured-image">
                <img src="/images/covers/goroutine-cover.png" referrerpolicy="no-referrer">
            </div><p>Tháng trước, một service của team mình đột nhiên chậm như rùa. p50 latency từ 50ms nhảy lên 3 giây. Mở Grafana lên — 120,000 goroutine đang chạy. Bình thường chỉ 200. Ai đó vừa push code quên <code>defer cancel()</code> trong một vòng lặp xử lý batch.</p>
<p>Goroutine là thứ làm Go ngon: nhẹ (~2KB stack), rẻ, bật cái là chạy. Nhưng chính vì quá dễ dùng nên quá dễ leak. Bài này là những pattern mình dùng để giữ goroutine trong tầm kiểm soát — từ errgroup đến worker pool đến backpressure. Tất cả có code chạy được, hầu hết rút từ production.</p>]]></description></item><item><title>API Filtering: gọi dữ liệu như dân sành cà phê</title><link>https://blog.luandnh.com/posts/api-filtering/</link><pubDate>Wed, 20 Aug 2025 10:00:00 +0700</pubDate><author>luandnh98@gmail.com (Dương Nguyễn Hoàng Luân)</author><guid>https://blog.luandnh.com/posts/api-filtering/</guid><description><![CDATA[<div class="featured-image">
                <img src="/images/covers/api-filtering-cover.png" referrerpolicy="no-referrer">
            </div><p>Năm đầu đi làm, mình từng viết một endpoint <code>GET /api/menus</code> trả về&hellip; toàn bộ menu. 200 items mỗi lần gọi. JSON nặng 1.2MB. Frontend chỉ cần tên + giá của 10 món đang active. Mình nhớ câu đầu tiên anh lead nói: &ldquo;Mày đang gửi cả cái kho hàng cho người ta chỉ cần xem menu đấy à?&rdquo;</p>
<p>Bài học đó mất 1 tuần refactor. Từ đó mỗi lần thiết kế API, mình luôn nghĩ đến quán cà phê: khách gọi iced Americano, barista không bưng ra cả quầy — họ ghi order rõ ràng, pha đúng món, và đưa đúng ly. API cũng phải vậy.</p>]]></description></item><item><title>Context trong Go: truyền dữ liệu, deadline, cancel — dùng đúng hay chết hiệu năng</title><link>https://blog.luandnh.com/posts/context-trong-go/</link><pubDate>Fri, 15 Aug 2025 10:00:00 +0700</pubDate><author>luandnh98@gmail.com (Dương Nguyễn Hoàng Luân)</author><guid>https://blog.luandnh.com/posts/context-trong-go/</guid><description><![CDATA[<div class="featured-image">
                <img src="/images/covers/go-context-cover.png" referrerpolicy="no-referrer">
            </div><p>Hồi mới code Go, mình có một bug production kỳ lạ: cứ sau 3-4 ngày chạy, service tự dưng ngốn 8GB RAM rồi OOM. Mò suốt chiều thứ Sáu mới phát hiện: một cái goroutine không bao giờ kết thúc vì mình quên truyền context xuống gRPC call. Mỗi request leak một goroutine, sau 100K request thì server &ldquo;đội mồ&rdquo; luôn.</p>
<p>Đó là lần đầu mình hiểu <code>context.Context</code> không phải mấy dòng code cho có. Dùng sai là chết thật. Dùng đúng thì request dừng gọn, goroutine sạch, hệ thống nhẹ nhàng.</p>]]></description></item></channel></rss>