<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Tiến Đạt - Backend Engineer: Kiến thức nền tảng]]></title><description><![CDATA[Kiến thức nền tảng]]></description><link>https://tiendatengineer.substack.com/s/kien-thuc-nen-tang</link><image><url>https://substackcdn.com/image/fetch/$s_!SVru!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc11b84e1-f5dc-4df7-a620-e907bae4dd52_1042x1044.png</url><title>Tiến Đạt - Backend Engineer: Kiến thức nền tảng</title><link>https://tiendatengineer.substack.com/s/kien-thuc-nen-tang</link></image><generator>Substack</generator><lastBuildDate>Sun, 07 Jun 2026 23:50:28 GMT</lastBuildDate><atom:link href="https://tiendatengineer.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Nguyễn Doãn Tiến Đạt]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[tiendatengineer@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[tiendatengineer@substack.com]]></itunes:email><itunes:name><![CDATA[Nguyễn Doãn Tiến Đạt]]></itunes:name></itunes:owner><itunes:author><![CDATA[Nguyễn Doãn Tiến Đạt]]></itunes:author><googleplay:owner><![CDATA[tiendatengineer@substack.com]]></googleplay:owner><googleplay:email><![CDATA[tiendatengineer@substack.com]]></googleplay:email><googleplay:author><![CDATA[Nguyễn Doãn Tiến Đạt]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[BigO]]></title><description><![CDATA[C&#225;ch &#273;o l&#432;&#7901;ng hi&#7879;u n&#259;ng c&#7911;a thu&#7853;t to&#225;n, d&#7921; &#273;o&#225;n th&#7901;i gian v&#224; b&#7897; nh&#7899; c&#7847;n khi d&#7919; li&#7879;u t&#259;ng l&#234;n]]></description><link>https://tiendatengineer.substack.com/p/bigo</link><guid isPermaLink="false">https://tiendatengineer.substack.com/p/bigo</guid><dc:creator><![CDATA[Nguyễn Doãn Tiến Đạt]]></dc:creator><pubDate>Fri, 12 Dec 2025 10:01:34 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!HRJu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F869ee25a-9e59-477c-8767-1085a4648dfc_1280x720.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Khi d&#7919; li&#7879;u ng&#224;y c&#224;ng l&#7899;n, l&#224;m th&#7871; n&#224;o &#273;&#7875; &#273;o l&#432;&#7901;ng v&#224; d&#7921; &#273;o&#225;n hi&#7879;u n&#259;ng c&#7911;a thu&#7853;t to&#225;n hay h&#7879; th&#7889;ng? &#272;&#243; ch&#237;nh l&#224; vai tr&#242; c&#7911;a <strong>BigO</strong> &#8211; m&#7897;t c&#225;ch &#273;&#7875; hi&#7875;u <strong>th&#7901;i gian v&#224; b&#7897; nh&#7899; c&#7847;n thi&#7871;t khi s&#7889; l&#432;&#7907;ng d&#7919; li&#7879;u t&#259;ng l&#234;n</strong>, gi&#250;p l&#7853;p tr&#236;nh vi&#234;n l&#7921;a ch&#7885;n gi&#7843;i ph&#225;p t&#7889;i &#432;u tr&#432;&#7899;c khi tri&#7875;n khai.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HRJu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F869ee25a-9e59-477c-8767-1085a4648dfc_1280x720.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HRJu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F869ee25a-9e59-477c-8767-1085a4648dfc_1280x720.jpeg 424w, https://substackcdn.com/image/fetch/$s_!HRJu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F869ee25a-9e59-477c-8767-1085a4648dfc_1280x720.jpeg 848w, https://substackcdn.com/image/fetch/$s_!HRJu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F869ee25a-9e59-477c-8767-1085a4648dfc_1280x720.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!HRJu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F869ee25a-9e59-477c-8767-1085a4648dfc_1280x720.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HRJu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F869ee25a-9e59-477c-8767-1085a4648dfc_1280x720.jpeg" width="1280" height="720" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/869ee25a-9e59-477c-8767-1085a4648dfc_1280x720.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:720,&quot;width&quot;:1280,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;How to calculate Big O notation time complexity | Stackademic&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="How to calculate Big O notation time complexity | Stackademic" title="How to calculate Big O notation time complexity | Stackademic" srcset="https://substackcdn.com/image/fetch/$s_!HRJu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F869ee25a-9e59-477c-8767-1085a4648dfc_1280x720.jpeg 424w, https://substackcdn.com/image/fetch/$s_!HRJu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F869ee25a-9e59-477c-8767-1085a4648dfc_1280x720.jpeg 848w, https://substackcdn.com/image/fetch/$s_!HRJu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F869ee25a-9e59-477c-8767-1085a4648dfc_1280x720.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!HRJu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F869ee25a-9e59-477c-8767-1085a4648dfc_1280x720.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>BigO l&#224; g&#236;?</h1><p>BigO l&#224; <strong>k&#253; hi&#7879;u &#273;&#225;nh gi&#225; &#273;&#7897; ph&#7913;c t&#7841;p c&#7911;a thu&#7853;t to&#225;n ho&#7863;c h&#7879; th&#7889;ng</strong>, th&#432;&#7901;ng d&#249;ng &#273;&#7875; &#273;o:</p><ul><li><p><strong>Time complexity</strong>: th&#7901;i gian th&#7921;c hi&#7879;n theo s&#7889; l&#432;&#7907;ng d&#7919; li&#7879;u (n).</p></li><li><p><strong>Space / Capacity complexity</strong>: b&#7897; nh&#7899; hay dung l&#432;&#7907;ng c&#7847;n thi&#7871;t theo s&#7889; l&#432;&#7907;ng d&#7919; li&#7879;u.</p></li></ul><p>N&#243;i c&#225;ch kh&#225;c, BigO gi&#250;p ch&#250;ng ta <strong>&#432;&#7899;c l&#432;&#7907;ng tr&#432;&#7899;c c&#225;ch m&#7897;t thu&#7853;t to&#225;n ho&#7863;c h&#7879; th&#7889;ng &#8220;t&#7889;n&#8221; bao nhi&#234;u th&#7901;i gian v&#224; b&#7897; nh&#7899; khi d&#7919; li&#7879;u t&#259;ng l&#234;n</strong>.</p><h1>BigO v&#7873; th&#7901;i gian</h1><ul><li><p>Th&#7875; hi&#7879;n <strong>s&#7889; b&#432;&#7899;c c&#7847;n th&#7921;c hi&#7879;n</strong> khi d&#7919; li&#7879;u t&#259;ng.</p></li><li><p>V&#237; d&#7909; minh h&#7885;a:</p><ul><li><p><strong>O(1)</strong>: Truy c&#7853;p ph&#7847;n t&#7917; m&#7843;ng theo index. Th&#7901;i gian <strong>kh&#244;ng &#273;&#7893;i</strong>, b&#7845;t k&#7875; d&#7919; li&#7879;u l&#7899;n hay nh&#7887;.</p></li><li><p><strong>O(n)</strong>: Duy&#7879;t m&#7897;t m&#7843;ng d&#224;i n ph&#7847;n t&#7917;. Th&#7901;i gian <strong>t&#259;ng tuy&#7871;n t&#237;nh</strong> theo s&#7889; ph&#7847;n t&#7917;.</p></li><li><p><strong>O(log n)</strong>: T&#236;m ki&#7871;m nh&#7883; ph&#226;n trong m&#7843;ng s&#7855;p x&#7871;p. Th&#7901;i gian <strong>t&#259;ng ch&#7853;m</strong>, gi&#7843;m d&#7919; li&#7879;u &#273;i m&#7897;t n&#7917;a m&#7895;i b&#432;&#7899;c.</p></li><li><p><strong>O(n&#178;)</strong>: Duy&#7879;t 2 v&#242;ng l&#7891;ng nhau. Th&#7901;i gian <strong>t&#259;ng nhanh</strong>, d&#7919; li&#7879;u g&#7845;p &#273;&#244;i &#8594; th&#7901;i gian t&#259;ng g&#7845;p 4.</p></li></ul></li></ul><h1>BigO v&#7873; dung l&#432;&#7907;ng</h1><ul><li><p>&#272;o <strong>b&#7897; nh&#7899; c&#7847;n thi&#7871;t</strong> &#273;&#7875; l&#432;u d&#7919; li&#7879;u khi thu&#7853;t to&#225;n ch&#7841;y.</p></li><li><p>V&#237; d&#7909;:</p><ul><li><p>O(1): ch&#7881; c&#7847;n v&#224;i bi&#7871;n t&#7841;m, kh&#244;ng ph&#7909; thu&#7897;c d&#7919; li&#7879;u.</p></li><li><p>O(n): l&#432;u to&#224;n b&#7897; d&#7919; li&#7879;u trong b&#7897; nh&#7899; (nh&#432; copy m&#7897;t m&#7843;ng).</p></li><li><p>O(n&#178;): d&#249;ng ma tr&#7853;n k&#237;ch th&#432;&#7899;c n&#215;n.</p></li></ul></li></ul><h1>T&#7841;i sao quan tr&#7885;ng?</h1><ul><li><p><strong>&#272;&#225;nh gi&#225; hi&#7879;u n&#259;ng tr&#432;&#7899;c khi tri&#7875;n khai</strong>: tr&#225;nh thu&#7853;t to&#225;n ch&#7853;m khi d&#7919; li&#7879;u l&#7899;n.</p></li><li><p><strong>Quy&#7871;t &#273;&#7883;nh c&#225;ch l&#432;u tr&#7919; d&#7919; li&#7879;u</strong>: gi&#7843;m b&#7897; nh&#7899;, cache h&#7907;p l&#253;.</p></li><li><p><strong>So s&#225;nh thu&#7853;t to&#225;n</strong>: ch&#7885;n thu&#7853;t to&#225;n nhanh h&#417;n ho&#7863;c t&#7889;n &#237;t b&#7897; nh&#7899; h&#417;n.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[Proxy]]></title><description><![CDATA[Proxy &#273;&#243;ng vai tr&#242; nh&#432; trung gian th&#244;ng minh trong h&#7879; th&#7889;ng, gi&#250;p t&#259;ng t&#7889;c, b&#7843;o m&#7853;t, qu&#7843;n l&#253; v&#224; c&#226;n b&#7857;ng l&#432;u l&#432;&#7907;ng gi&#7919;a client v&#224; server]]></description><link>https://tiendatengineer.substack.com/p/proxy</link><guid isPermaLink="false">https://tiendatengineer.substack.com/p/proxy</guid><dc:creator><![CDATA[Nguyễn Doãn Tiến Đạt]]></dc:creator><pubDate>Fri, 12 Dec 2025 08:05:37 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/b083d5f3-b15f-4082-95d8-693a3e7141fb_800x419.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Khi l&#432;&#7899;t web, g&#7917;i email hay truy c&#7853;p d&#7883;ch v&#7909; tr&#7921;c tuy&#7871;n, b&#7841;n c&#243; bi&#7871;t d&#7919; li&#7879;u c&#7911;a b&#7841;n th&#432;&#7901;ng kh&#244;ng &#273;i th&#7859;ng t&#7915; m&#225;y t&#237;nh &#273;&#7871;n server? Thay v&#224;o &#273;&#243;, n&#243; th&#432;&#7901;ng &#273;i qua m&#7897;t &#8216;trung gian&#8217; g&#7885;i l&#224; <strong>proxy</strong>.</p><p>Proxy kh&#244;ng ch&#7881; gi&#250;p t&#259;ng t&#7889;c, b&#7843;o m&#7853;t v&#224; ki&#7875;m so&#225;t truy c&#7853;p, m&#224; c&#242;n c&#243; th&#7875; &#273;&#7841;i di&#7879;n cho b&#7841;n ho&#7863;c cho server &#273;&#7875; x&#7917; l&#253; c&#225;c y&#234;u c&#7847;u m&#7897;t c&#225;ch th&#244;ng minh.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!01nR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf15c909-0fa4-4d64-9853-e1f55bdd5273_1024x468.webp" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!01nR!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf15c909-0fa4-4d64-9853-e1f55bdd5273_1024x468.webp 424w, https://substackcdn.com/image/fetch/$s_!01nR!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf15c909-0fa4-4d64-9853-e1f55bdd5273_1024x468.webp 848w, https://substackcdn.com/image/fetch/$s_!01nR!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf15c909-0fa4-4d64-9853-e1f55bdd5273_1024x468.webp 1272w, https://substackcdn.com/image/fetch/$s_!01nR!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf15c909-0fa4-4d64-9853-e1f55bdd5273_1024x468.webp 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!01nR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf15c909-0fa4-4d64-9853-e1f55bdd5273_1024x468.webp" width="1024" height="468" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cf15c909-0fa4-4d64-9853-e1f55bdd5273_1024x468.webp&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:468,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Proxy l&#224; g&#236;? T&#237;nh n&#259;ng, l&#7907;i &#237;ch v&#224; c&#225;ch c&#224;i &#273;&#7863;t tr&#234;n Chrome mi&#7877;n ph&#237;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Proxy l&#224; g&#236;? T&#237;nh n&#259;ng, l&#7907;i &#237;ch v&#224; c&#225;ch c&#224;i &#273;&#7863;t tr&#234;n Chrome mi&#7877;n ph&#237;" title="Proxy l&#224; g&#236;? T&#237;nh n&#259;ng, l&#7907;i &#237;ch v&#224; c&#225;ch c&#224;i &#273;&#7863;t tr&#234;n Chrome mi&#7877;n ph&#237;" srcset="https://substackcdn.com/image/fetch/$s_!01nR!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf15c909-0fa4-4d64-9853-e1f55bdd5273_1024x468.webp 424w, https://substackcdn.com/image/fetch/$s_!01nR!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf15c909-0fa4-4d64-9853-e1f55bdd5273_1024x468.webp 848w, https://substackcdn.com/image/fetch/$s_!01nR!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf15c909-0fa4-4d64-9853-e1f55bdd5273_1024x468.webp 1272w, https://substackcdn.com/image/fetch/$s_!01nR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf15c909-0fa4-4d64-9853-e1f55bdd5273_1024x468.webp 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Proxy l&#224; g&#236;?</h1><p>Proxy l&#224; m&#7897;t <strong>m&#225;y ch&#7911; trung gian</strong> &#273;&#7913;ng gi&#7919;a client v&#224; server, gi&#250;p <strong>chuy&#7875;n ti&#7871;p y&#234;u c&#7847;u v&#224; ph&#7843;n h&#7891;i</strong>, &#273;&#7891;ng th&#7901;i cung c&#7845;p c&#225;c t&#237;nh n&#259;ng nh&#432; <strong>b&#7843;o m&#7853;t, cache, load balancing</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!tOaE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F103afab6-24e9-46aa-b713-1beb8bc1c298_825x334.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!tOaE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F103afab6-24e9-46aa-b713-1beb8bc1c298_825x334.png 424w, https://substackcdn.com/image/fetch/$s_!tOaE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F103afab6-24e9-46aa-b713-1beb8bc1c298_825x334.png 848w, https://substackcdn.com/image/fetch/$s_!tOaE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F103afab6-24e9-46aa-b713-1beb8bc1c298_825x334.png 1272w, https://substackcdn.com/image/fetch/$s_!tOaE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F103afab6-24e9-46aa-b713-1beb8bc1c298_825x334.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!tOaE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F103afab6-24e9-46aa-b713-1beb8bc1c298_825x334.png" width="825" height="334" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/103afab6-24e9-46aa-b713-1beb8bc1c298_825x334.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:334,&quot;width&quot;:825,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;T&#7893;ng quan v&#7873; Proxy, Reverse Proxy vs. Forward Proxy, Forward Port, Load  Balancer&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="T&#7893;ng quan v&#7873; Proxy, Reverse Proxy vs. Forward Proxy, Forward Port, Load  Balancer" title="T&#7893;ng quan v&#7873; Proxy, Reverse Proxy vs. Forward Proxy, Forward Port, Load  Balancer" srcset="https://substackcdn.com/image/fetch/$s_!tOaE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F103afab6-24e9-46aa-b713-1beb8bc1c298_825x334.png 424w, https://substackcdn.com/image/fetch/$s_!tOaE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F103afab6-24e9-46aa-b713-1beb8bc1c298_825x334.png 848w, https://substackcdn.com/image/fetch/$s_!tOaE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F103afab6-24e9-46aa-b713-1beb8bc1c298_825x334.png 1272w, https://substackcdn.com/image/fetch/$s_!tOaE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F103afab6-24e9-46aa-b713-1beb8bc1c298_825x334.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Forward Proxy</h1><h2>&#272;&#7883;nh ngh&#297;a</h2><p>Forward Proxy l&#224; <strong>proxy &#273;&#7841;i di&#7879;n cho client</strong> khi truy c&#7853;p server b&#234;n ngo&#224;i. Client g&#7917;i request t&#7899;i proxy, proxy th&#7921;c hi&#7879;n request thay client v&#224; tr&#7843; k&#7871;t qu&#7843; v&#7873;.</p><h2>Vai tr&#242;</h2><ul><li><p><strong>&#7848;n danh client</strong>: server b&#234;n ngo&#224;i kh&#244;ng bi&#7871;t ai g&#7917;i request.</p></li><li><p><strong>Ch&#7863;n / ki&#7875;m so&#225;t truy c&#7853;p</strong>: qu&#7843;n l&#253; website m&#224; ng&#432;&#7901;i d&#249;ng c&#243; th&#7875; truy c&#7853;p.</p></li><li><p><strong>Cache d&#7919; li&#7879;u</strong>: gi&#7843;m b&#259;ng th&#244;ng, t&#259;ng t&#7889;c &#273;&#7897; truy c&#7853;p.</p></li></ul><h2>V&#237; d&#7909; minh h&#7885;a</h2><ul><li><p>C&#244;ng ty mu&#7889;n nh&#226;n vi&#234;n ch&#7881; truy c&#7853;p &#273;&#432;&#7907;c m&#7897;t s&#7889; website, t&#7845;t c&#7843; request &#273;i qua forward proxy &#273;&#7875; <strong>l&#7885;c n&#7897;i dung</strong>.</p></li><li><p>Ng&#432;&#7901;i d&#249;ng mu&#7889;n <strong>&#7849;n IP khi truy c&#7853;p internet</strong> d&#249;ng forward proxy &#273;&#7875; gi&#7845;u &#273;&#7883;a ch&#7881; th&#7853;t.</p></li></ul><h2>Use cases</h2><p><strong>&#7848;n danh khi truy c&#7853;p Internet</strong></p><ul><li><p>Forward proxy gi&#250;p client <strong>gi&#7845;u IP th&#7853;t</strong> khi truy c&#7853;p website ho&#7863;c d&#7883;ch v&#7909; b&#234;n ngo&#224;i.</p></li><li><p>V&#237; d&#7909;: ng&#432;&#7901;i d&#249;ng c&#225; nh&#226;n mu&#7889;n truy c&#7853;p c&#225;c trang web qu&#7889;c t&#7871; m&#224; kh&#244;ng &#273;&#7875; l&#7897; &#273;&#7883;a ch&#7881; IP th&#7853;t.</p></li></ul><p><strong>Ki&#7875;m so&#225;t v&#224; l&#7885;c truy c&#7853;p</strong></p><ul><li><p>C&#244;ng ty ho&#7863;c tr&#432;&#7901;ng h&#7885;c d&#249;ng forward proxy &#273;&#7875; <strong>qu&#7843;n l&#253; website m&#224; nh&#226;n vi&#234;n ho&#7863;c h&#7885;c sinh c&#243; th&#7875; truy c&#7853;p</strong>.</p></li><li><p>C&#243; th&#7875; ch&#7863;n c&#225;c trang web kh&#244;ng ph&#249; h&#7907;p ho&#7863;c gi&#7899;i h&#7841;n b&#259;ng th&#244;ng.</p></li></ul><p><strong>Cache d&#7919; li&#7879;u</strong></p><ul><li><p>Forward proxy c&#243; th&#7875; <strong>l&#432;u t&#7841;m d&#7919; li&#7879;u &#273;&#227; truy c&#7853;p</strong>, gi&#7843;m b&#259;ng th&#244;ng v&#224; t&#259;ng t&#7889;c &#273;&#7897; cho c&#225;c l&#7847;n truy c&#7853;p ti&#7871;p theo.</p></li><li><p>V&#237; d&#7909;: m&#7897;t trang web ph&#7893; bi&#7871;n &#273;&#432;&#7907;c nhi&#7873;u ng&#432;&#7901;i trong c&#244;ng ty truy c&#7853;p, d&#7919; li&#7879;u &#273;&#432;&#7907;c cache tr&#234;n proxy &#273;&#7875; load nhanh h&#417;n.</p></li></ul><p><strong>Bypass gi&#7899;i h&#7841;n &#273;&#7883;a l&#253;</strong></p><ul><li><p>Ng&#432;&#7901;i d&#249;ng mu&#7889;n truy c&#7853;p n&#7897;i dung b&#7883; h&#7841;n ch&#7871; theo v&#7883; tr&#237; &#273;&#7883;a l&#253; c&#243; th&#7875; d&#249;ng forward proxy &#273;&#7875; <strong>gi&#7843; l&#7853;p IP t&#7915; qu&#7889;c gia kh&#225;c</strong>.</p></li></ul><p><strong>Ghi l&#7841;i v&#224; gi&#225;m s&#225;t l&#432;u l&#432;&#7907;ng</strong></p><ul><li><p>Forward proxy gi&#250;p <strong>theo d&#245;i ho&#7841;t &#273;&#7897;ng Internet c&#7911;a ng&#432;&#7901;i d&#249;ng</strong> &#273;&#7875; ph&#226;n t&#237;ch, b&#225;o c&#225;o ho&#7863;c &#273;&#7843;m b&#7843;o tu&#226;n th&#7911; ch&#237;nh s&#225;ch c&#244;ng ty.</p></li></ul><div><hr></div><h1>Reverse Proxy</h1><h2>&#272;&#7883;nh ngh&#297;a</h2><p>Reverse Proxy l&#224; <strong>proxy &#273;&#7841;i di&#7879;n cho server</strong> khi nh&#7853;n request t&#7915; client. Client kh&#244;ng bi&#7871;t server th&#7853;t n&#7857;m &#7903; &#273;&#226;u, ch&#7881; g&#7917;i request t&#7899;i reverse proxy, proxy chuy&#7875;n ti&#7871;p t&#7899;i server th&#7921;c v&#224; tr&#7843; k&#7871;t qu&#7843; v&#7873; client.</p><h2>Vai tr&#242;</h2><ul><li><p><strong>Load balancing</strong>: ph&#226;n ph&#7889;i request t&#7899;i nhi&#7873;u server &#273;&#7875; tr&#225;nh qu&#225; t&#7843;i.</p></li><li><p><strong>B&#7843;o m&#7853;t</strong>: &#7849;n server th&#7853;t, ch&#7863;n c&#225;c truy c&#7853;p &#273;&#7897;c h&#7841;i.</p></li><li><p><strong>TLS/SSL termination</strong>: x&#7917; l&#253; m&#227; h&#243;a &#273;&#7875; gi&#7843;m t&#7843;i cho server backend.</p></li><li><p><strong>Cache t&#297;nh</strong>: gi&#7843;m t&#7843;i server backend, t&#259;ng t&#7889;c &#273;&#7897; ph&#7843;n h&#7891;i.</p></li></ul><h2>V&#237; d&#7909; minh h&#7885;a</h2><ul><li><p>Website l&#7899;n c&#243; nhi&#7873;u server backend, d&#249;ng reverse proxy nh&#432; <strong>Nginx ho&#7863;c HAProxy</strong> &#273;&#7875; ph&#226;n ph&#7889;i request v&#224; t&#259;ng hi&#7879;u n&#259;ng.</p></li><li><p>Cloudflare ho&#7841;t &#273;&#7897;ng nh&#432; reverse proxy, b&#7843;o v&#7879; server kh&#7887;i c&#225;c t&#7845;n c&#244;ng DDoS v&#224; cache n&#7897;i dung t&#297;nh.</p></li></ul><h2>Use cases</h2><p><strong>Load balancing (C&#226;n b&#7857;ng t&#7843;i)</strong></p><ul><li><p>Reverse proxy ph&#226;n ph&#7889;i request t&#7915; client t&#7899;i nhi&#7873;u server backend &#273;&#7875; <strong>tr&#225;nh qu&#225; t&#7843;i</strong>, t&#259;ng hi&#7879;u n&#259;ng v&#224; kh&#7843; n&#259;ng ch&#7883;u l&#7895;i.</p></li><li><p>V&#237; d&#7909;: website l&#7899;n c&#243; h&#224;ng ch&#7909;c server, Nginx ho&#7863;c HAProxy l&#224;m reverse proxy &#273;&#7875; ph&#226;n ph&#7889;i &#273;&#7873;u request.</p></li></ul><p><strong>B&#7843;o m&#7853;t v&#224; &#7849;n server th&#7853;t</strong></p><ul><li><p>Reverse proxy gi&#250;p <strong>gi&#7845;u IP v&#224; th&#244;ng tin c&#7911;a server backend</strong>, b&#7843;o v&#7879; kh&#7887;i c&#225;c t&#7845;n c&#244;ng tr&#7921;c ti&#7871;p (DDoS, probing).</p></li><li><p>V&#237; d&#7909;: Cloudflare ho&#7841;t &#273;&#7897;ng nh&#432; reverse proxy, l&#7885;c c&#225;c request &#273;&#7897;c h&#7841;i tr&#432;&#7899;c khi t&#7899;i server th&#7853;t.</p></li></ul><p><strong>TLS/SSL Termination</strong></p><ul><li><p>Reverse proxy c&#243; th&#7875; <strong>x&#7917; l&#253; m&#227; h&#243;a SSL/TLS</strong>, gi&#7843;m t&#7843;i cho server backend.</p></li><li><p>V&#237; d&#7909;: Nginx nh&#7853;n request HTTPS, gi&#7843;i m&#227; v&#224; chuy&#7875;n ti&#7871;p request n&#7897;i b&#7897; qua HTTP.</p></li></ul><p><strong>Caching n&#7897;i dung t&#297;nh</strong></p><ul><li><p>Reverse proxy c&#243; th&#7875; <strong>l&#432;u t&#7841;m c&#225;c file t&#297;nh</strong> nh&#432; &#7843;nh, CSS, JS, gi&#250;p gi&#7843;m t&#7843;i cho server backend v&#224; t&#259;ng t&#7889;c &#273;&#7897; ph&#7843;n h&#7891;i.</p></li><li><p>V&#237; d&#7909;: Nginx cache trang web ph&#7893; bi&#7871;n, kh&#225;ch truy c&#7853;p l&#7845;y n&#7897;i dung tr&#7921;c ti&#7871;p t&#7915; proxy.</p></li></ul><p><strong>Compression / Optimization</strong></p><ul><li><p>Reverse proxy c&#243; th&#7875; <strong>n&#233;n d&#7919; li&#7879;u, t&#7889;i &#432;u h&#243;a h&#236;nh &#7843;nh</strong> tr&#432;&#7899;c khi g&#7917;i t&#7899;i client, gi&#250;p ti&#7871;t ki&#7879;m b&#259;ng th&#244;ng.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[Message queue]]></title><description><![CDATA[Message Queue &#273;&#243;ng vai tr&#242; nh&#432; trung gian x&#7871;p h&#224;ng c&#225;c tin nh&#7855;n gi&#7919;a c&#225;c service, gi&#250;p h&#7879; th&#7889;ng giao ti&#7871;p b&#7845;t &#273;&#7891;ng b&#7897;, gi&#7843;m t&#7843;i v&#224; t&#259;ng &#273;&#7897; tin c&#7853;y]]></description><link>https://tiendatengineer.substack.com/p/message-queue</link><guid isPermaLink="false">https://tiendatengineer.substack.com/p/message-queue</guid><dc:creator><![CDATA[Nguyễn Doãn Tiến Đạt]]></dc:creator><pubDate>Fri, 12 Dec 2025 07:47:12 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!RYfk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59744b23-132c-4e48-8916-b528f6170d9c_820x640.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Trong c&#225;c &#7913;ng d&#7909;ng hi&#7879;n &#273;&#7841;i, <strong>h&#224;ng tri&#7879;u y&#234;u c&#7847;u</strong> v&#224; <strong>d&#7919; li&#7879;u li&#234;n t&#7909;c ch&#7843;y</strong> gi&#7919;a c&#225;c d&#7883;ch v&#7909;. V&#7853;y l&#224;m th&#7871; n&#224;o &#273;&#7875; <strong>h&#7879; th&#7889;ng kh&#244;ng b&#7883; ngh&#7869;n</strong>, v&#224; <strong>c&#225;c service c&#243; th&#7875; giao ti&#7871;p m&#7897;t c&#225;ch m&#432;&#7907;t m&#224;</strong> m&#224; kh&#244;ng ph&#7843;i ch&#7901; nhau?</p><p>C&#226;u tr&#7843; l&#7901;i th&#432;&#7901;ng n&#7857;m &#7903; m&#7897;t th&#224;nh ph&#7847;n t&#432;&#7903;ng ch&#7915;ng &#273;&#417;n gi&#7843;n nh&#432;ng c&#7921;c k&#7923; quan tr&#7885;ng: <strong>Message Queue</strong> &#8211; n&#417;i c&#225;c <strong>tin nh&#7855;n &#273;&#432;&#7907;c x&#7871;p h&#224;ng ch&#7901; x&#7917; l&#253;</strong>, gi&#250;p c&#225;c &#7913;ng d&#7909;ng ho&#7841;t &#273;&#7897;ng tr&#417;n tru v&#224; &#273;&#225;ng tin c&#7853;y h&#417;n.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RYfk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59744b23-132c-4e48-8916-b528f6170d9c_820x640.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RYfk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59744b23-132c-4e48-8916-b528f6170d9c_820x640.png 424w, https://substackcdn.com/image/fetch/$s_!RYfk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59744b23-132c-4e48-8916-b528f6170d9c_820x640.png 848w, https://substackcdn.com/image/fetch/$s_!RYfk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59744b23-132c-4e48-8916-b528f6170d9c_820x640.png 1272w, https://substackcdn.com/image/fetch/$s_!RYfk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59744b23-132c-4e48-8916-b528f6170d9c_820x640.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RYfk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59744b23-132c-4e48-8916-b528f6170d9c_820x640.png" width="820" height="640" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/59744b23-132c-4e48-8916-b528f6170d9c_820x640.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:640,&quot;width&quot;:820,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Microservice - T&#7841;i sao l&#7841;i s&#7917; d&#7909;ng Message queue?&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Microservice - T&#7841;i sao l&#7841;i s&#7917; d&#7909;ng Message queue?" title="Microservice - T&#7841;i sao l&#7841;i s&#7917; d&#7909;ng Message queue?" srcset="https://substackcdn.com/image/fetch/$s_!RYfk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59744b23-132c-4e48-8916-b528f6170d9c_820x640.png 424w, https://substackcdn.com/image/fetch/$s_!RYfk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59744b23-132c-4e48-8916-b528f6170d9c_820x640.png 848w, https://substackcdn.com/image/fetch/$s_!RYfk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59744b23-132c-4e48-8916-b528f6170d9c_820x640.png 1272w, https://substackcdn.com/image/fetch/$s_!RYfk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F59744b23-132c-4e48-8916-b528f6170d9c_820x640.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Message Queue l&#224; g&#236;?</h1><p>Message Queue l&#224; m&#7897;t <strong>h&#7879; th&#7889;ng trung gian</strong> cho ph&#233;p <strong>g&#7917;i v&#224; nh&#7853;n d&#7919; li&#7879;u (message) gi&#7919;a c&#225;c &#7913;ng d&#7909;ng ho&#7863;c d&#7883;ch v&#7909; m&#7897;t c&#225;ch b&#7845;t &#273;&#7891;ng b&#7897;</strong>.</p><blockquote><p>N&#7871;u c&#225;c service l&#224; ng&#432;&#7901;i, message queue l&#224; <strong>b&#432;u &#273;i&#7879;n</strong>, n&#417;i g&#7917;i th&#432; &#273;&#7875; ng&#432;&#7901;i nh&#7853;n &#273;&#7885;c khi r&#7843;nh, thay v&#236; ph&#7843;i g&#7863;p tr&#7921;c ti&#7871;p v&#224; trao &#273;&#7893;i ngay l&#7853;p t&#7913;c.</p></blockquote><h1>T&#7841;i sao c&#7847;n Message Queue?</h1><p>Trong c&#225;c h&#7879; th&#7889;ng hi&#7879;n &#273;&#7841;i, nhi&#7873;u service c&#7847;n <strong>trao &#273;&#7893;i d&#7919; li&#7879;u li&#234;n t&#7909;c</strong>:</p><ul><li><p>N&#7871;u g&#7885;i tr&#7921;c ti&#7871;p (synchronous), service A ph&#7843;i ch&#7901; service B tr&#7843; l&#7901;i &#8594; ch&#7853;m, d&#7877; b&#7883; ngh&#7869;n.</p></li><li><p>MQ cho ph&#233;p <strong>g&#7917;i message v&#224; ti&#7871;p t&#7909;c l&#224;m vi&#7879;c</strong>, service nh&#7853;n c&#243; th&#7875; x&#7917; l&#253; khi r&#7843;nh.</p></li></ul><p>C&#225;c v&#7845;n &#273;&#7873; MQ gi&#7843;i quy&#7871;t:</p><ul><li><p><strong>Gi&#7843;m t&#7843;i cho h&#7879; th&#7889;ng</strong>: kh&#244;ng b&#7883; &#8220;ngh&#7869;n&#8221; khi nhi&#7873;u y&#234;u c&#7847;u c&#249;ng l&#250;c.</p></li><li><p><strong>T&#259;ng &#273;&#7897; tin c&#7853;y</strong>: message &#273;&#432;&#7907;c l&#432;u l&#7841;i, n&#7871;u service nh&#7853;n t&#7841;m th&#7901;i down v&#7851;n c&#243; th&#7875; x&#7917; l&#253; sau.</p></li><li><p><strong>T&#225;ch r&#7901;i c&#225;c service</strong>: A kh&#244;ng c&#7847;n bi&#7871;t B x&#7917; l&#253; ra sao, ch&#7881; c&#7847;n g&#7917;i message.</p></li></ul><h1>C&#225;ch ho&#7841;t &#273;&#7897;ng c&#417; b&#7843;n</h1><ol><li><p><strong>Producer (ng&#432;&#7901;i g&#7917;i)</strong>: G&#7917;i message v&#224;o queue.</p></li><li><p><strong>Queue (h&#224;ng &#273;&#7907;i)</strong>: Gi&#7919; message theo th&#7913; t&#7921;, &#273;&#7907;i consumer x&#7917; l&#253;.</p></li><li><p><strong>Consumer (ng&#432;&#7901;i nh&#7853;n)</strong>: L&#7845;y message t&#7915; queue v&#224; x&#7917; l&#253;.</p></li></ol><p><strong>V&#237; d&#7909;:</strong></p><p>M&#7897;t website &#273;&#7863;t h&#224;ng:</p><ul><li><p>Producer: service x&#7917; l&#253; &#273;&#417;n h&#224;ng g&#7917;i message &#8220;&#273;&#417;n h&#224;ng m&#7899;i&#8221;.</p></li><li><p>Queue: gi&#7919; &#273;&#417;n h&#224;ng ch&#7901; x&#7917; l&#253;.</p></li><li><p>Consumer: service kho nh&#7853;n message, c&#7853;p nh&#7853;t t&#7891;n kho, g&#7917;i email x&#225;c nh&#7853;n.</p></li></ul><h1>C&#225;c lo&#7841;i Message Queue ph&#7893; bi&#7871;n</h1><ul><li><p><strong>RabbitMQ</strong>: H&#7895; tr&#7907; nhi&#7873;u ki&#7875;u routing, queue b&#7873;n v&#7919;ng.</p></li><li><p><strong>Kafka</strong>: Th&#432;&#7901;ng d&#249;ng cho streaming, x&#7917; l&#253; l&#432;&#7907;ng l&#7899;n message, h&#7895; tr&#7907; replay message.</p></li><li><p><strong>SQS (AWS)</strong>: MQ tr&#234;n cloud, &#273;&#417;n gi&#7843;n, d&#7877; scale.</p></li></ul><h1>L&#7907;i &#237;ch c&#7911;a Message Queue</h1><ul><li><p><strong>B&#7845;t &#273;&#7891;ng b&#7897;</strong>: Producer kh&#244;ng c&#7847;n ch&#7901; Consumer.</p></li><li><p><strong>T&#259;ng kh&#7843; n&#259;ng ch&#7883;u l&#7895;i</strong>: Message &#273;&#432;&#7907;c l&#432;u l&#7841;i n&#7871;u Consumer g&#7863;p s&#7921; c&#7889;.</p></li><li><p><strong>D&#7877; m&#7903; r&#7897;ng</strong>: Th&#234;m Consumer &#273;&#7875; t&#259;ng throughput.</p></li><li><p><strong>T&#225;ch r&#7901;i h&#7879; th&#7889;ng</strong>: Service kh&#244;ng ph&#7909; thu&#7897;c tr&#7921;c ti&#7871;p v&#224;o nhau.</p></li></ul><p></p>]]></content:encoded></item><item><title><![CDATA[Bộ nhớ đệm (caching)]]></title><description><![CDATA[Cache &#273;&#243;ng vai tr&#242; nh&#432; b&#7843;n sao nhanh c&#7911;a d&#7919; li&#7879;u, gi&#250;p h&#7879; th&#7889;ng truy xu&#7845;t th&#244;ng tin nhanh ch&#243;ng, gi&#7843;m t&#7843;i cho database, v&#224; c&#7843;i thi&#7879;n t&#7889;c &#273;&#7897; ph&#7843;n h&#7891;i c&#361;ng nh&#432; tr&#7843;i nghi&#7879;m ng&#432;&#7901;i d&#249;ng]]></description><link>https://tiendatengineer.substack.com/p/bo-nho-em-caching</link><guid isPermaLink="false">https://tiendatengineer.substack.com/p/bo-nho-em-caching</guid><dc:creator><![CDATA[Nguyễn Doãn Tiến Đạt]]></dc:creator><pubDate>Fri, 12 Dec 2025 07:23:56 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/8a952f25-6af3-4624-ad8a-471958426094_1804x1494.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>B&#7841;n c&#243; bao gi&#7901; th&#7855;c m&#7855;c t&#7841;i sao m&#7897;t s&#7889; trang web t&#7843;i c&#7921;c nhanh, trong khi nh&#7919;ng trang kh&#225;c th&#236; ch&#7853;m &#273;&#7871;n m&#7913;c ph&#7843;i ch&#7901;? Hay t&#7841;i sao m&#7897;t s&#7889; &#7913;ng d&#7909;ng ph&#7843;n h&#7891;i ngay l&#7853;p t&#7913;c khi d&#7919; li&#7879;u v&#7915;a &#273;&#432;&#7907;c c&#7853;p nh&#7853;t? B&#237; m&#7853;t th&#432;&#7901;ng n&#7857;m &#7903; m&#7897;t k&#7929; thu&#7853;t t&#432;&#7903;ng ch&#7915;ng &#273;&#417;n gi&#7843;n nh&#432;ng v&#244; c&#249;ng m&#7841;nh m&#7869;: <strong>caching</strong>.</p><p>Nh&#432;ng caching kh&#244;ng ph&#7843;i l&#250;c n&#224;o c&#361;ng &#273;&#417;n gi&#7843;n&#8212;n&#243; &#273;&#7863;t ra c&#226;u h&#7887;i v&#7873; <strong>d&#7919; li&#7879;u lu&#244;n t&#432;&#417;i m&#7899;i</strong>, <strong>l&#224;m th&#7871; n&#224;o &#273;&#7875; kh&#244;ng t&#7843;i l&#7841;i database m&#7895;i l&#7847;n</strong>, v&#224; <strong>c&#225;ch c&#226;n b&#7857;ng gi&#7919;a t&#7889;c &#273;&#7897; v&#224; &#273;&#7897; ch&#237;nh x&#225;c c&#7911;a th&#244;ng tin</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4iQK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ea36ecf-f506-4f38-8031-1e290add3fb5_850x446.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4iQK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ea36ecf-f506-4f38-8031-1e290add3fb5_850x446.png 424w, https://substackcdn.com/image/fetch/$s_!4iQK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ea36ecf-f506-4f38-8031-1e290add3fb5_850x446.png 848w, https://substackcdn.com/image/fetch/$s_!4iQK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ea36ecf-f506-4f38-8031-1e290add3fb5_850x446.png 1272w, https://substackcdn.com/image/fetch/$s_!4iQK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ea36ecf-f506-4f38-8031-1e290add3fb5_850x446.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4iQK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ea36ecf-f506-4f38-8031-1e290add3fb5_850x446.png" width="850" height="446" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0ea36ecf-f506-4f38-8031-1e290add3fb5_850x446.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:446,&quot;width&quot;:850,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;What is Database Caching? Definition &amp; FAQs | ScyllaDB&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="What is Database Caching? Definition &amp; FAQs | ScyllaDB" title="What is Database Caching? Definition &amp; FAQs | ScyllaDB" srcset="https://substackcdn.com/image/fetch/$s_!4iQK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ea36ecf-f506-4f38-8031-1e290add3fb5_850x446.png 424w, https://substackcdn.com/image/fetch/$s_!4iQK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ea36ecf-f506-4f38-8031-1e290add3fb5_850x446.png 848w, https://substackcdn.com/image/fetch/$s_!4iQK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ea36ecf-f506-4f38-8031-1e290add3fb5_850x446.png 1272w, https://substackcdn.com/image/fetch/$s_!4iQK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ea36ecf-f506-4f38-8031-1e290add3fb5_850x446.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Caching l&#224; g&#236;?</h1><p>Caching l&#224; <strong>k&#7929; thu&#7853;t l&#432;u tr&#7919; t&#7841;m th&#7901;i d&#7919; li&#7879;u ho&#7863;c k&#7871;t qu&#7843; t&#237;nh to&#225;n</strong> &#7903; n&#417;i d&#7877; truy c&#7853;p h&#417;n, &#273;&#7875; <strong>truy xu&#7845;t nhanh h&#417;n</strong> khi c&#7847;n d&#249;ng l&#7841;i.</p><blockquote><p>Thay v&#236; &#273;i t&#236;m d&#7919; li&#7879;u t&#7915; ngu&#7891;n g&#7889;c m&#7895;i l&#7847;n, h&#7879; th&#7889;ng l&#7845;y tr&#7921;c ti&#7871;p t&#7915; &#8220;b&#7843;n sao nhanh&#8221; trong cache.</p></blockquote><h1>T&#7841;i sao c&#7847;n caching?</h1><ul><li><p>Gi&#7843;m th&#7901;i gian truy xu&#7845;t d&#7919; li&#7879;u &#8594; &#7913;ng d&#7909;ng ph&#7843;n h&#7891;i nhanh h&#417;n.</p></li><li><p>Gi&#7843;m t&#7843;i cho <strong>database ho&#7863;c h&#7879; th&#7889;ng backend</strong>, &#273;&#7863;c bi&#7879;t khi c&#243; nhi&#7873;u ng&#432;&#7901;i d&#249;ng c&#249;ng truy c&#7853;p d&#7919; li&#7879;u gi&#7889;ng nhau.</p></li><li><p>Gi&#250;p c&#7843;i thi&#7879;n tr&#7843;i nghi&#7879;m ng&#432;&#7901;i d&#249;ng, &#273;&#7863;c bi&#7879;t v&#7899;i d&#7919; li&#7879;u &#273;&#7885;c nhi&#7873;u, thay &#273;&#7893;i &#237;t.</p></li></ul><h1>C&#225;c lo&#7841;i caching ph&#7893; bi&#7871;n</h1><ol><li><p><strong>In-memory cache</strong>: L&#432;u trong b&#7897; nh&#7899; RAM c&#7911;a server, truy xu&#7845;t c&#7921;c nhanh.</p><ul><li><p>V&#237; d&#7909;: Redis, Memcached</p></li></ul></li><li><p><strong>Browser cache</strong>: Tr&#236;nh duy&#7879;t l&#432;u file t&#297;nh (CSS, JS, h&#236;nh &#7843;nh) &#273;&#7875; kh&#244;ng ph&#7843;i t&#7843;i l&#7841;i t&#7915; server.</p></li><li><p><strong>CDN cache</strong>: L&#432;u b&#7843;n sao d&#7919; li&#7879;u t&#297;nh &#7903; nhi&#7873;u &#273;&#7883;a &#273;i&#7875;m g&#7847;n ng&#432;&#7901;i d&#249;ng, gi&#7843;m &#273;&#7897; tr&#7877;.</p></li></ol><h1>V&#237; d&#7909; minh h&#7885;a</h1><ul><li><p>M&#7897;t trang web hi&#7875;n th&#7883; b&#7843;ng gi&#225; s&#7843;n ph&#7849;m t&#7915; database. Thay v&#236; truy v&#7845;n database m&#7895;i l&#7847;n ng&#432;&#7901;i d&#249;ng m&#7903; trang, h&#7879; th&#7889;ng <strong>l&#432;u k&#7871;t qu&#7843; truy v&#7845;n trong cache</strong> 5 ph&#250;t.</p></li><li><p>Khi ng&#432;&#7901;i d&#249;ng kh&#225;c m&#7903; trang trong 5 ph&#250;t &#273;&#243;, d&#7919; li&#7879;u &#273;&#432;&#7907;c l&#7845;y tr&#7921;c ti&#7871;p t&#7915; cache &#8594; ph&#7843;n h&#7891;i ngay l&#7853;p t&#7913;c, gi&#7843;m t&#7843;i database.</p></li></ul><div><hr></div><h1>L&#432;u &#253; khi d&#249;ng cache</h1><ul><li><p><strong>D&#7919; li&#7879;u thay &#273;&#7893;i</strong> &#8594; c&#7847;n c&#417; ch&#7871; <strong>h&#7871;t h&#7841;n (TTL)</strong> ho&#7863;c <strong>invalidate cache</strong>.</p></li><li><p>Kh&#244;ng ph&#7843;i d&#7919; li&#7879;u n&#224;o c&#361;ng n&#234;n cache, &#273;&#7863;c bi&#7879;t d&#7919; li&#7879;u c&#7921;c k&#7923; nh&#7841;y c&#7843;m ho&#7863;c thay &#273;&#7893;i li&#234;n t&#7909;c.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[Cơ sở dữ liệu (database)]]></title><description><![CDATA[Database l&#224; tr&#225;i tim c&#7911;a m&#7885;i &#7913;ng d&#7909;ng, n&#417;i d&#7919; li&#7879;u &#273;&#432;&#7907;c l&#432;u tr&#7919;, qu&#7843;n l&#253; v&#224; truy xu&#7845;t m&#7897;t c&#225;ch c&#243; c&#7845;u tr&#250;c, gi&#250;p doanh nghi&#7879;p v&#224; ng&#432;&#7901;i d&#249;ng &#273;&#432;a ra quy&#7871;t &#273;&#7883;nh nhanh ch&#243;ng v&#224; ch&#237;nh x&#225;c]]></description><link>https://tiendatengineer.substack.com/p/co-so-du-lieu-database</link><guid isPermaLink="false">https://tiendatengineer.substack.com/p/co-so-du-lieu-database</guid><dc:creator><![CDATA[Nguyễn Doãn Tiến Đạt]]></dc:creator><pubDate>Fri, 12 Dec 2025 07:02:53 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!3Es9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81088b7-a188-4089-845a-63936e930a71_1632x1076.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote><p>C&#417; s&#7903; d&#7919; li&#7879;u (Database) l&#224; n&#7873;n m&#243;ng c&#7911;a m&#7885;i h&#7879; th&#7889;ng ph&#7847;n m&#7873;m. Nh&#432;ng &#8220;database&#8221; kh&#244;ng ch&#7881; l&#224; MySQL hay MongoDB &#8212; m&#224; l&#224; <strong>m&#7897;t h&#7879; sinh th&#225;i l&#7899;n</strong>, v&#7899;i nhi&#7873;u lo&#7841;i ki&#7871;n tr&#250;c kh&#225;c nhau, t&#7889;i &#432;u cho nh&#7919;ng nhu c&#7847;u kh&#225;c nhau.</p></blockquote><h1>Database d&#249;ng &#273;&#7875; l&#224;m g&#236;?</h1><ul><li><p>L&#432;u tr&#7919; d&#7919; li&#7879;u c&#243; c&#7845;u tr&#250;c ho&#7863;c kh&#244;ng c&#7845;u tr&#250;c.</p></li><li><p>Cho ph&#233;p truy v&#7845;n nhanh v&#224; &#273;&#225;ng tin c&#7853;y.</p></li><li><p>&#272;&#7843;m b&#7843;o d&#7919; li&#7879;u kh&#244;ng m&#7845;t khi t&#7855;t m&#225;y.</p></li></ul><p>&#8594; <strong>N&#243; l&#224; b&#7897; nh&#7899; d&#224;i h&#7841;n c&#7911;a h&#7879; th&#7889;ng</strong>, kh&#225;c v&#7899;i RAM.</p><h1>Ph&#226;n lo&#7841;i</h1><p>C&#243; 2 c&#225;ch ph&#226;n lo&#7841;i ch&#237;nh: v&#7873; <strong>c&#7845;u tr&#250;c t&#7893; ch&#7913;c m&#244; h&#236;nh d&#7919; li&#7879;u</strong> v&#224; v&#7873; <strong>t&#225;c v&#7909; h&#7879; th&#7889;ng ph&#7843;i x&#7917; l&#253;</strong>.</p><h2>SQL v&#224; NoSQL</h2><blockquote><p>&#272;&#226;y l&#224; c&#225;ch ph&#226;n lo&#7841;i d&#7921;a tr&#234;n <strong>c&#7845;u tr&#250;c d&#7919; li&#7879;u</strong> v&#224; <strong>c&#225;ch t&#7893; ch&#7913;c l&#432;u tr&#7919;</strong>.</p><ul><li><p>SQL &#8594; quan h&#7879;, d&#7841;ng b&#7843;ng (relational model)</p></li><li><p>NoSQL &#8594; phi quan h&#7879;, d&#7841;ng document/kv/column/graph</p></li></ul></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3Es9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81088b7-a188-4089-845a-63936e930a71_1632x1076.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3Es9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81088b7-a188-4089-845a-63936e930a71_1632x1076.png 424w, https://substackcdn.com/image/fetch/$s_!3Es9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81088b7-a188-4089-845a-63936e930a71_1632x1076.png 848w, https://substackcdn.com/image/fetch/$s_!3Es9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81088b7-a188-4089-845a-63936e930a71_1632x1076.png 1272w, https://substackcdn.com/image/fetch/$s_!3Es9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81088b7-a188-4089-845a-63936e930a71_1632x1076.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3Es9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81088b7-a188-4089-845a-63936e930a71_1632x1076.png" width="1456" height="960" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a81088b7-a188-4089-845a-63936e930a71_1632x1076.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:960,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;SQL vs NoSQL - 7 Key Differences You Must Know&quot;,&quot;title&quot;:&quot;SQL vs NoSQL - 7 Key Differences You Must Know&quot;,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="SQL vs NoSQL - 7 Key Differences You Must Know" title="SQL vs NoSQL - 7 Key Differences You Must Know" srcset="https://substackcdn.com/image/fetch/$s_!3Es9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81088b7-a188-4089-845a-63936e930a71_1632x1076.png 424w, https://substackcdn.com/image/fetch/$s_!3Es9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81088b7-a188-4089-845a-63936e930a71_1632x1076.png 848w, https://substackcdn.com/image/fetch/$s_!3Es9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81088b7-a188-4089-845a-63936e930a71_1632x1076.png 1272w, https://substackcdn.com/image/fetch/$s_!3Es9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa81088b7-a188-4089-845a-63936e930a71_1632x1076.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>SQL</h3><ul><li><p><strong>C&#7845;u tr&#250;c</strong>: D&#7919; li&#7879;u l&#432;u trong <strong>b&#7843;ng</strong> (table), g&#7891;m h&#224;ng (row) v&#224; c&#7897;t (column).</p></li><li><p><strong>Schema</strong>: C&#7913;ng, ph&#7843;i &#273;&#7883;nh ngh&#297;a tr&#432;&#7899;c c&#225;c c&#7897;t, ki&#7875;u d&#7919; li&#7879;u.</p></li><li><p><strong>Quan h&#7879;</strong>: B&#7843;ng c&#243; th&#7875; li&#234;n k&#7871;t nhau b&#7857;ng kh&#243;a ch&#237;nh/kh&#243;a ngo&#7841;i.</p></li><li><p><strong>T&#237;nh n&#259;ng n&#7893;i b&#7853;t</strong>:</p><ul><li><p>ACID (giao d&#7883;ch an to&#224;n, d&#7919; li&#7879;u ch&#237;nh x&#225;c)</p></li><li><p>D&#7877; truy v&#7845;n ph&#7913;c t&#7841;p b&#7857;ng SQL</p></li></ul></li><li><p><strong>V&#237; d&#7909;</strong>: MySQL, PostgreSQL, Oracle</p></li><li><p><strong>Minh h&#7885;a</strong>:</p><ul><li><p>M&#7897;t b&#7843;ng <code>SinhVien</code> c&#243; c&#7897;t <code>id</code>, <code>ten</code>, <code>tuoi</code>.</p></li><li><p>M&#7897;t b&#7843;ng <code>Diem</code> c&#243; c&#7897;t <code>sinhvien_id</code>, <code>mon</code>, <code>diem</code>.</p></li><li><p>D&#249;ng join &#273;&#7875; bi&#7871;t sinh vi&#234;n n&#224;o c&#243; &#273;i&#7875;m m&#244;n n&#224;o.</p></li></ul></li></ul><h3>NoSQL</h3><ul><li><p><strong>C&#7845;u tr&#250;c</strong>: Kh&#244;ng nh&#7845;t thi&#7871;t theo b&#7843;ng, c&#243; th&#7875; l&#224; <strong>document</strong>, <strong>key-value</strong>, <strong>c&#7897;t</strong>, ho&#7863;c <strong>graph</strong>.</p></li><li><p><strong>Schema</strong>: Linh ho&#7841;t, th&#234;m tr&#432;&#7901;ng m&#7899;i kh&#244;ng &#7843;nh h&#432;&#7903;ng d&#7919; li&#7879;u c&#361;.</p></li><li><p><strong>Quan h&#7879;</strong>: &#205;t ho&#7863;c kh&#244;ng d&#249;ng join.</p></li><li><p><strong>T&#237;nh n&#259;ng n&#7893;i b&#7853;t</strong>:</p><ul><li><p>D&#7877; m&#7903; r&#7897;ng ngang (d&#249;ng nhi&#7873;u m&#225;y)</p></li><li><p>Hi&#7879;u n&#259;ng cao cho d&#7919; li&#7879;u l&#7899;n ho&#7863;c phi c&#7845;u tr&#250;c</p></li><li><p>M&#7897;t s&#7889; trade-off v&#7873; t&#237;nh nh&#7845;t qu&#225;n (kh&#244;ng ACID 100%)</p></li></ul></li><li><p><strong>V&#237; d&#7909;</strong>: MongoDB (document), Redis (key-value), Cassandra (column)</p></li><li><p><strong>Minh h&#7885;a</strong>:</p><ul><li><p>Trong MongoDB, m&#7897;t document <code>SinhVien</code> c&#243; th&#7875; ch&#7913;a lu&#244;n danh s&#225;ch &#273;i&#7875;m:</p></li></ul></li></ul><pre><code><code>{ &#8220;id&#8221;: 1, &#8220;ten&#8221;: &#8220;An&#8221;, &#8220;tuoi&#8221;: 20, &#8220;diem&#8221;: [{&#8221;mon&#8221;: &#8220;Toan&#8221;, &#8220;diem&#8221;: 9}, {&#8221;mon&#8221;: &#8220;Ly&#8221;, &#8220;diem&#8221;: 8}] }</code></code></pre><h3>So s&#225;nh nhanh</h3><p><strong>C&#7845;u tr&#250;c d&#7919; li&#7879;u:</strong></p><ul><li><p>SQL: D&#7919; li&#7879;u l&#432;u trong b&#7843;ng c&#7889; &#273;&#7883;nh, g&#7891;m h&#224;ng v&#224; c&#7897;t.</p></li><li><p>NoSQL: D&#7919; li&#7879;u c&#243; th&#7875; l&#224; document, key-value, c&#7897;t ho&#7863;c graph, kh&#244;ng c&#7889; &#273;&#7883;nh.</p></li></ul><p><strong>Schema:</strong></p><ul><li><p>SQL: C&#7913;ng, ph&#7843;i &#273;&#7883;nh ngh&#297;a tr&#432;&#7899;c c&#225;c c&#7897;t v&#224; ki&#7875;u d&#7919; li&#7879;u.</p></li><li><p>NoSQL: Linh ho&#7841;t, c&#243; th&#7875; th&#234;m tr&#432;&#7901;ng m&#7899;i d&#7877; d&#224;ng m&#224; kh&#244;ng &#7843;nh h&#432;&#7903;ng d&#7919; li&#7879;u c&#361;.</p></li></ul><p><strong>Quan h&#7879; gi&#7919;a d&#7919; li&#7879;u:</strong></p><ul><li><p>SQL: C&#243;, s&#7917; d&#7909;ng join &#273;&#7875; li&#234;n k&#7871;t c&#225;c b&#7843;ng.</p></li><li><p>NoSQL: &#205;t ho&#7863;c kh&#244;ng d&#249;ng join.</p></li></ul><p><strong>ACID (t&#237;nh to&#224;n v&#7865;n d&#7919; li&#7879;u):</strong></p><ul><li><p>SQL: &#272;&#7843;m b&#7843;o ACID &#273;&#7847;y &#273;&#7911; (an to&#224;n, ch&#237;nh x&#225;c).</p></li><li><p>NoSQL: Kh&#244;ng ho&#224;n to&#224;n ACID, m&#7897;t s&#7889; trade-off &#273;&#7875; t&#259;ng hi&#7879;u n&#259;ng.</p></li></ul><p><strong>V&#237; d&#7909; h&#7879; qu&#7843;n tr&#7883;:</strong></p><ul><li><p>SQL: MySQL, PostgreSQL, Oracle.</p></li><li><p>NoSQL: MongoDB, Redis, Cassandra.</p></li></ul><p><strong>Khi n&#224;o d&#249;ng:</strong></p><ul><li><p>SQL: H&#7879; th&#7889;ng giao d&#7883;ch, d&#7919; li&#7879;u quan tr&#7885;ng, c&#7847;n t&#237;nh to&#224;n v&#7865;n cao.</p></li><li><p>NoSQL: D&#7919; li&#7879;u l&#7899;n, web, realtime, d&#7919; li&#7879;u phi c&#7845;u tr&#250;c ho&#7863;c semi-structured.</p></li></ul><h2>OLTP v&#224; OLAP</h2><blockquote><p>&#272;&#226;y l&#224; c&#225;ch ph&#226;n lo&#7841;i d&#7921;a tr&#234;n <strong>m&#7909;c &#273;&#237;ch s&#7917; d&#7909;ng</strong>, <strong>t&#237;nh ch&#7845;t truy v&#7845;n</strong>, v&#224; <strong>pattern v&#7853;n h&#224;nh</strong>.</p><ul><li><p>OLTP &#8594; giao d&#7883;ch nh&#7887;, &#273;&#7897; tr&#7877; th&#7845;p</p></li><li><p>OLAP &#8594; ph&#226;n t&#237;ch d&#7919; li&#7879;u l&#7899;n, throughput cao</p></li></ul></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Sneb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91d03c0-8fff-4dc8-8596-5b21f84cb710_1920x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Sneb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91d03c0-8fff-4dc8-8596-5b21f84cb710_1920x1080.png 424w, https://substackcdn.com/image/fetch/$s_!Sneb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91d03c0-8fff-4dc8-8596-5b21f84cb710_1920x1080.png 848w, https://substackcdn.com/image/fetch/$s_!Sneb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91d03c0-8fff-4dc8-8596-5b21f84cb710_1920x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!Sneb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91d03c0-8fff-4dc8-8596-5b21f84cb710_1920x1080.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Sneb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91d03c0-8fff-4dc8-8596-5b21f84cb710_1920x1080.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b91d03c0-8fff-4dc8-8596-5b21f84cb710_1920x1080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Transactional vs. Analytical: A Deep Dive into OLTP and OLAP for Data  Professionals | by Henry | Data Engineer Things&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Transactional vs. Analytical: A Deep Dive into OLTP and OLAP for Data  Professionals | by Henry | Data Engineer Things" title="Transactional vs. Analytical: A Deep Dive into OLTP and OLAP for Data  Professionals | by Henry | Data Engineer Things" srcset="https://substackcdn.com/image/fetch/$s_!Sneb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91d03c0-8fff-4dc8-8596-5b21f84cb710_1920x1080.png 424w, https://substackcdn.com/image/fetch/$s_!Sneb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91d03c0-8fff-4dc8-8596-5b21f84cb710_1920x1080.png 848w, https://substackcdn.com/image/fetch/$s_!Sneb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91d03c0-8fff-4dc8-8596-5b21f84cb710_1920x1080.png 1272w, https://substackcdn.com/image/fetch/$s_!Sneb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb91d03c0-8fff-4dc8-8596-5b21f84cb710_1920x1080.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>OLTP (Online Transaction Processing)</h3><ul><li><p><strong>M&#7909;c &#273;&#237;ch</strong>: X&#7917; l&#253; <strong>giao d&#7883;ch h&#224;ng ng&#224;y</strong>, d&#7919; li&#7879;u thay &#273;&#7893;i li&#234;n t&#7909;c.</p></li><li><p><strong>&#272;&#7863;c &#273;i&#7875;m</strong>:</p><ul><li><p>Nhi&#7873;u <strong>ghi/&#273;&#7885;c nh&#7887;</strong> (insert/update/delete nhanh)</p></li><li><p>D&#7919; li&#7879;u <strong>chi ti&#7871;t, t&#432;&#417;i m&#7899;i</strong></p></li><li><p>Y&#234;u c&#7847;u <strong>ACID</strong> (an to&#224;n, ch&#237;nh x&#225;c)</p></li><li><p>Th&#432;&#7901;ng l&#224; <strong>b&#7843;ng chu&#7849;n h&#243;a</strong> (normalized) &#273;&#7875; tr&#225;nh d&#432; th&#7915;a</p></li></ul></li><li><p><strong>V&#237; d&#7909;</strong>:</p><ul><li><p>MySQL l&#432;u &#273;&#417;n h&#224;ng, kh&#225;ch h&#224;ng, giao d&#7883;ch ng&#226;n h&#224;ng</p></li><li><p>M&#7897;t b&#7843;ng <code>Orders</code> v&#7899;i <code>OrderID</code>, <code>CustomerID</code>, <code>Amount</code>, <code>Status</code></p></li></ul></li><li><p><strong>Truy v&#7845;n</strong>: Nhanh, &#273;&#417;n gi&#7843;n, truy v&#7845;n theo h&#224;ng, s&#7889; l&#432;&#7907;ng b&#7843;n ghi &#237;t m&#7895;i l&#7847;n</p></li></ul><h3>OLAP (Online Analytical Processing)</h3><ul><li><p><strong>M&#7909;c &#273;&#237;ch</strong>: Ph&#226;n t&#237;ch d&#7919; li&#7879;u <strong>l&#7899;n</strong>, t&#7893;ng h&#7907;p th&#244;ng tin &#273;&#7875; ra quy&#7871;t &#273;&#7883;nh.</p></li><li><p><strong>&#272;&#7863;c &#273;i&#7875;m</strong>:</p><ul><li><p>Nhi&#7873;u <strong>&#273;&#7885;c l&#7899;n</strong>, &#237;t ghi (bulk insert)</p></li><li><p>D&#7919; li&#7879;u th&#432;&#7901;ng <strong>t&#243;m t&#7855;t, g&#7897;p</strong>, kh&#244;ng c&#7847;n t&#432;&#417;i m&#7899;i ngay l&#7853;p t&#7913;c</p></li><li><p>Th&#432;&#7901;ng d&#249;ng <strong>b&#7843;ng d&#7841;ng c&#7897;t (columnar)</strong> &#273;&#7875; t&#237;nh to&#225;n nhanh</p></li><li><p>Thi&#7871;t k&#7871; <strong>denormalized</strong> (d&#7919; li&#7879;u l&#7863;p &#273;&#7875; t&#259;ng t&#7889;c ph&#226;n t&#237;ch)</p></li></ul></li><li><p><strong>V&#237; d&#7909;</strong>:</p><ul><li><p>ClickHouse l&#432;u d&#7919; li&#7879;u b&#225;n h&#224;ng theo th&#225;ng, theo s&#7843;n ph&#7849;m, t&#7893;ng doanh thu</p></li><li><p>M&#7897;t b&#7843;ng <code>SalesSummary</code> v&#7899;i <code>Month</code>, <code>ProductID</code>, <code>TotalAmount</code></p></li></ul></li><li><p><strong>Truy v&#7845;n</strong>: Ph&#7913;c t&#7841;p, t&#237;nh t&#7893;ng, trung b&#236;nh, group by, trend, b&#225;o c&#225;o</p></li></ul><h3>So s&#225;nh nhanh</h3><p><strong>M&#7909;c &#273;&#237;ch:</strong></p><ul><li><p>OLTP: X&#7917; l&#253; giao d&#7883;ch h&#224;ng ng&#224;y.</p></li><li><p>OLAP: Ph&#226;n t&#237;ch d&#7919; li&#7879;u, l&#224;m b&#225;o c&#225;o.</p></li></ul><p><strong>D&#7919; li&#7879;u:</strong></p><ul><li><p>OLTP: Chi ti&#7871;t, lu&#244;n m&#7899;i.</p></li><li><p>OLAP: T&#243;m t&#7855;t, d&#7919; li&#7879;u l&#7883;ch s&#7917;.</p></li></ul><p><strong>Ghi/&#273;&#7885;c:</strong></p><ul><li><p>OLTP: Nhi&#7873;u ghi/&#273;&#7885;c nh&#7887;, thao t&#225;c nhanh.</p></li><li><p>OLAP: &#205;t ghi, nhi&#7873;u &#273;&#7885;c l&#7899;n, x&#7917; l&#253; nhi&#7873;u b&#7843;n ghi c&#249;ng l&#250;c.</p></li></ul><p><strong>ACID:</strong></p><ul><li><p>OLTP: Quan tr&#7885;ng, &#273;&#7843;m b&#7843;o giao d&#7883;ch an to&#224;n.</p></li><li><p>OLAP: Kh&#244;ng b&#7855;t bu&#7897;c 100%, m&#7897;t s&#7889; trade-off &#273;&#7875; t&#259;ng t&#7889;c ph&#226;n t&#237;ch.</p></li></ul><p><strong>Thi&#7871;t k&#7871; d&#7919; li&#7879;u:</strong></p><ul><li><p>OLTP: Chu&#7849;n h&#243;a (normalized) &#273;&#7875; tr&#225;nh d&#432; th&#7915;a.</p></li><li><p>OLAP: Denormalized ho&#7863;c d&#7841;ng c&#7897;t (columnar) &#273;&#7875; truy v&#7845;n nhanh.</p></li></ul><p><strong>V&#237; d&#7909; c&#417; s&#7903; d&#7919; li&#7879;u:</strong></p><ul><li><p>OLTP: MySQL, PostgreSQL.</p></li><li><p>OLAP: ClickHouse, Amazon Redshift.</p></li></ul><p><strong>Truy v&#7845;n:</strong></p><ul><li><p>OLTP: Nhanh, &#273;&#417;n gi&#7843;n, thao t&#225;c tr&#234;n v&#224;i b&#7843;n ghi.</p></li><li><p>OLAP: Ph&#7913;c t&#7841;p, ch&#7853;m h&#417;n nh&#432;ng t&#237;nh to&#225;n nhanh tr&#234;n l&#432;&#7907;ng l&#7899;n d&#7919; li&#7879;u.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[Single-node system và Distributed system]]></title><description><![CDATA[Distributed system kh&#244;ng ph&#7843;i l&#224; n&#226;ng c&#7845;p, m&#224; l&#224; &#273;&#7863;c t&#7843; k&#7929; thu&#7853;t &#273;&#7875; gi&#7843;i quy&#7871;t nh&#7919;ng th&#7913; m&#224; single-node kh&#244;ng th&#7875;]]></description><link>https://tiendatengineer.substack.com/p/single-node-system-va-distributed</link><guid isPermaLink="false">https://tiendatengineer.substack.com/p/single-node-system-va-distributed</guid><dc:creator><![CDATA[Nguyễn Doãn Tiến Đạt]]></dc:creator><pubDate>Fri, 12 Dec 2025 03:39:22 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/f7180c36-f1d1-4217-864d-9467c6de0130_2560x2560.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote><p>Khi n&#243;i &#273;&#7871;n <strong>h&#7879; th&#7889;ng ph&#226;n t&#225;n</strong> (distributed system), nhi&#7873;u ng&#432;&#7901;i d&#7877; h&#236;nh dung ngay &#273;&#7871;n c&#225;c c&#7909;m m&#225;y ch&#7911; l&#7899;n, microservices, Kubernetes, sharding, replication&#8230; Nh&#432;ng &#273;&#7875; hi&#7875;u &#273;&#250;ng b&#7843;n ch&#7845;t, tr&#432;&#7899;c ti&#234;n ta ph&#7843;i b&#7855;t &#273;&#7847;u t&#7915; <strong>&#273;i&#7873;u &#273;&#417;n gi&#7843;n nh&#7845;t: Single-Node System</strong>. V&#236; distributed system sinh ra &#273;&#7875; gi&#7843;i quy&#7871;t <strong>nh&#7919;ng gi&#7899;i h&#7841;n</strong> c&#7911;a single-node.</p></blockquote><h1>Single-Node System &#8211; M&#7897;t m&#225;y l&#224;m t&#7845;t c&#7843;</h1><p><strong>Single-node system</strong> l&#224; m&#244; h&#236;nh m&#224; to&#224;n b&#7897; &#7913;ng d&#7909;ng c&#7911;a b&#7841;n ch&#7841;y tr&#234;n <strong>m&#7897;t m&#225;y duy nh&#7845;t</strong>:<br>&#8211; App backend<br>&#8211; Database<br>&#8211; Storage<br>&#8211; Cronjob<br>&#8211; Cache (c&#243; th&#7875; l&#224; memory)</p><p>T&#7845;t c&#7843; t&#224;i nguy&#234;n CPU, RAM, Disk c&#7911;a h&#7879; th&#7889;ng &#273;&#7873;u n&#7857;m tr&#234;n c&#249;ng m&#7897;t node.</p><p><strong>&#10004; &#431;u &#273;i&#7875;m</strong></p><ul><li><p><strong>&#272;&#417;n gi&#7843;n</strong>: tri&#7875;n khai d&#7877;, debug d&#7877;, chi ph&#237; th&#7845;p.</p></li><li><p><strong>Kh&#244;ng c&#243; distributed complexity</strong>: kh&#244;ng ph&#7843;i lo network partition, replication lag, consensus, clock drift&#8230;</p></li><li><p><strong>Ph&#249; h&#7907;p cho MVP</strong>: h&#7847;u h&#7871;t startup b&#7855;t &#273;&#7847;u b&#7857;ng single-node.</p></li></ul><p><strong>&#10004; H&#7841;n ch&#7871;</strong></p><ul><li><p><strong>Single Point of Failure</strong>: m&#225;y ch&#7871;t &#8594; h&#7879; th&#7889;ng ch&#7871;t.</p></li><li><p><strong>Kh&#244;ng scale theo chi&#7873;u ngang</strong>: mu&#7889;n m&#7841;nh h&#417;n ch&#7881; c&#243; c&#225;ch t&#259;ng CPU/RAM (vertical scaling).</p></li><li><p><strong>Gi&#7899;i h&#7841;n t&#224;i nguy&#234;n</strong>: d&#249; n&#226;ng c&#7845;p &#273;&#7871;n &#273;&#226;u c&#361;ng c&#243; ng&#432;&#7905;ng (th&#432;&#7901;ng l&#224; v&#224;i tr&#259;m GB RAM v&#224; v&#224;i ch&#7909;c cores).</p></li></ul><p>Single-node gi&#7889;ng nh&#432; <strong>m&#7897;t nh&#224; h&#224;ng ch&#7881; c&#243; m&#7897;t &#273;&#7847;u b&#7871;p</strong>. N&#7871;u kh&#225;ch qu&#225; &#273;&#244;ng &#8594; b&#7871;p qu&#225; t&#7843;i &#8594; ph&#7909;c v&#7909; ch&#7853;m &#8594; b&#7919;a &#259;n b&#7883; delay.</p><div><hr></div><h1>Distributed System &#8211; Khi m&#7897;t m&#225;y kh&#244;ng c&#242;n &#273;&#7911; n&#7919;a</h1><p><strong>Distributed system</strong> l&#224; h&#7879; th&#7889;ng ch&#7841;y tr&#234;n <strong>nhi&#7873;u node</strong> &#273;&#7897;c l&#7853;p, giao ti&#7871;p qua m&#7841;ng nh&#432;ng ph&#7889;i h&#7907;p &#273;&#7875; ho&#7841;t &#273;&#7897;ng nh&#432; m&#7897;t h&#7879; th&#7889;ng duy nh&#7845;t.</p><p>M&#7897;t distributed system c&#243; th&#7875; g&#7891;m:</p><ul><li><p>Nhi&#7873;u backend service</p></li><li><p>Nhi&#7873;u database instance (primary/replica, sharding)</p></li><li><p>Caching cluster</p></li><li><p>Storage distributed (S3, Ceph&#8230;)</p></li><li><p>Message queue cluster (Kafka, NATS)</p></li></ul><p><strong>&#10004; &#431;u &#273;i&#7875;m</strong></p><ul><li><p><strong>Horizontal scaling</strong>: c&#7847;n th&#234;m s&#7913;c m&#7841;nh &#8594; th&#234;m node.</p></li><li><p><strong>High availability</strong>: m&#7897;t m&#225;y ch&#7871;t h&#7879; th&#7889;ng v&#7851;n ch&#7841;y.</p></li><li><p><strong>Throughput l&#7899;n</strong>: chia t&#7843;i qua nhi&#7873;u m&#225;y.</p></li><li><p><strong>&#272;&#225;p &#7913;ng nhu c&#7847;u l&#7899;n</strong>: h&#224;ng tri&#7879;u user c&#249;ng l&#250;c.</p></li></ul><p>Distributed system gi&#7889;ng nh&#432; <strong>nh&#224; h&#224;ng c&#243; nhi&#7873;u &#273;&#7847;u b&#7871;p</strong>, m&#7895;i ng&#432;&#7901;i l&#224;m m&#7897;t ph&#7847;n &#8594; ph&#7909;c v&#7909; &#273;&#432;&#7907;c nhi&#7873;u kh&#225;ch c&#249;ng l&#250;c.</p><p><strong>&#10004; H&#7841;n ch&#7871;</strong></p><ul><li><p><strong>Ph&#7913;c t&#7841;p</strong>: ph&#7843;i &#273;&#7889;i m&#7863;t v&#7899;i distributed consensus, network latency, partition, replication consistency&#8230;</p></li><li><p><strong>Kh&#243; debug</strong>: l&#7895;i c&#243; th&#7875; n&#7857;m &#7903; b&#7845;t k&#7923; node n&#224;o.</p></li><li><p><strong>Chi ph&#237; cao h&#417;n</strong>: c&#7843; ph&#7847;n c&#7913;ng l&#7851;n c&#244;ng s&#7913;c v&#7853;n h&#224;nh.</p></li><li><p><strong>Kh&#244;ng ph&#7843;i b&#224;i to&#225;n n&#224;o c&#361;ng c&#7847;n distributed</strong>.</p></li></ul><div><hr></div><h1>Khi n&#224;o Single-Node l&#224; &#273;&#7911;?</h1><ul><li><p>MVP, proof-of-concept</p></li><li><p>H&#7879; th&#7889;ng d&#432;&#7899;i 5&#8211;10k users/day</p></li><li><p>Workload nh&#7865;, kh&#244;ng c&#7847;n realtime</p></li><li><p>D&#7919; li&#7879;u kh&#244;ng qu&#225; l&#7899;n (&lt;100GB)</p></li><li><p>Team nh&#7887;, kh&#244;ng c&#243; DevOps chuy&#234;n s&#226;u</p></li></ul><p>&#128073; Th&#7921;c t&#7871; &#273;&#7841;i &#273;a s&#7889; c&#225;c d&#7921; &#225;n n&#7897;i b&#7897; doanh nghi&#7879;p v&#7851;n ch&#7841;y <strong>single-node</strong> r&#7845;t &#7893;n &#273;&#7883;nh.</p><div><hr></div><h1>Khi n&#224;o c&#7847;n chuy&#7875;n sang Distributed?</h1><p>Khi single-node ch&#7841;m ng&#432;&#7905;ng:</p><ul><li><p>CPU/RAM kh&#244;ng th&#7875; t&#259;ng th&#234;m</p></li><li><p>Database b&#7883; qu&#225; t&#7843;i</p></li><li><p>M&#7897;t node kh&#244;ng c&#242;n &#273;&#225;ng tin c&#7853;y</p></li><li><p>C&#7847;n multi-region</p></li><li><p>C&#7847;n high availability</p></li><li><p>C&#7847;n h&#417;n 1 instance &#273;&#7875; scale</p></li><li><p>Delay t&#259;ng do t&#7843;i cao</p></li></ul><p>Ho&#7863;c khi s&#7843;n ph&#7849;m ph&#225;t tri&#7875;n &#273;&#7871;n m&#7913;c c&#7847;n:</p><ul><li><p>caching cluster</p></li><li><p>sharding database</p></li><li><p>load balancing</p></li><li><p>event-driven architecture</p></li></ul>]]></content:encoded></item><item><title><![CDATA[SSL/TLS và Certificate]]></title><description><![CDATA[SSL/TLS l&#224; c&#244;ng ngh&#7879; gi&#250;p d&#7919; li&#7879;u Internet an to&#224;n. Certificate l&#224; gi&#7845;y ch&#7913;ng nh&#7853;n &#273;&#7875; tr&#236;nh duy&#7879;t bi&#7871;t website l&#224; th&#7853;t v&#224; c&#243; th&#7875; tin t&#432;&#7903;ng.]]></description><link>https://tiendatengineer.substack.com/p/ssltls-va-certificate</link><guid isPermaLink="false">https://tiendatengineer.substack.com/p/ssltls-va-certificate</guid><dc:creator><![CDATA[Nguyễn Doãn Tiến Đạt]]></dc:creator><pubDate>Fri, 12 Dec 2025 03:02:41 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/c383bdc6-d14b-4acc-a63f-fbf4836d221b_1000x666.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>SSL/TLS</h1><blockquote><p><strong>SSL/TLS l&#224; &#8220;&#7893; kh&#243;a an to&#224;n&#8221; gi&#250;p d&#7919; li&#7879;u tr&#234;n Internet kh&#244;ng b&#7883; &#273;&#7885;c tr&#7897;m ho&#7863;c s&#7917;a &#273;&#7893;i.</strong></p></blockquote><p>Gi&#7889;ng nh&#432;:</p><ul><li><p>B&#7841;n <strong>n&#243;i chuy&#7879;n qua &#273;i&#7879;n tho&#7841;i</strong> nh&#432;ng &#273;&#432;&#7901;ng d&#226;y &#273;&#227; &#273;&#432;&#7907;c <strong>m&#227; h&#243;a</strong>, ng&#432;&#7901;i nghe l&#233;n kh&#244;ng hi&#7875;u &#273;&#432;&#7907;c.</p></li><li><p>B&#7841;n g&#7917;i <strong>th&#432;</strong> nh&#432;ng th&#432; &#273;&#227; &#273;&#432;&#7907;c <strong>ni&#234;m phong</strong>, ng&#432;&#7901;i kh&#225;c m&#7903; ra s&#7869; b&#7883; ph&#225;t hi&#7879;n.</p></li></ul><p>&#128073; <strong>SSL/TLS = c&#244;ng ngh&#7879; m&#227; h&#243;a gi&#250;p th&#244;ng tin khi truy&#7873;n qua Internet &#273;&#432;&#7907;c an to&#224;n.</strong></p><p>Khi truy c&#7853;p trang web c&#243; <code>https://</code> v&#224; bi&#7875;u t&#432;&#7907;ng &#7893; kh&#243;a, b&#7841;n &#273;ang d&#249;ng SSL/TLS.</p><h1>Certificate</h1><blockquote><p><strong>Certificate (ch&#7913;ng ch&#7881; s&#7889;) gi&#7889;ng nh&#432; &#8220;th&#7867; c&#259;n c&#432;&#7899;c c&#7911;a website&#8221;.</strong></p></blockquote><p>N&#243; d&#249;ng &#273;&#7875; ch&#7913;ng minh:</p><ol><li><p><strong>Website &#273;&#250;ng l&#224; website th&#7853;t</strong>, kh&#244;ng ph&#7843;i gi&#7843; m&#7841;o</p></li><li><p><strong>Website s&#7903; h&#7919;u &#273;&#250;ng domain</strong>, v&#237; d&#7909;: https://bank.com</p></li><li><p><strong>Website c&#243; ch&#236;a kh&#243;a &#273;&#7875; m&#227; h&#243;a d&#7919; li&#7879;u an to&#224;n</strong></p></li></ol><p>Certificate &#273;&#432;&#7907;c c&#7845;p b&#7903;i <strong>t&#7893; ch&#7913;c uy t&#237;n</strong> (CA &#8211; Certificate Authority), t&#432;&#417;ng t&#7921; nh&#432;:</p><ul><li><p>Th&#7867; c&#259;n c&#432;&#7899;c &#273;&#432;&#7907;c c&#7845;p b&#7903;i Nh&#224; n&#432;&#7899;c</p></li><li><p>B&#7857;ng l&#225;i xe &#273;&#432;&#7907;c c&#7845;p b&#7903;i c&#417; quan giao th&#244;ng</p></li></ul><p>&#128073; Tr&#236;nh duy&#7879;t ch&#7881; tin nh&#7919;ng certificate &#273;&#432;&#7907;c &#8220;nh&#224; ph&#225;t h&#224;nh uy t&#237;n&#8221; c&#7845;p.</p><h1>SSL/TLS k&#7871;t h&#7907;p Certificate</h1><ol><li><p><strong>Certificate</strong> gi&#250;p tr&#236;nh duy&#7879;t ki&#7875;m tra: &#8220;&#272;&#226;y c&#243; &#273;&#250;ng l&#224; website th&#7853;t kh&#244;ng?&#8221;</p></li><li><p>sau khi x&#225;c minh, tr&#236;nh duy&#7879;t v&#224; website d&#249;ng <strong>SSL/TLS</strong> &#273;&#7875;: <strong>m&#227; h&#243;a to&#224;n b&#7897; d&#7919; li&#7879;u g&#7917;i/nh&#7853;n</strong></p></li></ol><p>&#128073; Certificate = ch&#7913;ng minh danh t&#237;nh<br>&#128073; SSL/TLS = b&#7843;o m&#7853;t d&#7919; li&#7879;u</p><p>Ch&#250;ng gi&#7889;ng nh&#432;:</p><ul><li><p>Certificate = &#8220;th&#7867; c&#259;n c&#432;&#7899;c&#8221; &#273;&#7875; ch&#7913;ng minh b&#7841;n l&#224; ai</p></li><li><p>SSL/TLS = &#8220;m&#227; h&#243;a cu&#7897;c tr&#242; chuy&#7879;n&#8221; &#273;&#7875; b&#7843;o v&#7879; th&#244;ng tin</p></li></ul><h1>C&#225;c m&#244; h&#236;nh x&#225;c th&#7921;c</h1><h2>One-Way TLS (ph&#7893; bi&#7871;n nh&#7845;t)</h2><ul><li><p>Client ki&#7875;m tra certificate c&#7911;a server</p></li><li><p>Server <strong>kh&#244;ng</strong> ki&#7875;m tra client</p></li><li><p>Browser &#8594; Server: HTTPS</p></li><li><p>API Gateway &#8594; Backend Service</p></li></ul><p>&#128073; D&#249;ng cho <strong>99% website</strong>.</p><div><hr></div><h2>Mutual TLS (mTLS) &#8212; 2 chi&#7873;u</h2><ul><li><p>Server c&#243; certificate</p></li><li><p>Client <strong>c&#361;ng ph&#7843;i c&#243; certificate</strong></p></li><li><p>Hai b&#234;n &#273;&#7873;u authenticate nhau</p></li></ul><p>&#7912;ng d&#7909;ng:</p><ul><li><p>K&#7871;t n&#7889;i microservice trong n&#7897;i b&#7897;</p></li><li><p>Banking, Payment Gateway</p></li><li><p>IoT device authenticate (kh&#244;ng d&#249;ng password)</p></li></ul><p>&#128073; B&#7843;o m&#7853;t r&#7845;t cao, y&#234;u c&#7847;u qu&#7843;n l&#253; cert ph&#7913;c t&#7841;p.</p><h1>Q&#250;a tr&#236;nh TLS Handshake</h1><div data-attrs="{&quot;url&quot;:&quot;https://cheapsslweb.com/blog/wp-content/uploads/2024/07/ssl-tls-handshake-1.webp&quot;}" data-component-name="AssetErrorToDOM"><picture><img src="/img/missing-image.png" height="455" width="728"></picture></div><h2>Establish TCP Connection (3-way handshake)</h2><p>Trong h&#236;nh:</p><ul><li><p>Client &#8594; SYN</p></li><li><p>Server &#8594; SYN + ACK</p></li><li><p>Client &#8594; ACK</p></li></ul><div><hr></div><h2>SSL/TLS Handshake (TLS 1.2)</h2><h3>ClientHello</h3><p>Client g&#7917;i:</p><ul><li><p>version TLS h&#7895; tr&#7907;</p></li><li><p>c&#225;c cipher suites h&#7895; tr&#7907;</p></li><li><p>random bytes</p></li><li><p>SNI (domain truy c&#7853;p)</p></li></ul><div><hr></div><h3>ServerHello + Certificate</h3><p>Server g&#7917;i:</p><ul><li><p>version TLS ch&#7885;n</p></li><li><p>cipher suite ch&#7885;n</p></li><li><p>certificate (public key)</p></li></ul><div><hr></div><h3>Certificate Verification (Client &#8594; Server)</h3><p>Client ki&#7875;m tra:</p><ul><li><p>CA c&#243; h&#7907;p l&#7879; kh&#244;ng</p></li><li><p>domain trong cert c&#243; kh&#7899;p kh&#244;ng</p></li><li><p>cert c&#242;n h&#7841;n kh&#244;ng</p></li></ul><div><hr></div><h3>ClientKeyExchange</h3><p>Client g&#7917;i pre-master secret ho&#7863;c public key (n&#7871;u ECDHE).</p><div><hr></div><h3>Server Finished</h3><p>C&#7843; hai b&#234;n:</p><ul><li><p>t&#7841;o master secret</p></li><li><p>sinh symmetric key &#273;&#7875; m&#227; h&#243;a data</p></li><li><p>b&#225;o &#8220;Finished&#8221;</p></li></ul><div><hr></div><h2>Encrypted Application Data</h2><p>Sau khi handshake xong, to&#224;n b&#7897; HTTP s&#7869; &#273;&#432;&#7907;c m&#227; h&#243;a:</p><p>Client &#8594; HTTP GET<br>Server &#8594; HTTP Response</p><h1>V&#237; d&#7909; v&#7873; setup HTTPS cho server</h1><h2>Chu&#7849;n b&#7883; domain</h2><p>HTTPS <strong>b&#7855;t bu&#7897;c</strong> c&#7847;n 1 domain h&#7907;p l&#7879;.</p><p>B&#7841;n c&#7847;n:</p><ul><li><p>M&#7897;t domain: v&#237; d&#7909; <code>myservice.com</code></p></li><li><p>Tr&#7887; DNS v&#7873; server (A record &#8594; IP server)</p></li></ul><p>&#128073; N&#7871;u ch&#432;a tr&#7887; DNS, th&#236; cert kh&#244;ng th&#7875; verify.</p><h2>L&#7845;y SSL/TLS certificate</h2><p>C&#243; 2 lo&#7841;i ph&#7893; bi&#7871;n:</p><h3>L&#7921;a ch&#7885;n A &#8211; Free (Let&#8217;s Encrypt)</h3><p>D&#249;ng certbot, zero-downtime, t&#7921; gia h&#7841;n.<br>D&#249;ng cho h&#7847;u h&#7871;t h&#7879; th&#7889;ng.</p><p><strong>On Ubuntu:</strong></p><pre><code><code>sudo apt install certbot
sudo apt install python3-certbot-nginx
sudo certbot --nginx -d myservice.com
</code></code></pre><h3>L&#7921;a ch&#7885;n B &#8211; Certificate tr&#7843; ph&#237;</h3><p>B&#7841;n mua t&#7915;:</p><ul><li><p>DigiCert</p></li><li><p>GlobalSign</p></li><li><p>Sectigo</p></li></ul><p>Quy tr&#236;nh:</p><ul><li><p>T&#7841;o CSR</p></li><li><p>G&#7917;i cho CA</p></li><li><p>Nh&#7853;n file <code>.crt</code> + <code>.key</code> + chain file</p></li></ul><h2>C&#7845;u h&#236;nh server ch&#7841;y HTTPS</h2><h3>Case 1 &#8212; Nginx</h3><p>File c&#7845;u h&#236;nh v&#237; d&#7909;:</p><pre><code><code>server {
    listen 443 ssl;
    server_name myservice.com;

    ssl_certificate /etc/letsencrypt/live/myservice.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/myservice.com/privkey.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    location / {
        proxy_pass http://127.0.0.1:8080;
    }
}</code></code></pre><p>Th&#234;m redirect HTTP &#8594; HTTPS:</p><pre><code><code>server {
    listen 80;
    server_name myservice.com;
    return 301 https://$host$request_uri;
}
</code></code></pre><p>Reload:</p><pre><code><code>sudo nginx -t
sudo systemctl reload nginx
</code></code></pre><div><hr></div><h3>Case 2 &#8212; Golang HTTPS native</h3><p>Golang cho ph&#233;p ch&#7841;y HTTPS r&#7845;t d&#7877;:</p><p>File <code>main.go</code>:</p><pre><code><code>package main

import (
    &#8220;log&#8221;
    &#8220;net/http&#8221;
)

func main() {
    http.HandleFunc(&#8221;/&#8221;, func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte(&#8221;Hello HTTPS&#8221;))
    })

    log.Println(&#8221;Listening on :443...&#8221;)
    err := http.ListenAndServeTLS(&#8221;:443&#8221;,
        &#8220;server.crt&#8221;, // public cert
        &#8220;server.key&#8221;, // private key
        nil,
    )
    log.Fatal(err)
}</code></code></pre><p>Ch&#7841;y:</p><pre><code><code>go run main.go</code></code></pre><div><hr></div><h2>Ki&#7875;m tra HTTPS</h2><ul><li><p>Truy c&#7853;p https://myservice.com</p></li><li><p>Ki&#7875;m tra padlock (&#7893; kh&#243;a) trong browser</p></li><li><p>Ki&#7875;m tra certificate v&#7899;i:</p></li></ul><pre><code><code>openssl s_client -connect myservice.com:443 -servername myservice.com
</code></code></pre><div><hr></div><h2>Gia h&#7841;n certificate</h2><p>N&#7871;u d&#249;ng Let&#8217;s Encrypt:</p><pre><code><code>sudo certbot renew --dry-run
</code></code></pre><p>Let&#8217;s Encrypt t&#7921; gia h&#7841;n qua cron.</p><div><hr></div><h2>T&#243;m t&#7855;t 5 b&#432;&#7899;c &#273;&#417;n gi&#7843;n</h2><ol><li><p><strong>C&#243; domain</strong> &#8594; tr&#7887; DNS v&#7873; server</p></li><li><p><strong>Sinh certificate</strong> (Let&#8217;s Encrypt / tr&#7843; ph&#237;)</p></li><li><p><strong>C&#7845;u h&#236;nh HTTPS</strong> (Nginx, Golang, Node, v.v.)</p></li><li><p><strong>Redirect HTTP &#8594; HTTPS</strong></p></li><li><p><strong>Gia h&#7841;n cert</strong> (Let&#8217;s Encrypt auto)</p></li></ol>]]></content:encoded></item><item><title><![CDATA[HTTP/1.1 và HTTP/2]]></title><description><![CDATA[HTTP/1.1 x&#7917; l&#253; m&#7895;i k&#7871;t n&#7889;i theo ki&#7875;u l&#7847;n l&#432;&#7907;t t&#7915;ng request m&#7897;t d&#7877; g&#226;y ngh&#7869;n, trong khi HTTP/2 cho ph&#233;p nhi&#7873;u request ch&#7841;y song song tr&#234;n c&#249;ng m&#7897;t k&#7871;t n&#7889;i nh&#7901; multiplexing]]></description><link>https://tiendatengineer.substack.com/p/http11-va-http2</link><guid isPermaLink="false">https://tiendatengineer.substack.com/p/http11-va-http2</guid><dc:creator><![CDATA[Nguyễn Doãn Tiến Đạt]]></dc:creator><pubDate>Fri, 12 Dec 2025 02:10:09 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/66f1c307-8ac8-42c1-ba50-def17c555a00_800x480.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote><p>HTTP/1.1 gi&#7889;ng nh&#432; m&#7897;t ng&#432;&#7901;i ch&#7841;y b&#224;n ch&#7881; b&#432;ng &#273;&#432;&#7907;c <strong>m&#7897;t m&#243;n m&#7895;i l&#7847;n</strong>, n&#234;n ph&#7843;i &#273;i t&#7899;i &#273;i lui r&#7845;t nhi&#7873;u.</p><p>HTTP/2 gi&#7889;ng nh&#432; m&#7897;t xe &#273;&#7849;y c&#243; th&#7875; <strong>ch&#7903; nhi&#7873;u m&#243;n c&#249;ng l&#250;c</strong>, n&#234;n ph&#7909;c v&#7909; nhanh v&#224; &#237;t ph&#7843;i di chuy&#7875;n h&#417;n.</p></blockquote><h1>V&#236; sao c&#7847;n hi&#7875;u HTTP/1.1 v&#224; HTTP/2?</h1><p>&#272;a s&#7889; developer d&#249;ng HTTP m&#7895;i ng&#224;y nh&#432;ng &#237;t khi th&#7853;t s&#7921; nh&#236;n th&#7845;y &#8220;c&#225;ch n&#243; ch&#7841;y b&#234;n d&#432;&#7899;i&#8221;. Khi vi&#7871;t API, g&#7885;i API, d&#249;ng tr&#236;nh duy&#7879;t&#8230; ta ch&#7881; th&#7845;y <em>request</em> v&#224; <em>response</em>&#8212;nh&#432;ng kh&#244;ng th&#7845;y d&#242;ng d&#7919; li&#7879;u th&#7921;c s&#7921; di chuy&#7875;n nh&#432; th&#7871; n&#224;o.</p><p>&#272;&#7875; hi&#7875;u v&#236; sao HTTP/2 nhanh h&#417;n HTTP/1.1, v&#236; sao c&#243; chuy&#7879;n Head-of-Line Blocking, v&#236; sao ph&#7843;i c&#243; stream, frame, multiplexing&#8230;, ta ph&#7843;i &#273;&#7863;t ch&#250;ng v&#224;o <em>&#273;&#250;ng t&#7847;ng</em> trong stack m&#7841;ng: <strong>HTTP &#7903; Application Layer, TCP &#7903; Transport Layer</strong>.</p><div><hr></div><h1>T&#7847;ng HTTP v&#224; t&#7847;ng TCP</h1><p><strong>HTTP &#8594; Application Layer</strong><br>&#272;&#226;y l&#224; n&#417;i b&#7841;n vi&#7871;t API, define header, body, method GET/POST&#8230;<br>HTTP ch&#7881; quan t&#226;m t&#7899;i <em>request l&#224; g&#236;</em> v&#224; <em>response l&#224; g&#236;</em>.</p><p><strong>TCP &#8594; Transport Layer</strong><br>&#272;&#226;y l&#224; n&#417;i d&#7919; li&#7879;u &#273;&#432;&#7907;c <em>chia nh&#7887;</em>, <em>&#273;&#225;nh s&#7889;</em>, <em>g&#7917;i t&#7915;ng packet</em>, <em>&#273;&#7843;m b&#7843;o kh&#244;ng m&#7845;t d&#7919; li&#7879;u</em>, <em>&#273;&#250;ng th&#7913; t&#7921;</em>.</p><p><strong>&#272;i&#7875;m quan tr&#7885;ng:</strong></p><blockquote><p>HTTP kh&#244;ng t&#7921; v&#7853;n chuy&#7875;n d&#7919; li&#7879;u. TCP m&#7899;i l&#224; th&#7913; th&#7921;c s&#7921; &#8220;ch&#7903;&#8221; d&#7919; li&#7879;u &#273;i.</p></blockquote><p>H&#227;y t&#432;&#7903;ng t&#432;&#7907;ng:</p><ul><li><p>HTTP = h&#224;ng h&#243;a</p></li><li><p>TCP = xe t&#7843;i v&#7853;n chuy&#7875;n</p></li><li><p>M&#7897;t request/response = m&#7897;t ki&#7879;n h&#224;ng</p></li><li><p>TCP chia ki&#7879;n h&#224;ng th&#224;nh nhi&#7873;u th&#249;ng nh&#7887; (packet) r&#7891;i g&#7917;i &#273;i.</p></li></ul><div><hr></div><h1>HTTP/1.1 ho&#7841;t &#273;&#7897;ng nh&#432; th&#7871; n&#224;o v&#224; HOL x&#7843;y ra &#7903; &#273;&#226;u?</h1><blockquote><p>HTTP/1.1 quy &#273;&#7883;nh &#8220;1 request t&#7841;i 1 th&#7901;i &#273;i&#7875;m tr&#234;n 1 TCP connection&#8221;</p></blockquote><p>D&#249; c&#243; keep-alive, pipelining th&#236; b&#7843;n ch&#7845;t l&#224;:</p><ul><li><p>D&#7919; li&#7879;u c&#7911;a request ph&#7843;i &#273;i theo th&#7913; t&#7921;.</p></li><li><p>Response c&#361;ng ph&#7843;i tr&#7843; v&#7873; theo <strong>th&#7913; t&#7921;</strong>.</p></li><li><p>N&#7871;u request &#273;&#7913;ng &#273;&#7847;u b&#7883; ch&#7853;m &#8594; m&#7885;i request ph&#237;a sau &#273;&#7873;u <strong>ch&#7901;</strong>.</p></li></ul><p>&#272;&#226;y g&#7885;i l&#224;:</p><blockquote><p><strong>Head-of-Line Blocking (HOL)</strong> &#7903; t&#7847;ng HTTP.</p></blockquote><p><strong>V&#237; d&#7909; h&#236;nh t&#432;&#7907;ng:</strong><br>B&#7841;n &#273;i qua 1 tr&#7841;m thu ph&#237; c&#243; 1 l&#224;n. Xe &#273;&#7847;u ti&#234;n b&#7883; k&#7865;t &#8594; t&#7845;t c&#7843; xe ph&#237;a sau ph&#7843;i &#273;&#7913;ng ch&#7901;. &#272;&#243; ch&#237;nh l&#224; HTTP/1.1.</p><div><hr></div><h1>HTTP/2 thay &#273;&#7893;i &#273;i&#7873;u g&#236;? Multiplexing l&#224; g&#236;?</h1><blockquote><p>HTTP/2 kh&#244;ng thay TCP. HTTP/2 ch&#7881; thay <strong>c&#225;ch t&#7893; ch&#7913;c d&#7919; li&#7879;u &#7903; t&#7847;ng HTTP</strong> tr&#432;&#7899;c khi &#273;&#432;a xu&#7889;ng TCP.</p><p>C&#417; ch&#7871; m&#7899;i c&#7911;a HTTP/2: <strong>Multiplexing qua Stream &#8594; Frame</strong></p></blockquote><ul><li><p>M&#7897;t TCP connection duy nh&#7845;t</p></li><li><p>Trong &#273;&#243; c&#243; <strong>nhi&#7873;u stream</strong> (nh&#432; nhi&#7873;u l&#224;n &#273;&#432;&#7901;ng &#7843;o)</p></li><li><p>M&#7895;i stream g&#7917;i <strong>nhi&#7873;u frame</strong> nh&#7887; (g&#243;i con)</p></li><li><p>C&#225;c frame thu&#7897;c c&#225;c stream <strong>&#273;&#432;&#7907;c tr&#7897;n l&#7851;n khi g&#7917;i</strong>, kh&#244;ng ph&#7843;i ch&#7901; nhau</p></li><li><p>T&#7841;i ph&#237;a nh&#7853;n, HTTP/2 gh&#233;p l&#7841;i frame th&#224;nh &#273;&#250;ng request/response t&#432;&#417;ng &#7913;ng.</p></li></ul><blockquote><p>T&#7847;ng TCP v&#7851;n &#273;i tu&#7847;n t&#7921;, nh&#432;ng <strong>kh&#244;ng c&#242;n chuy&#7879;n ch&#7901; nhau &#7903; t&#7847;ng HTTP</strong>, v&#236; c&#225;c request &#273;&#432;&#7907;c &#8220;tr&#432;&#7907;t qua nhau&#8221; &#7903; d&#7841;ng frame.</p></blockquote><p><strong>H&#236;nh dung:</strong><br>M&#7897;t l&#224;n &#273;&#432;&#7901;ng th&#7853;t (TCP). Tr&#234;n &#273;&#243; v&#7869; ra h&#224;ng ch&#7909;c &#8220;l&#224;n &#7843;o&#8221; (stream). Xe c&#7911;a m&#7895;i ng&#432;&#7901;i &#273;&#432;&#7907;c chia th&#224;nh nhi&#7873;u th&#249;ng h&#224;ng nh&#7887; (frame). C&#225;c th&#249;ng h&#224;ng l&#7851;n nhau, &#273;i chung l&#224;n nh&#432;ng &#273;&#7873;u c&#243; g&#7855;n ID &#8594; t&#7899;i n&#417;i l&#7855;p l&#7841;i th&#224;nh t&#7915;ng ki&#7879;n ri&#234;ng.<br>=&gt; <strong>HOL &#7903; t&#7847;ng HTTP bi&#7871;n m&#7845;t.</strong></p><div><hr></div><h1>C&#225;c t&#7889;i &#432;u quan tr&#7885;ng kh&#225;c c&#7911;a HTTP/2</h1><p>Ngo&#224;i multiplexing, HTTP/2 c&#242;n c&#243;:</p><h2>Stream prioritization (&#432;u ti&#234;n lu&#7891;ng)</h2><p>B&#7841;n c&#243; th&#7875; n&#243;i v&#7899;i server:</p><ul><li><p>&#8220;Lu&#7891;ng n&#224;y quan tr&#7885;ng, g&#7917;i tr&#432;&#7899;c.&#8221;</p></li><li><p>&#8220;Lu&#7891;ng kia g&#7917;i sau.&#8221;</p></li></ul><p>&#272;i&#7873;u n&#224;y gi&#250;p:</p><ul><li><p>T&#7843;i CSS tr&#432;&#7899;c h&#236;nh &#7843;nh</p></li><li><p>T&#7843;i thumbnail tr&#432;&#7899;c &#7843;nh full HD</p></li><li><p>React hydration tr&#432;&#7899;c t&#7843;i analytics</p></li></ul><h2>Header Compression (HPACK)</h2><p>Gi&#7843;m dung l&#432;&#7907;ng header b&#7857;ng dictionary + incremental encoding.<br>Ti&#7871;t ki&#7879;m c&#7921;c m&#7841;nh v&#236; header HTTP th&#432;&#7901;ng l&#7863;p r&#7845;t nhi&#7873;u.</p><h2>Server Push</h2><blockquote><p>&#272;&#227; b&#7883; b&#7887; &#7903; HTTP/3 nh&#432;ng l&#224; &#273;i&#7875;m hay c&#7911;a HTTP/2</p></blockquote><p>Server c&#243; th&#7875; g&#7917;i tr&#432;&#7899;c t&#224;i nguy&#234;n m&#224; client s&#7855;p c&#7847;n, kh&#244;ng ch&#7901; client request.</p><h1>Tham kh&#7843;o</h1><p>https://viblo.asia/p/http11-va-http2-dau-la-su-khac-biet-YWOZrj27ZQ0</p>]]></content:encoded></item><item><title><![CDATA[HTTP Lifecycle]]></title><description><![CDATA[V&#242;ng &#273;&#7901;i c&#7911;a request ch&#237;nh l&#224; &#8220;t&#7845;m b&#7843;n &#273;&#7891;&#8221; m&#224; m&#7885;i backend engineer n&#234;n thu&#7897;c n&#7857;m l&#242;ng]]></description><link>https://tiendatengineer.substack.com/p/http-lifecycle</link><guid isPermaLink="false">https://tiendatengineer.substack.com/p/http-lifecycle</guid><dc:creator><![CDATA[Nguyễn Doãn Tiến Đạt]]></dc:creator><pubDate>Thu, 11 Dec 2025 07:57:05 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/7e5b66b9-6030-4093-983b-289452cdca29_770x433.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<blockquote><p>Khi b&#7841;n g&#245; m&#7897;t URL ho&#7863;c khi backend g&#7885;i m&#7897;t API n&#7897;i b&#7897;, m&#7885;i th&#7913; c&#243; v&#7867; &#273;&#417;n gi&#7843;n: <em>g&#7917;i request &#8211; nh&#7853;n response</em>. Nh&#432;ng th&#7921;c t&#7871;, &#273;&#7857;ng sau &#273;&#243; l&#224; m&#7897;t <strong>chu&#7895;i x&#7917; l&#253; ph&#7913;c t&#7841;p</strong> &#273;i qua h&#224;ng lo&#7841;t l&#7899;p m&#7841;ng, proxy, middleware v&#224; logic &#7913;ng d&#7909;ng.</p><p>Hi&#7875;u r&#245; <em>HTTP Request Lifecycle</em> kh&#244;ng ch&#7881; l&#224; ki&#7871;n th&#7913;c n&#7873;n t&#7843;ng &#8212; m&#224; c&#242;n gi&#250;p b&#7841;n:</p><ul><li><p>Debug ch&#237;nh x&#225;c request &#273;ang k&#7865;t &#7903; &#273;&#226;u</p></li><li><p>Gi&#7843;m latency v&#224; t&#7889;i &#432;u hi&#7879;u n&#259;ng</p></li><li><p>X&#225;c &#273;&#7883;nh &#273;&#250;ng l&#7899;p ch&#7883;u tr&#225;ch nhi&#7879;m khi x&#7843;y ra l&#7895;i ho&#7863;c timeout</p></li><li><p>Thi&#7871;t k&#7871; h&#7879; th&#7889;ng v&#224; microservices ch&#7855;c ch&#7855;n h&#417;n</p></li></ul><p>B&#224;i vi&#7871;t n&#224;y s&#7869; &#273;i qua to&#224;n b&#7897; v&#242;ng &#273;&#7901;i &#273;&#243;, theo &#273;&#250;ng h&#224;nh tr&#236;nh m&#224; m&#7897;t request th&#7921;c s&#7921; tr&#7843;i qua.</p></blockquote><h1>1. To&#224;n B&#7897; H&#224;nh Tr&#236;nh</h1><p><strong>Client &#8594; DNS &#8594; TCP/TLS &#8594; Reverse Proxy &#8594; HTTP Server &#8594; Middleware &#8594; Routing &#8594; Handler &#8594; Business Logic &#8594; Response</strong></p><p>D&#432;&#7899;i &#273;&#226;y l&#224; m&#244; t&#7843; chi ti&#7871;t t&#7915;ng b&#432;&#7899;c:</p><div><hr></div><h2>Client</h2><p>Tr&#236;nh duy&#7879;t ho&#7863;c &#7913;ng d&#7909;ng g&#7917;i y&#234;u c&#7847;u HTTP bao g&#7891;m: method (GET/POST/&#8230;), URL, headers, body (n&#7871;u c&#243;).</p><div><hr></div><h2>DNS</h2><p>Chuy&#7875;n hostname (v&#237; d&#7909;: <code>api.example.com</code>) th&#224;nh &#273;&#7883;a ch&#7881; IP. N&#7871;u DNS ch&#7853;m &#8594; request b&#7883; delay ngay t&#7915; b&#432;&#7899;c &#273;&#7847;u.</p><div><hr></div><h2>TCP / TLS Handshake</h2><ul><li><p>TCP: Thi&#7871;t l&#7853;p k&#7871;t n&#7889;i (SYN &#8594; SYN/ACK &#8594; ACK).</p></li><li><p>TLS: N&#7871;u HTTPS, di&#7877;n ra th&#234;m handshake &#273;&#7875; t&#7841;o k&#234;nh m&#227; ho&#225;.</p></li></ul><div><hr></div><h2>Reverse Proxy (Nginx / Envoy / HAProxy)</h2><p>&#272;i&#7875;m v&#224;o &#273;&#7847;u ti&#234;n c&#7911;a backend. Proxy c&#243; th&#7875; x&#7917; l&#253;:</p><ul><li><p>SSL termination (gi&#7843;i m&#227; HTTPS)</p></li><li><p>Rate limit</p></li><li><p>Load balancing</p></li><li><p>Routing c&#417; b&#7843;n theo path/host</p></li><li><p>Caching</p></li><li><p>Logging</p></li></ul><p>Sau &#273;&#243;, request &#273;&#432;&#7907;c forward v&#224;o service backend th&#7921;c s&#7921;.</p><div><hr></div><h2>HTTP Server (b&#234;n trong &#7913;ng d&#7909;ng)</h2><p>V&#237; d&#7909;: Go <code>net/http</code>, Node.js <code>Express</code>, Java <code>Spring</code>, Python <code>FastAPI</code>.<br>Nhi&#7879;m v&#7909;:</p><ul><li><p>Parse request</p></li><li><p>T&#7841;o request object</p></li><li><p>&#272;i&#7873;u ph&#7889;i middleware v&#224; routing</p></li></ul><div><hr></div><h2>Middleware</h2><p>C&#225;c l&#7899;p ch&#7841;y tr&#432;&#7899;c ho&#7863;c sau handler:</p><ul><li><p>Logging</p></li><li><p>Authentication / Authorization</p></li><li><p>CORS</p></li><li><p>Panic recovery</p></li><li><p>Body limit</p></li><li><p>Rate limit c&#7845;p &#7913;ng d&#7909;ng</p></li></ul><p>Middleware qu&#225; nhi&#7873;u &#8594; t&#259;ng th&#7901;i gian x&#7917; l&#253; v&#224; memory footprint.</p><div><hr></div><h2>Routing</h2><p>So kh&#7899;p method + path &#273;&#7875; ch&#7885;n &#273;&#250;ng handler.<br>C&#225;c framework hi&#7879;n &#273;&#7841;i d&#249;ng <strong>trie-based router</strong> &#273;&#7875; t&#259;ng t&#7889;c.</p><div><hr></div><h2>Handler (Controller)</h2><p>Nh&#7853;n request, validate input, &#225;nh x&#7841; v&#7873; business logic.</p><div><hr></div><h2>Business Logic</h2><p>Ph&#7847;n x&#7917; l&#253; ch&#237;nh c&#7911;a &#7913;ng d&#7909;ng:</p><ul><li><p>Query database</p></li><li><p>G&#7885;i cache (Redis, Memcached)</p></li><li><p>G&#7885;i API n&#7897;i b&#7897; ho&#7863;c b&#234;n th&#7913; ba</p></li><li><p>X&#7917; l&#253; nghi&#7879;p v&#7909;</p></li><li><p>Mapping d&#7919; li&#7879;u</p></li></ul><p>&#272;&#226;y l&#224; n&#417;i quy&#7871;t &#273;&#7883;nh ph&#7847;n l&#7899;n performance c&#7911;a h&#7879; th&#7889;ng.</p><div><hr></div><h2>Response</h2><p>K&#7871;t qu&#7843; &#273;&#432;&#7907;c serialize (JSON, protobuf&#8230;)<br>v&#224; g&#7917;i ng&#432;&#7907;c l&#7841;i qua c&#249;ng k&#7871;t n&#7889;i TCP/TLS v&#7873; client.</p><div><hr></div><h1>2. C&#225;c lo&#7841;i Timeout &#8211; Request c&#243; th&#7875; ch&#7871;t &#7903; &#273;&#226;u?</h1><p>M&#7897;t trong nh&#7919;ng l&#7907;i &#237;ch l&#7899;n nh&#7845;t c&#7911;a vi&#7879;c hi&#7875;u lifecycle l&#224; bi&#7871;t timeout n&#7857;m &#7903; l&#7899;p n&#224;o.</p><h2>DNS timeout</h2><p>Kh&#244;ng resolve &#273;&#432;&#7907;c hostname.</p><h2>TCP connect timeout</h2><p>Kh&#244;ng thi&#7871;t l&#7853;p &#273;&#432;&#7907;c k&#7871;t n&#7889;i (server down, firewall ch&#7863;n).</p><h2>TLS handshake timeout</h2><p>Kh&#244;ng b&#7855;t tay TLS xong.</p><h2>Reverse proxy timeout</h2><ul><li><p>upstream timeout</p></li><li><p>idle timeout</p></li><li><p>read/write timeout</p></li></ul><p>(V&#237; d&#7909;: <code>upstream timed out</code> trong Nginx)</p><h2>Application timeout</h2><p>Framework HTTP server gi&#7899;i h&#7841;n th&#7901;i gian x&#7917; l&#253;.</p><h2>Context timeout trong handler</h2><p>Backend t&#7921; cancel x&#7917; l&#253;: <code>context deadline exceeded</code></p><h2>Database timeout</h2><p>Query qu&#225; l&#226;u &#8594; &#7843;nh h&#432;&#7903;ng c&#7843; request.</p><p><strong>M&#7897;t request c&#243; th&#7875; ch&#7871;t &#7903; r&#7845;t nhi&#7873;u &#273;i&#7875;m &#8212; hi&#7875;u &#273;&#250;ng l&#7899;p l&#224; ch&#236;a kh&#243;a &#273;&#7875; debug.</strong></p><div><hr></div><h1>3. C&#225;c &#273;i&#7875;m t&#7889;i &#432;u trong to&#224;n b&#7897; lifecycle</h1><h2>DNS</h2><ul><li><p>B&#7853;t DNS caching</p></li><li><p>S&#7917; d&#7909;ng DNS resolver nhanh (Cloudflare 1.1.1.1)</p></li></ul><h2>TCP/TLS</h2><ul><li><p>Gi&#7919; k&#7871;t n&#7889;i l&#226;u h&#417;n b&#7857;ng Keep-alive</p></li><li><p>B&#7853;t HTTP/2 ho&#7863;c HTTP/3</p></li><li><p>TLS session resumption &#273;&#7875; gi&#7843;m handshake</p></li></ul><h2>Reverse Proxy</h2><ul><li><p>T&#7889;i &#432;u buffer</p></li><li><p>B&#7853;t gzip/brotli</p></li><li><p>Tinh ch&#7881;nh timeout h&#7907;p l&#253;</p></li><li><p>Cache response t&#297;nh</p></li></ul><h2>Middleware</h2><ul><li><p>Ch&#7881; gi&#7919; nh&#7919;ng middleware c&#7847;n thi&#7871;t</p></li><li><p>Kh&#244;ng l&#224;m DB/API call b&#234;n trong middleware</p></li></ul><h2>Routing</h2><ul><li><p>D&#249;ng router hi&#7879;u qu&#7843; (Gin, Fiber, FastAPI&#8230;)</p></li><li><p>Tr&#225;nh dynamic regex routing n&#7863;ng</p></li></ul><h2>Business Logic</h2><ul><li><p>T&#7889;i &#432;u query DB (index, limit, tr&#225;nh N+1)</p></li><li><p>Cache th&#244;ng minh</p></li><li><p>Gi&#7843;m external call ho&#7863;c d&#249;ng bulk request</p></li><li><p>H&#7841;n ch&#7871; serialize object kh&#7893;ng l&#7891;</p></li></ul><h2>Response</h2><ul><li><p>Tr&#225;nh response qu&#225; n&#7863;ng</p></li><li><p>D&#249;ng json encoder hi&#7879;u qu&#7843; (v&#237; d&#7909;: <code>jsoniter</code> cho Go)</p></li></ul><div><hr></div><h1>4. S&#417; &#273;&#7891; t&#7893;ng quan</h1><pre><code><code>Client
  &#8595;
DNS
  &#8595;
TCP Handshake
  &#8595;
TLS Handshake (HTTPS)
  &#8595;
Reverse Proxy (Nginx/Envoy)
  &#8595;
Application HTTP Server
  &#8595;
Middleware Chain
  &#8595;
Router
  &#8595;
Handler / Controller
  &#8595;
Business Logic
  &#8595;
Response &#8594; Client
</code></code></pre><div><hr></div><h1>5. K&#7871;t lu&#7853;n</h1><p>M&#7897;t request HTTP kh&#244;ng &#273;&#417;n gi&#7843;n ch&#7881; l&#224; &#8220;g&#7885;i API&#8221;. N&#243; &#273;i qua r&#7845;t nhi&#7873;u l&#7899;p &#8212; t&#7915; DNS, TCP, TLS &#273;&#7871;n proxy, middleware v&#224; business logic.<br>Hi&#7875;u r&#245; t&#7915;ng l&#7899;p gi&#250;p b&#7841;n:</p><ul><li><p>Debug nhanh h&#417;n</p></li><li><p>Thi&#7871;t k&#7871; h&#7879; th&#7889;ng ch&#7855;c ch&#7855;n h&#417;n</p></li><li><p>T&#7889;i &#432;u hi&#7879;u n&#259;ng &#273;&#250;ng ch&#7895;</p></li><li><p>Tr&#225;nh timeout v&#224; bottleneck kh&#243; &#273;o&#225;n</p></li></ul>]]></content:encoded></item><item><title><![CDATA[TCP và UDP]]></title><description><![CDATA[TCP v&#224; UDP l&#224; hai giao th&#7913;c thu&#7897;c t&#7847;ng v&#7853;n chuy&#7875;n trong m&#244; h&#236;nh TCP/IP. Ch&#250;ng quy&#7871;t &#273;&#7883;nh c&#225;ch d&#7919; li&#7879;u &#273;&#432;&#7907;c g&#7917;i t&#7915; m&#225;y n&#224;y sang m&#225;y kh&#225;c tr&#234;n Internet.]]></description><link>https://tiendatengineer.substack.com/p/tcp-vs-udp</link><guid isPermaLink="false">https://tiendatengineer.substack.com/p/tcp-vs-udp</guid><dc:creator><![CDATA[Nguyễn Doãn Tiến Đạt]]></dc:creator><pubDate>Thu, 11 Dec 2025 07:35:30 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/6bea2701-0a5e-4a44-8152-0016b24652f0_1200x675.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>TCP (Transmission Control Protocol)</h1><div class="pullquote"><p><strong>Giao th&#7913;c &#8220;&#273;&#7843;m b&#7843;o, c&#7849;n th&#7853;n, ch&#7853;m m&#224; ch&#7855;c&#8221;</strong></p></div><p>TCP cung c&#7845;p:</p><ul><li><p><strong>Connection-oriented</strong> &#8211; ph&#7843;i b&#7855;t tay (3-way handshake) tr&#432;&#7899;c khi g&#7917;i.</p></li><li><p><strong>Reliable</strong> &#8211; b&#7843;o &#273;&#7843;m d&#7919; li&#7879;u &#273;&#7871;n &#273;&#7911;, &#273;&#250;ng th&#7913; t&#7921;.</p></li><li><p><strong>Flow control / Congestion control</strong> &#8211; t&#7921; &#273;i&#7873;u ch&#7881;nh t&#7889;c &#273;&#7897; g&#7917;i &#273;&#7875; tr&#225;nh ngh&#7869;n m&#7841;ng.</p></li><li><p><strong>Retransmission</strong> &#8211; g&#243;i m&#7845;t s&#7869; &#273;&#432;&#7907;c g&#7917;i l&#7841;i.</p></li></ul><p>&#128073; <strong>Th&#237;ch h&#7907;p cho</strong>: web, API, database, file transfer, email&#8212;n&#417;i d&#7919; li&#7879;u ph&#7843;i ch&#237;nh x&#225;c tuy&#7879;t &#273;&#7889;i.</p><div><hr></div><h1>UDP (User Datagram Protocol)</h1><div class="pullquote"><p><strong>Giao th&#7913;c &#8220;nhanh, nh&#7865;, kh&#244;ng &#273;&#7843;m b&#7843;o&#8221;</strong></p></div><p>UDP c&#243;:</p><ul><li><p><strong>Connectionless</strong> &#8211; g&#7917;i th&#7859;ng, kh&#244;ng c&#7847;n handshake.</p></li><li><p><strong>Kh&#244;ng &#273;&#7843;m b&#7843;o</strong> &#8211; m&#7845;t g&#243;i, tr&#249;ng g&#243;i, sai th&#7913; t&#7921; &#273;&#7873;u c&#243; th&#7875; x&#7843;y ra.</p></li><li><p><strong>Kh&#244;ng ki&#7875;m so&#225;t d&#242;ng / t&#7855;c ngh&#7869;n</strong> &#8211; t&#7889;c &#273;&#7897; g&#7917;i tu&#7923; &#7913;ng d&#7909;ng.</p></li><li><p><strong>&#272;&#7897; tr&#7877; r&#7845;t th&#7845;p</strong> &#8211; v&#236; kh&#244;ng t&#7889;n chi ph&#237; ki&#7875;m tra tr&#7841;ng th&#225;i.</p></li></ul><p>&#128073; <strong>Th&#237;ch h&#7907;p cho</strong>: video call, live stream, game real-time, DNS, IoT&#8212;n&#417;i quan tr&#7885;ng <strong>t&#7889;c &#273;&#7897; h&#417;n &#273;&#7897; ch&#237;nh x&#225;c</strong>.</p>]]></content:encoded></item><item><title><![CDATA[Kiến trúc máy tính]]></title><description><![CDATA[M&#7897;t ch&#432;&#417;ng tr&#236;nh ho&#7841;t &#273;&#7897;ng nh&#432; th&#7871; n&#224;o b&#234;n trong m&#225;y t&#237;nh? T&#7845;t c&#7843; b&#7855;t &#273;&#7847;u khi h&#7879; &#273;i&#7873;u h&#224;nh n&#7841;p n&#243; v&#224;o RAM &#273;&#7875; CPU th&#7921;c thi &#8212; v&#224; c&#242;n nhi&#7873;u &#273;i&#7873;u th&#250; v&#7883; ph&#237;a sau.]]></description><link>https://tiendatengineer.substack.com/p/kien-truc-may-tinh</link><guid isPermaLink="false">https://tiendatengineer.substack.com/p/kien-truc-may-tinh</guid><dc:creator><![CDATA[Nguyễn Doãn Tiến Đạt]]></dc:creator><pubDate>Fri, 05 Dec 2025 09:21:04 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/a501d3ed-8018-4ce0-b4de-dbdca6571513_1299x921.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uEgh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c458360-aa8e-4f49-869c-133bcde587cf_800x450.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uEgh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c458360-aa8e-4f49-869c-133bcde587cf_800x450.jpeg 424w, https://substackcdn.com/image/fetch/$s_!uEgh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c458360-aa8e-4f49-869c-133bcde587cf_800x450.jpeg 848w, https://substackcdn.com/image/fetch/$s_!uEgh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c458360-aa8e-4f49-869c-133bcde587cf_800x450.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!uEgh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c458360-aa8e-4f49-869c-133bcde587cf_800x450.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uEgh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c458360-aa8e-4f49-869c-133bcde587cf_800x450.jpeg" width="800" height="450" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4c458360-aa8e-4f49-869c-133bcde587cf_800x450.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:450,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Kh&#225;i ni&#7879;m c&#417; b&#7843;n v&#7873; t&#7893; ch&#7913;c, ki&#7871;n tr&#250;c m&#225;y t&#237;nh v&#224; c&#225;c thu&#7853;t ng&#7919;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Kh&#225;i ni&#7879;m c&#417; b&#7843;n v&#7873; t&#7893; ch&#7913;c, ki&#7871;n tr&#250;c m&#225;y t&#237;nh v&#224; c&#225;c thu&#7853;t ng&#7919;" title="Kh&#225;i ni&#7879;m c&#417; b&#7843;n v&#7873; t&#7893; ch&#7913;c, ki&#7871;n tr&#250;c m&#225;y t&#237;nh v&#224; c&#225;c thu&#7853;t ng&#7919;" srcset="https://substackcdn.com/image/fetch/$s_!uEgh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c458360-aa8e-4f49-869c-133bcde587cf_800x450.jpeg 424w, https://substackcdn.com/image/fetch/$s_!uEgh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c458360-aa8e-4f49-869c-133bcde587cf_800x450.jpeg 848w, https://substackcdn.com/image/fetch/$s_!uEgh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c458360-aa8e-4f49-869c-133bcde587cf_800x450.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!uEgh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4c458360-aa8e-4f49-869c-133bcde587cf_800x450.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h1>Ki&#7871;n tr&#250;c m&#225;y t&#237;nh l&#224; g&#236;?</h1><blockquote><p><strong>Ki&#7871;n tr&#250;c m&#225;y t&#237;nh</strong> l&#224; c&#225;ch m&#224; m&#7897;t m&#225;y t&#237;nh &#273;&#432;&#7907;c t&#7893; ch&#7913;c &#273;&#7875;:</p></blockquote><ul><li><p>Nh&#7853;n l&#7879;nh</p></li><li><p>X&#7917; l&#253;</p></li><li><p>L&#432;u tr&#7919;</p></li><li><p>Giao ti&#7871;p v&#7899;i thi&#7871;t b&#7883; b&#234;n ngo&#224;i</p></li></ul><div><hr></div><h1>4 th&#224;nh ph&#7847;n c&#7889;t l&#245;i</h1><h2>CPU (B&#7897; x&#7917; l&#253; trung t&#226;m)</h2><ul><li><p>Th&#7921;c thi c&#226;u l&#7879;nh</p></li><li><p>G&#7891;m:</p><ul><li><p><strong>ALU</strong>: x&#7917; l&#253; t&#237;nh to&#225;n</p></li><li><p><strong>Control Unit</strong>: &#273;i&#7873;u khi&#7875;n</p></li><li><p><strong>Registers</strong>: b&#7897; nh&#7899; si&#234;u nhanh trong CPU</p></li></ul></li></ul><blockquote><p><strong>CPU l&#224; b&#7897; n&#227;o</strong></p></blockquote><div><hr></div><h2>Memory (B&#7897; nh&#7899;)</h2><p><strong>Th&#7913; t&#7921; t&#7915; nhanh &#8594; ch&#7853;m:</strong></p><ol><li><p>Register</p></li><li><p>Cache (L1, L2, L3)</p></li><li><p>RAM</p></li><li><p>SSD / HDD</p></li></ol><blockquote><p>C&#224;ng nhanh th&#236; c&#224;ng <strong>nh&#7887; &amp; &#273;&#7855;t</strong></p></blockquote><div><hr></div><h2>Storage (L&#432;u tr&#7919;)</h2><ul><li><p>HDD, SSD</p></li><li><p>L&#432;u d&#7919; li&#7879;u l&#226;u d&#224;i</p></li><li><p>Ch&#7853;m h&#417;n RAM r&#7845;t nhi&#7873;u</p></li></ul><div><hr></div><h2>I/O (Input / Output)</h2><ul><li><p>B&#224;n ph&#237;m, chu&#7897;t, m&#7841;ng, &#7893; &#273;&#297;a</p></li><li><p>Giao ti&#7871;p gi&#7919;a m&#225;y v&#224; th&#7871; gi&#7899;i b&#234;n ngo&#224;i</p></li></ul><div><hr></div><h1>Chu tr&#236;nh CPU x&#7917; l&#253; 1 l&#7879;nh</h1><blockquote><p><strong>Fetch &#8594; Decode &#8594; Execute</strong></p></blockquote><ol><li><p>Fetch: l&#7845;y l&#7879;nh t&#7915; RAM</p></li><li><p>Decode: gi&#7843;i m&#227; l&#7879;nh</p></li><li><p>Execute: th&#7921;c thi</p></li></ol><p>Chu tr&#236;nh n&#224;y l&#7863;p l&#7841;i <strong>h&#224;ng t&#7927; l&#7847;n m&#7895;i gi&#226;y</strong>.</p><div><hr></div><h1>Process &amp; Thread trong ki&#7871;n tr&#250;c</h1><ul><li><p><strong>Process</strong>:</p><ul><li><p>C&#243; b&#7897; nh&#7899; ri&#234;ng</p></li><li><p>Ch&#7841;y &#273;&#7897;c l&#7853;p</p></li></ul></li><li><p><strong>Thread</strong>:</p><ul><li><p>N&#7857;m trong process</p></li><li><p>D&#249;ng chung b&#7897; nh&#7899;</p></li></ul></li></ul><p><strong>Backend server th&#432;&#7901;ng:</strong></p><ul><li><p>1 service = 1 process</p></li><li><p>M&#7895;i request = 1 thread / goroutine</p></li></ul><h1>M&#7897;t ch&#432;&#417;ng tr&#236;nh ho&#7841;t &#273;&#7897;ng nh&#432; th&#7871; n&#224;o?</h1><p>Gi&#7843; s&#7917; ch&#250;ng ta &#273;&#227; x&#226;y d&#7921;ng xong m&#7897;t ch&#432;&#417;ng tr&#236;nh vi&#7871;t b&#7857;ng Golang, v&#7853;y &#273;&#7875; ch&#432;&#417;ng tr&#236;nh n&#224;y ch&#7841;y, ch&#250;ng s&#7869; tr&#7843;i qua nh&#7919;ng b&#432;&#7899;c g&#236;? H&#227;y c&#249;ng t&#236;m hi&#7875;u.</p><h2>T&#7915; ch&#432;&#417;ng tr&#236;nh Go &#8594; CPU th&#7921;c thi: to&#224;n b&#7897; qu&#225; tr&#236;nh</h2><p>Gi&#7843; s&#7917; b&#7841;n c&#243; file: <code>main.go, </code>v&#224; b&#7841;n &#273;&#227; build xong binary v&#7899;i: <code>go build</code></p><p>B&#226;y gi&#7901;, <strong>&#273;&#7875; ch&#432;&#417;ng tr&#236;nh Go ch&#7841;y</strong>, m&#225;y t&#237;nh s&#7869; tr&#7843;i qua 5 giai &#273;o&#7841;n t&#432;&#417;ng &#7913;ng v&#7899;i c&#225;c th&#224;nh ph&#7847;n trong ki&#7871;n tr&#250;c m&#225;y t&#237;nh.</p><div><hr></div><h2>&#7892; &#273;&#297;a (SSD/HDD) &#8594; L&#432;u binary</h2><p>Sau khi build, b&#7841;n c&#243; file: <code>./myapp</code></p><p>N&#243; n&#7857;m <strong>trong &#7893; &#273;&#297;a</strong>, gi&#7889;ng nh&#432; t&#224;i li&#7879;u &#273;ang n&#7857;m trong kho. L&#250;c n&#224;y ch&#432;&#417;ng tr&#236;nh <em>ch&#432;a &#273;&#432;&#7907;c ch&#7841;y</em>, ch&#432;a &#7903; RAM, ch&#432;a d&#249;ng CPU.</p><div><hr></div><h2>OS nh&#7853;n l&#7879;nh ch&#7841;y ch&#432;&#417;ng tr&#236;nh &#8594; T&#7841;o Process m&#7899;i</h2><p>Khi b&#7841;n ch&#7841;y: <code>./myapp. </code><strong>OS (Linux/Windows)</strong> v&#224;o cu&#7897;c.</p><p>OS th&#7921;c hi&#7879;n:</p><ol><li><p><strong>T&#7841;o m&#7897;t Process</strong></p></li><li><p>C&#7845;p cho process n&#224;y:</p><ul><li><p>v&#249;ng <strong>RAM ri&#234;ng</strong></p></li><li><p><strong>stack</strong> v&#224; <strong>heap</strong></p></li><li><p>danh s&#225;ch <strong>file descriptor</strong></p></li><li><p>quy&#7873;n truy c&#7853;p h&#7879; th&#7889;ng</p></li></ul></li></ol><blockquote><p>&#272;&#226;y l&#224; l&#250;c ch&#432;&#417;ng tr&#236;nh &#8220;&#273;&#432;&#7907;c sinh ra&#8221; trong h&#7879; th&#7889;ng.</p></blockquote><div><hr></div><h2>OS t&#7843;i binary t&#7915; &#7893; &#273;&#297;a &#8594; RAM</h2><p>OS &#273;&#7885;c file <code>./myapp</code> t&#7915; SSD/HDD v&#224; <strong>copy v&#224;o RAM</strong>.</p><ul><li><p>RAM nhanh h&#417;n &#7893; &#273;&#297;a h&#224;ng ng&#224;n l&#7847;n</p></li><li><p>CPU ch&#7881; c&#243; th&#7875; l&#7845;y l&#7879;nh t&#7915; RAM, kh&#244;ng th&#7875; &#273;&#7885;c tr&#7921;c ti&#7871;p t&#7915; &#7893; &#273;&#297;a</p></li></ul><p>&#10145;&#65039; &#272;&#226;y l&#224; b&#432;&#7899;c: <strong>Load &#8594; Decode &#8594; Prepare</strong></p><div><hr></div><h2>CPU b&#7855;t &#273;&#7847;u th&#7921;c thi &#8594; Go Runtime kh&#7903;i &#273;&#7897;ng tr&#432;&#7899;c</h2><p>Khi ch&#432;&#417;ng tr&#236;nh &#273;&#227; n&#7857;m trong RAM, <strong>CPU b&#7855;t &#273;&#7847;u ch&#7841;y</strong>. Nh&#432;ng CPU <strong>kh&#244;ng ch&#7841;y </strong><code>main()</code><strong> ngay</strong>. N&#243; ch&#7841;y <strong>Go Runtime</strong> tr&#432;&#7899;c, v&#236; Go binary lu&#244;n mang theo runtime nh&#7865;.</p><p>Go runtime s&#7869;:</p><ul><li><p>kh&#7903;i t&#7841;o <strong>garbage collector</strong></p></li><li><p>t&#7841;o <strong>scheduler</strong> cho goroutine (M:N)</p></li><li><p>set s&#7889; l&#432;&#7907;ng OS threads (GOMAXPROCS)</p></li><li><p>kh&#7903;i t&#7841;o b&#7897; c&#7845;p ph&#225;t b&#7897; nh&#7899; (allocator)</p></li><li><p>chu&#7849;n b&#7883; network poller</p></li></ul><p>&#10145;&#65039; Sau khi runtime &#273;&#7911; &#273;i&#7873;u ki&#7879;n &#8594; <strong>g&#7885;i v&#224;o h&#224;m </strong><code>main.main()</code></p><div><hr></div><h2>Ch&#432;&#417;ng tr&#236;nh Go ch&#7841;y &#8594; T&#432;&#417;ng t&#225;c v&#7899;i OS, CPU, RAM</h2><p>T&#7915; &#273;&#226;y ch&#432;&#417;ng tr&#236;nh ho&#7841;t &#273;&#7897;ng nh&#432; sau:</p><p><strong>Khi ch&#7841;y logic trong Go: </strong>CPU th&#7921;c thi t&#7915;ng instruction trong RAM.</p><p><strong>Khi b&#7841;n t&#7841;o goroutine: </strong>Go scheduler s&#7869;:</p><ul><li><p>gom h&#224;ng ngh&#236;n goroutine</p></li><li><p>ph&#226;n ph&#7889;i l&#234;n m&#7897;t v&#224;i OS thread</p></li><li><p>chuy&#7875;n &#273;&#7893;i c&#7921;c nhanh m&#224; kh&#244;ng c&#7847;n OS can thi&#7879;p</p></li></ul><p><strong>Khi b&#7841;n &#273;&#7885;c file, g&#7885;i API, sleep&#8230;: </strong>Go runtime d&#249;ng <strong>system call</strong> &#273;&#7875; nh&#7901; OS l&#224;m gi&#250;p.</p><p>V&#237; d&#7909;: <code>fmt.Println(&#8221;Hello&#8221;)</code></p><p>Flow: <code>Go fmt &#8594; Go runtime &#8594; syscall write &#8594; OS &#8594; stdout</code></p><div><hr></div><h2>G&#243;c nh&#236;n t&#7893;ng th&#7875; &#8211; li&#234;n k&#7871;t v&#7899;i ki&#7871;n tr&#250;c m&#225;y t&#237;nh</h2><p>D&#432;&#7899;i &#273;&#226;y l&#224; <strong>s&#417; &#273;&#7891; ch&#237;nh x&#225;c qu&#225; tr&#236;nh</strong>:</p><pre><code><code>(1) Go Code (.go files)
        &#8595;
go build &#8594; compiler &#8594; binary (machine code)
        &#8595;
(2) Binary n&#7857;m trong &#7893; &#273;&#297;a (SSD/HDD)
        &#8595;
(3) OS t&#7841;o Process &#8594; c&#7845;p RAM/Thread
        &#8595;
(4) OS load binary v&#224;o RAM
        &#8595;
(5) CPU b&#7855;t &#273;&#7847;u ch&#7841;y &#8594; Go runtime kh&#7903;i &#273;&#7897;ng
        &#8595;
(6) main() ch&#7841;y
        &#8595;
(7) Ch&#432;&#417;ng tr&#236;nh t&#432;&#417;ng t&#225;c:
      - CPU: ch&#7841;y l&#7879;nh
      - RAM: l&#432;u d&#7919; li&#7879;u
      - OS: syscall (file, network, socket)
      - hardware: network card, disk, GPU</code></code></pre><div><hr></div><h2>T&#243;m l&#7841;i</h2><blockquote><p><strong>Golang build th&#224;nh binary, OS n&#7841;p binary v&#224;o RAM, CPU ch&#7841;y binary v&#7899;i s&#7921; h&#7895; tr&#7907; c&#7911;a Go runtime, v&#224; m&#7885;i I/O &#273;&#7873;u qua OS.</strong></p></blockquote>]]></content:encoded></item></channel></rss>