<?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"><channel><title><![CDATA[Wei-Ming's Blog]]></title><description><![CDATA[Share knowledge about software engineer. Believe sharing can change the world.]]></description><link>https://wei-ming.tw</link><generator>GatsbyJS</generator><lastBuildDate>Sat, 22 Oct 2022 09:39:17 GMT</lastBuildDate><item><title><![CDATA[Storage and Retrieval (3) - Column-based storage engine]]></title><description><![CDATA[while the analytical requirement arise in large companies, the performance for aggregating large scale data gradually cannot be accepted by using row-based storage engine. Column-based storage engines were developed for optimizing analytical requirement. They have huge improvement while query large portion of data on few columns. In this article we will talk more about its core concept.]]></description><link>https://wei-ming.tw/posts/column-based</link><guid isPermaLink="false">https://wei-ming.tw/posts/column-based</guid><pubDate>Sun, 19 Dec 2021 23:12:04 GMT</pubDate><content:encoded>&lt;h4 id=&quot;preface&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#preface&quot; aria-label=&quot;preface permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Preface&lt;/h4&gt;
&lt;p&gt;This is the third article of a series to summarize the key concepts of Chapter 3. Storage and Retrieval in the &lt;a href=&quot;https://www.amazon.com/Designing-Data-Intensive-Applications-Reliable-Maintainable/dp/1449373321&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Designing Data Intensive Application&lt;/a&gt; book. The series consists of 3 articles, including log-structure storage engine (SSTables and LSM Tree), page-oriented storage engine (B Tree) and column based storage engine.&lt;/p&gt;
&lt;h4 id=&quot;landscape-of-database-storages&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#landscape-of-database-storages&quot; aria-label=&quot;landscape of database storages permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Landscape of database storages&lt;/h4&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/b0453fbb95c32586f445dca4f9795c72/3e992/storage-engine-tree.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 46.25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsSAAALEgHS3X78AAAA+ElEQVQoz32SiYrFMAhF8/+/WCil0H3f9zpzhEDa92aEiyHR69Vo5Nfu+xbrXfxl0zRJFEXi+760bfvINW8yt8B5nrIsi+z7rmf8dV0yDIOUZamk4zg+ipm3Gns+jkOqqlIV+KIolKSua/VJkojnedL3vcbO8yzruopxSVBDMgkEUn3bNgXBvHPmnrg0TaXrOsmyTIIgUG/c9khyQeVvRixEkKIMUEQVooZ2UMSFNcjsnJqm0bkBkmkbNWEY6t1jhrYNC3eW/Gae55pEHKAoxWmX+XJ+/LJL4BID1JAA0XuteLcb8LE2FhDQHrvFjOI41mGj8j9zt+QHDZm8w9QVNO4AAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/b0453fbb95c32586f445dca4f9795c72/8ac56/storage-engine-tree.webp 240w,
/static/b0453fbb95c32586f445dca4f9795c72/d3be9/storage-engine-tree.webp 480w,
/static/b0453fbb95c32586f445dca4f9795c72/e46b2/storage-engine-tree.webp 960w,
/static/b0453fbb95c32586f445dca4f9795c72/f992d/storage-engine-tree.webp 1440w,
/static/b0453fbb95c32586f445dca4f9795c72/97599/storage-engine-tree.webp 1902w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/b0453fbb95c32586f445dca4f9795c72/8ff5a/storage-engine-tree.png 240w,
/static/b0453fbb95c32586f445dca4f9795c72/e85cb/storage-engine-tree.png 480w,
/static/b0453fbb95c32586f445dca4f9795c72/d9199/storage-engine-tree.png 960w,
/static/b0453fbb95c32586f445dca4f9795c72/07a9c/storage-engine-tree.png 1440w,
/static/b0453fbb95c32586f445dca4f9795c72/3e992/storage-engine-tree.png 1902w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/b0453fbb95c32586f445dca4f9795c72/d9199/storage-engine-tree.png&quot; alt=&quot;Landscape of database storages&quot; title=&quot;Landscape of database storages&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;p&gt;In short, database storages are divided into two categories, row-based and column based. In this article we will focus on the core concept of column-based storage engine, and compare the pros and  cons between row-based storage engine.&lt;/p&gt;
&lt;h2 id=&quot;column-based-storage-engine&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#column-based-storage-engine&quot; aria-label=&quot;column based storage engine permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Column-based storage engine&lt;/h2&gt;
&lt;p&gt;Before introducing column-based storage engine, we need to know 2 terms first:&lt;/p&gt;
&lt;h3 id=&quot;oltp-vs-olap&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#oltp-vs-olap&quot; aria-label=&quot;oltp vs olap permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;OLTP v.s. OLAP&lt;/h3&gt;
&lt;figure style=&quot;max-width: 500px&quot;&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/64569c4e418ce51c64efa94915eee260/fbf08/OLTP-OLAP.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAAAsSAAALEgHS3X78AAABJElEQVQY0z2Q226CQBRF+f+/qEUbYxprU216tzEICiLgtanWC1VMhVgriIzI7nCadJKVM2ceVvYewZyG6H1G6NoHmp3ZHhanx3dzdsB6ywAkSE+0XMCXaggaMnayhLCpwFfqdA/4TBFSycQDhosIhUodpUcN+ruH+Za/OTG8n+O/kK0c7LkE/S5GtxXIORFKLgtfbSC2DIS6BiFNc18fEKWnFknLrxbupD6aQxebIMH0Y4yJbSNx15SOZFkRkpiBdH4GLX8Bp/oMZugQqKq9R609Q7lqovig4ubFgDHeoDMP4e1inI4M7HSihKGq4JtXs4qX0At5LsxgcH2FsKUSVHn0lRDDJSPeHEb7YBnDpcp/J3Ic+rc0CWu3EGhN4sCrRnxPhb9JjmRbfNKovAAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/64569c4e418ce51c64efa94915eee260/8ac56/OLTP-OLAP.webp 240w,
/static/64569c4e418ce51c64efa94915eee260/d3be9/OLTP-OLAP.webp 480w,
/static/64569c4e418ce51c64efa94915eee260/e46b2/OLTP-OLAP.webp 960w,
/static/64569c4e418ce51c64efa94915eee260/c76c7/OLTP-OLAP.webp 962w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/64569c4e418ce51c64efa94915eee260/8ff5a/OLTP-OLAP.png 240w,
/static/64569c4e418ce51c64efa94915eee260/e85cb/OLTP-OLAP.png 480w,
/static/64569c4e418ce51c64efa94915eee260/d9199/OLTP-OLAP.png 960w,
/static/64569c4e418ce51c64efa94915eee260/fbf08/OLTP-OLAP.png 962w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/64569c4e418ce51c64efa94915eee260/d9199/OLTP-OLAP.png&quot; alt=&quot;OLTP v.s. OLAP&quot; title=&quot;OLTP v.s. OLAP&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;OLTP (OnLine Transactional Processing)&lt;/th&gt;
&lt;th&gt;OLAP (OnLine Analytical Processing)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Primarily used by&lt;/td&gt;
&lt;td&gt;End user/customer, via web application&lt;/td&gt;
&lt;td&gt;Internal analyst, for decision support performance reporting&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Main read pattern&lt;/td&gt;
&lt;td&gt;Small number of records per query, fetched by key&lt;/td&gt;
&lt;td&gt;Aggregate over large number of records&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Main write pattern&lt;/td&gt;
&lt;td&gt;Random-access, low-latency writes from user input&lt;/td&gt;
&lt;td&gt;Bulk import (ETL) or event stream&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;What data represents&lt;/td&gt;
&lt;td&gt;Latest state of data (current point in time)&lt;/td&gt;
&lt;td&gt;History of events that happened over time&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dataset size&lt;/td&gt;
&lt;td&gt;Gigabytes to terabytes&lt;/td&gt;
&lt;td&gt;Terabytes to petabytes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Since the analytical requirements in large companies arise, and this two different scenarios actually have quite different access pattern to database, new database was evolved to enhance its performance. And one of the most important one is column-based storage engine.&lt;/p&gt;
&lt;h3 id=&quot;star-schema&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#star-schema&quot; aria-label=&quot;star schema permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Star Schema&lt;/h3&gt;
&lt;p&gt;While business analysts or data analysts are analyzing business data, it’s very common that there is a fact table (e.g. orders, transactions, events), and several metadata tables that fact tables will reference to them (e.g. product, customer table). The shape of schema and their foreign keys will be like a “star”. So we call it start schema.&lt;/p&gt;
&lt;p&gt;The fact table is usually very very large (&gt; trillion data for large company), this makes analytical operation difficult for traditional row-based database.&lt;/p&gt;
&lt;h3 id=&quot;column-based-storage-engine-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#column-based-storage-engine-1&quot; aria-label=&quot;column based storage engine 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Column-based storage engine&lt;/h3&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/d24a667eefc744241802576b0bab6474/b6e50/column-based-storage-engine.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 67.91666666666667%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAAAsSAAALEgHS3X78AAABtElEQVQ4y5VT2Y6CQBDk/3/NeK3nCiiKFyqEIKAcUtvVcRJ19cFJKjMMQ011dWG5bgTHCeG6RITZ7IQwTFGWBa7XAkXB+aow67IsFbfbDU3TPMGy7V/M5w4mkyFse4rhsI/B4AfT6RTj8Rij0UgumaHT6cj+AK1WC5vNBlmWKfnrsHx/LQe28LwlgiDAer3GbrdHFEXY7/ey3uF4PML3fX2/Wq30+XK5KA6Hg+J0YmUhrKqqlJnyvx0kZCVUT+XtdhuW4zhS8lz8c1WF53kKKjXP2+0Wi8VC1zxPRXmea8n0jeVTNT0WD204At5EUvpE77hP77hP8n6/r8+9Xk/LTtNUCUj45GEtpVZ1jYrzHdwrxYrqBTXPyUwi4m2XG3aKN4kfCpbxpnufxj+FV4lALiXpvFwqCvGsuOfN3Ew1Bq+qDJQwEUOJTAji8xmxeHMWw2kyQdKvFLIh9IY5OkjOOALJn7mVXjFfzKABzzKn70gt/gksg2qCOyHX5iCbwLiw+91uV7tMLMUac+aJkH8C8xTHMZIkUUXMGUlNNB4/JFjRx5LNX2JecE1yBpiB/eTho7JH0j/iHDGDCh0wTQAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/d24a667eefc744241802576b0bab6474/8ac56/column-based-storage-engine.webp 240w,
/static/d24a667eefc744241802576b0bab6474/d3be9/column-based-storage-engine.webp 480w,
/static/d24a667eefc744241802576b0bab6474/e46b2/column-based-storage-engine.webp 960w,
/static/d24a667eefc744241802576b0bab6474/f992d/column-based-storage-engine.webp 1440w,
/static/d24a667eefc744241802576b0bab6474/511b7/column-based-storage-engine.webp 1862w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/d24a667eefc744241802576b0bab6474/8ff5a/column-based-storage-engine.png 240w,
/static/d24a667eefc744241802576b0bab6474/e85cb/column-based-storage-engine.png 480w,
/static/d24a667eefc744241802576b0bab6474/d9199/column-based-storage-engine.png 960w,
/static/d24a667eefc744241802576b0bab6474/07a9c/column-based-storage-engine.png 1440w,
/static/d24a667eefc744241802576b0bab6474/b6e50/column-based-storage-engine.png 1862w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/d24a667eefc744241802576b0bab6474/d9199/column-based-storage-engine.png&quot; alt=&quot;column based storage engine&quot; title=&quot;column based storage engine&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;p&gt;The core concept of column-based storage engine is quite intuitive. We store data by column instead of by row. Imaging that we have millions of customer data, if we store data by row, then while doing aggregation (e.g. summation, average), it will be very time consuming because we may need to load each rows (Unless we have index).&lt;/p&gt;
&lt;p&gt;On the other hand, if we store data by column, then calculating all customers’ average age will only require to load the file for age column. It will tremendously enhance the performance.&lt;/p&gt;
&lt;h4 id=&quot;the-benefits&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-benefits&quot; aria-label=&quot;the benefits permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The benefits&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;reduce query latency: when we want to access few columns but large portions of records, we don’t need to load every record from disk into memory and select what we want, this can extremely increase speed&lt;/li&gt;
&lt;li&gt;column compression → less disk space and faster execution: some of column have limited outcomes, we can compress it by encoding like bitmap / running length. Then we require less disk space, and have faster execution because data can be fitted in L1 cache &amp;#x26; AND/OR operation&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;the-drawbacks&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-drawbacks&quot; aria-label=&quot;the drawbacks permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The drawbacks&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;worse write performance: insert one record need to update every column, so it’s better to do this in batch (or use memory for temporally storing data, then writing to DB in batch)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;real-world-db&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#real-world-db&quot; aria-label=&quot;real world db permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Real world DB&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;DBs: &lt;a href=&quot;https://clickhouse.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Clickhouse&lt;/a&gt; / &lt;a href=&quot;https://www.vertica.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Vertica&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;comparison-matrix-of-row-based--column-based-storage-engine&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#comparison-matrix-of-row-based--column-based-storage-engine&quot; aria-label=&quot;comparison matrix of row based  column based storage engine permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Comparison matrix of Row-based &amp;#x26; Column based storage engine&lt;/h4&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Pros &amp;#x26; Cons&lt;/th&gt;
&lt;th&gt;Real world DB&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Row-based&lt;/td&gt;
&lt;td&gt;- Better write performance &lt;/br&gt; - Easier to handle transactional operation&lt;/td&gt;
&lt;td&gt;Cassandra / LevelDB  / HBase / Lucence MySQL / PostgreSQL / MongoDB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Column-based&lt;/td&gt;
&lt;td&gt;- Largely better aggregation performance of few columns but on large portion of data Worse&lt;/br&gt; - write performance, usually we will write data in batch&lt;/td&gt;
&lt;td&gt;Clickhoise / Vertica&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&quot;summary&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#summary&quot; aria-label=&quot;summary permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Summary&lt;/h3&gt;
&lt;p&gt;If also read the previous 2 articles about storage and retrieval, then congratulation! Now we should be able to have some thoughts in our mind to determine what databases to use for our application.&lt;/p&gt;
&lt;p&gt;Let’s recall the landscape of database storage engines. Now, how will you determine the selection of databases in your application ?&lt;/p&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/b0453fbb95c32586f445dca4f9795c72/3e992/storage-engine-tree.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 46.25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsSAAALEgHS3X78AAAA+ElEQVQoz32SiYrFMAhF8/+/WCil0H3f9zpzhEDa92aEiyHR69Vo5Nfu+xbrXfxl0zRJFEXi+760bfvINW8yt8B5nrIsi+z7rmf8dV0yDIOUZamk4zg+ipm3Gns+jkOqqlIV+KIolKSua/VJkojnedL3vcbO8yzruopxSVBDMgkEUn3bNgXBvHPmnrg0TaXrOsmyTIIgUG/c9khyQeVvRixEkKIMUEQVooZ2UMSFNcjsnJqm0bkBkmkbNWEY6t1jhrYNC3eW/Gae55pEHKAoxWmX+XJ+/LJL4BID1JAA0XuteLcb8LE2FhDQHrvFjOI41mGj8j9zt+QHDZm8w9QVNO4AAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/b0453fbb95c32586f445dca4f9795c72/8ac56/storage-engine-tree.webp 240w,
/static/b0453fbb95c32586f445dca4f9795c72/d3be9/storage-engine-tree.webp 480w,
/static/b0453fbb95c32586f445dca4f9795c72/e46b2/storage-engine-tree.webp 960w,
/static/b0453fbb95c32586f445dca4f9795c72/f992d/storage-engine-tree.webp 1440w,
/static/b0453fbb95c32586f445dca4f9795c72/97599/storage-engine-tree.webp 1902w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/b0453fbb95c32586f445dca4f9795c72/8ff5a/storage-engine-tree.png 240w,
/static/b0453fbb95c32586f445dca4f9795c72/e85cb/storage-engine-tree.png 480w,
/static/b0453fbb95c32586f445dca4f9795c72/d9199/storage-engine-tree.png 960w,
/static/b0453fbb95c32586f445dca4f9795c72/07a9c/storage-engine-tree.png 1440w,
/static/b0453fbb95c32586f445dca4f9795c72/3e992/storage-engine-tree.png 1902w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/b0453fbb95c32586f445dca4f9795c72/d9199/storage-engine-tree.png&quot; alt=&quot;Landscape of database storages&quot; title=&quot;Landscape of database storages&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;p&gt;Mine is pretty simple, for analytical requirements like internal analysis or performance reporting, we should firstly consider column-based storage engine. Then, for write intensive application, we can consider using log-structured storage engine, and on the other hands we can consider page-oriented storage engine if number of reads are usually larger than writes.&lt;/p&gt;
&lt;p&gt;Yes, this is just the first step of how to design data intensive application. But everything comes from the first step. Let’s proceed to the future chapters of this book.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Storage and Retrieval (2) - B Tree]]></title><description><![CDATA[B Tree is one of the most famous data structure of page-oriented storage engine (e.g. MySQL). page-oriented storage engine has relatively good read performance comparing to log-structured storage engine. Let's take a look at B Tree!]]></description><link>https://wei-ming.tw/posts/btree</link><guid isPermaLink="false">https://wei-ming.tw/posts/btree</guid><pubDate>Sat, 18 Dec 2021 23:12:04 GMT</pubDate><content:encoded>&lt;h4 id=&quot;preface&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#preface&quot; aria-label=&quot;preface permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Preface&lt;/h4&gt;
&lt;p&gt;This is the second article of a series to summarize the key concepts of Chapter 3. Storage and Retrieval in the &lt;a href=&quot;https://www.amazon.com/Designing-Data-Intensive-Applications-Reliable-Maintainable/dp/1449373321&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Designing Data Intensive Application&lt;/a&gt; book. The series consists of 3 articles, including log-structure storage engine (SSTables and LSM Tree), page-oriented storage engine (B Tree) and column based storage engine.&lt;/p&gt;
&lt;h4 id=&quot;landscape-of-database-storages&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#landscape-of-database-storages&quot; aria-label=&quot;landscape of database storages permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Landscape of database storages&lt;/h4&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/b0453fbb95c32586f445dca4f9795c72/3e992/storage-engine-tree.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 46.25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsSAAALEgHS3X78AAAA+ElEQVQoz32SiYrFMAhF8/+/WCil0H3f9zpzhEDa92aEiyHR69Vo5Nfu+xbrXfxl0zRJFEXi+760bfvINW8yt8B5nrIsi+z7rmf8dV0yDIOUZamk4zg+ipm3Gns+jkOqqlIV+KIolKSua/VJkojnedL3vcbO8yzruopxSVBDMgkEUn3bNgXBvHPmnrg0TaXrOsmyTIIgUG/c9khyQeVvRixEkKIMUEQVooZ2UMSFNcjsnJqm0bkBkmkbNWEY6t1jhrYNC3eW/Gae55pEHKAoxWmX+XJ+/LJL4BID1JAA0XuteLcb8LE2FhDQHrvFjOI41mGj8j9zt+QHDZm8w9QVNO4AAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/b0453fbb95c32586f445dca4f9795c72/8ac56/storage-engine-tree.webp 240w,
/static/b0453fbb95c32586f445dca4f9795c72/d3be9/storage-engine-tree.webp 480w,
/static/b0453fbb95c32586f445dca4f9795c72/e46b2/storage-engine-tree.webp 960w,
/static/b0453fbb95c32586f445dca4f9795c72/f992d/storage-engine-tree.webp 1440w,
/static/b0453fbb95c32586f445dca4f9795c72/97599/storage-engine-tree.webp 1902w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/b0453fbb95c32586f445dca4f9795c72/8ff5a/storage-engine-tree.png 240w,
/static/b0453fbb95c32586f445dca4f9795c72/e85cb/storage-engine-tree.png 480w,
/static/b0453fbb95c32586f445dca4f9795c72/d9199/storage-engine-tree.png 960w,
/static/b0453fbb95c32586f445dca4f9795c72/07a9c/storage-engine-tree.png 1440w,
/static/b0453fbb95c32586f445dca4f9795c72/3e992/storage-engine-tree.png 1902w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/b0453fbb95c32586f445dca4f9795c72/d9199/storage-engine-tree.png&quot; alt=&quot;Landscape of database storages&quot; title=&quot;Landscape of database storages&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;p&gt;In short, database storages are divided into two categories, row-based and column based. We will talk more about the difference of them in next article. In this article, we will talk more about the page-oriented storage under row-based storage.&lt;/p&gt;
&lt;h2 id=&quot;page-oriented-storage-engine&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#page-oriented-storage-engine&quot; aria-label=&quot;page oriented storage engine permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Page-oriented storage engine&lt;/h2&gt;
&lt;p&gt;Almost log-structured storage engine have pro-found influence on database evolution, the most widely adopted engine is actually page-oriented storage engine.&lt;/p&gt;
&lt;p&gt;Different from log-structure storage engine, page oriented storage engine &lt;strong&gt;update the value in place&lt;/strong&gt; (in its original page), instead of appending data to latest segment file.&lt;/p&gt;
&lt;p&gt;B Tree, which were adopted by MySQL, PostgreSQL and MongoDB, are the most adopted data structure.&lt;/p&gt;
&lt;h3 id=&quot;b-tree&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#b-tree&quot; aria-label=&quot;b tree permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;B Tree&lt;/h3&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/aceba302c4d7fedfdc314c15790959b5/11d70/b-tree.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 35.833333333333336%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAYAAAAIy204AAAACXBIWXMAAAsSAAALEgHS3X78AAAAy0lEQVQoz3VRawuEMAzb//+J4sDHFMQvPvFt7lLIMYUrhG5dSJvO4Rv3fUP5OA6c54nrujBNE0II6LrO3vZ9t7q4QhwuLpLsvUdd18jzHGVZom1bZFmGpmmQpqndY7E3HF7B4rquvymF2AHxL9y2bUagHYJCy7I8GlCQPGZyuAo2lStxbMIkScxiURRmbRgGjONo0JkCXIVsk9/3PeZ5fsAE2VFTUoCfwEfWOQVz/GnkKuhG0GoeO5Sl989JrKoqa8hJOSVXwwZaF88fDGQhy2F2KHAAAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/aceba302c4d7fedfdc314c15790959b5/8ac56/b-tree.webp 240w,
/static/aceba302c4d7fedfdc314c15790959b5/d3be9/b-tree.webp 480w,
/static/aceba302c4d7fedfdc314c15790959b5/e46b2/b-tree.webp 960w,
/static/aceba302c4d7fedfdc314c15790959b5/f992d/b-tree.webp 1440w,
/static/aceba302c4d7fedfdc314c15790959b5/d1be1/b-tree.webp 1802w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/aceba302c4d7fedfdc314c15790959b5/8ff5a/b-tree.png 240w,
/static/aceba302c4d7fedfdc314c15790959b5/e85cb/b-tree.png 480w,
/static/aceba302c4d7fedfdc314c15790959b5/d9199/b-tree.png 960w,
/static/aceba302c4d7fedfdc314c15790959b5/07a9c/b-tree.png 1440w,
/static/aceba302c4d7fedfdc314c15790959b5/11d70/b-tree.png 1802w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/aceba302c4d7fedfdc314c15790959b5/d9199/b-tree.png&quot; alt=&quot;Landscape of database storages&quot; title=&quot;Landscape of database storages&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;h4 id=&quot;how-it-works&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-it-works&quot; aria-label=&quot;how it works permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How it works&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For read request:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Binary search for root page&lt;/li&gt;
&lt;li&gt;Go to corresponding child page if necessary or get the value of corresponding key directly&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For write request:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Find corresponding node first&lt;/li&gt;
&lt;li&gt;If found, update the value in that page directly&lt;/li&gt;
&lt;li&gt;If not found, insert a node in the page.&lt;/li&gt;
&lt;li&gt;If the page is full, split page into 2 pages, and equally distribute the nodes&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Branching factor: the number of nodes in one page, usually it’s several hundreds.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Since B Tree is a balanced tree, the depth of tree is O(log n), where n is the number of key-value pairs.&lt;/li&gt;
&lt;li&gt;A four-level tree of 4KB pages with a branching factor of 500 can store up to 256 TB.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;pros--cons&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#pros--cons&quot; aria-label=&quot;pros  cons permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Pros &amp;#x26; Cons&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Better read performance: because we are searching a N-ary search tree, the time complexity is O(log n). Where N is branching factor. On the other hands, the worst case of log-structured storage engine is nearly O(n).&lt;/li&gt;
&lt;li&gt;Worse write performance: write request in log-structured storage engine is to intuitively append data, but in B Tree, we need to search key first, open the target page, update value, and then save the page back.&lt;/li&gt;
&lt;li&gt;More complex concurrency control &amp;#x26; crash recovery.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;comparison-matrix-of-log-structure--page-oriented-storage-engine&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#comparison-matrix-of-log-structure--page-oriented-storage-engine&quot; aria-label=&quot;comparison matrix of log structure  page oriented storage engine permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Comparison matrix of Log-structure &amp;#x26; Page-oriented Storage engine&lt;/h4&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Category&lt;/th&gt;
&lt;th&gt;Pros &amp;#x26; Cons&lt;/th&gt;
&lt;th&gt;Well know data structure&lt;/th&gt;
&lt;th&gt;Real world DB&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Log-structure&lt;/td&gt;
&lt;td&gt;Better write performance&lt;/td&gt;
&lt;td&gt;SSTables &amp;#x26; LSM Tree&lt;/td&gt;
&lt;td&gt;Cassandra  LevelDB  HBase Lucence&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Page-oriented&lt;/td&gt;
&lt;td&gt;Better read performance more complex concurrency control &amp;#x26; crash recovery&lt;/td&gt;
&lt;td&gt;B Tree&lt;/td&gt;
&lt;td&gt;MySQL PostgreSQL MongoDB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4 id=&quot;about-write-performance&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#about-write-performance&quot; aria-label=&quot;about write performance permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;About write performance&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Write Amplification: one write query can produce how many disk writes ?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;For write-intensive application, disk I/O is usually the bottleneck. Usually log-structured storage engine will have less write amplification, so its write performance is usually better.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Log structure engines have higher write latency at high percentiles:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;although log structure storage engines usually have better write performance, however, they are sometimes largely influenced by background compaction process disk I/O. So log structure storage engine usually have higher write latency at higher percentile.&lt;/li&gt;
&lt;li&gt;On the other hands, the write latency of page oriented storage engine is more stable.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;summary&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#summary&quot; aria-label=&quot;summary permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Summary&lt;/h3&gt;
&lt;p&gt;In this article, we walk through the design of page-oriented storage engine, mainly B Tree. We can know that data was updated directly in page file, so in general we can have worse write performance. But Since it’s a balanced tree structure, it can have much better read performance.&lt;/p&gt;
&lt;p&gt;So in short, if the scenario requires much more read than write, we can consider use page-oriented storage engine. On the other hands, if we to handle a write intensive application, we can consider using log-structured storage engine.&lt;/p&gt;
&lt;p&gt;In next article, we will talk more about column-based storage engine, which has many different design philosophy comparing to row-based storage engine. Let’s go.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Storage and Retrieval (1) - SSTable and LSM Tree]]></title><description><![CDATA[SSTable and LSM Tree are the underlying data structure of log structure storage engine (e.g. Cassandra). Log structure storage engine has relatively good write performance comparing to page oriented storage engine (e.g. B Tree, adopted by MySQL). Let's take a look at SSTable and LSM Tree !]]></description><link>https://wei-ming.tw/posts/sstable-and-lsmtree</link><guid isPermaLink="false">https://wei-ming.tw/posts/sstable-and-lsmtree</guid><pubDate>Thu, 16 Dec 2021 23:12:04 GMT</pubDate><content:encoded>&lt;h4 id=&quot;preface&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#preface&quot; aria-label=&quot;preface permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Preface&lt;/h4&gt;
&lt;p&gt;This is the first article of a series to summarize the key concepts of Chapter 3. Storage and Retrieval in the &lt;a href=&quot;https://www.amazon.com/Designing-Data-Intensive-Applications-Reliable-Maintainable/dp/1449373321&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Designing Data Intensive Application&lt;/a&gt; book. The series consists of 3 articles, including log-structure storage engine (SSTables and LSM Tree), page-oriented storage engine (B Tree) and column based storage engine.&lt;/p&gt;
&lt;h4 id=&quot;why-study-database-storage-and-retrieval-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#why-study-database-storage-and-retrieval-&quot; aria-label=&quot;why study database storage and retrieval  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Why study database storage and retrieval ?&lt;/h4&gt;
&lt;p&gt;There are so many different types of database available, like &lt;a href=&quot;https://www.mysql.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;MySQL&lt;/a&gt;, &lt;a href=&quot;https://www.mongodb.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;MongoDB&lt;/a&gt;, &lt;a href=&quot;https://cassandra.apache.org/_/index.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Cassandra&lt;/a&gt;, &lt;a href=&quot;https://clickhouse.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Clickhouse&lt;/a&gt; and etc. While designing our application, we should be able to select proper tool. Besides, Understanding underline core concepts is crucial for us to tune database performance.&lt;/p&gt;
&lt;h4 id=&quot;what-we-are-going-to-learn-in-this-article-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-we-are-going-to-learn-in-this-article-&quot; aria-label=&quot;what we are going to learn in this article  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What we are going to learn in this article ?&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;The underlining core concepts of different data storage structures and retrieval among modern databases.&lt;/li&gt;
&lt;li&gt;The pros and cons of each type of it and when we should use it.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;landscape-of-database-storages&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#landscape-of-database-storages&quot; aria-label=&quot;landscape of database storages permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Landscape of database storages&lt;/h4&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/b0453fbb95c32586f445dca4f9795c72/3e992/storage-engine-tree.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 46.25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsSAAALEgHS3X78AAAA+ElEQVQoz32SiYrFMAhF8/+/WCil0H3f9zpzhEDa92aEiyHR69Vo5Nfu+xbrXfxl0zRJFEXi+760bfvINW8yt8B5nrIsi+z7rmf8dV0yDIOUZamk4zg+ipm3Gns+jkOqqlIV+KIolKSua/VJkojnedL3vcbO8yzruopxSVBDMgkEUn3bNgXBvHPmnrg0TaXrOsmyTIIgUG/c9khyQeVvRixEkKIMUEQVooZ2UMSFNcjsnJqm0bkBkmkbNWEY6t1jhrYNC3eW/Gae55pEHKAoxWmX+XJ+/LJL4BID1JAA0XuteLcb8LE2FhDQHrvFjOI41mGj8j9zt+QHDZm8w9QVNO4AAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/b0453fbb95c32586f445dca4f9795c72/8ac56/storage-engine-tree.webp 240w,
/static/b0453fbb95c32586f445dca4f9795c72/d3be9/storage-engine-tree.webp 480w,
/static/b0453fbb95c32586f445dca4f9795c72/e46b2/storage-engine-tree.webp 960w,
/static/b0453fbb95c32586f445dca4f9795c72/f992d/storage-engine-tree.webp 1440w,
/static/b0453fbb95c32586f445dca4f9795c72/97599/storage-engine-tree.webp 1902w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/b0453fbb95c32586f445dca4f9795c72/8ff5a/storage-engine-tree.png 240w,
/static/b0453fbb95c32586f445dca4f9795c72/e85cb/storage-engine-tree.png 480w,
/static/b0453fbb95c32586f445dca4f9795c72/d9199/storage-engine-tree.png 960w,
/static/b0453fbb95c32586f445dca4f9795c72/07a9c/storage-engine-tree.png 1440w,
/static/b0453fbb95c32586f445dca4f9795c72/3e992/storage-engine-tree.png 1902w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/b0453fbb95c32586f445dca4f9795c72/d9199/storage-engine-tree.png&quot; alt=&quot;Landscape of database storages&quot; title=&quot;Landscape of database storages&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;p&gt;In short, database storages are divided into two categories, row-based and column based. We will talk more about the difference of them in future article. In this article, we will talk more about the log-structure storage under row-based storage. And in next article, we will talk more about page-oriented storage engine.&lt;/p&gt;
&lt;h2 id=&quot;log-structured-storage-engine&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#log-structured-storage-engine&quot; aria-label=&quot;log structured storage engine permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Log-structured storage engine&lt;/h2&gt;
&lt;h3 id=&quot;high-level-concept&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#high-level-concept&quot; aria-label=&quot;high level concept permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;High level concept&lt;/h3&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/df9e4d7ea5a3d27c05202cefb51cb500/d3deb/log-structure-storage.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 65.83333333333333%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAYAAACpUE5eAAAACXBIWXMAABYlAAAWJQFJUiTwAAABOElEQVQ4y5WT646CQAyFef8HxB+EyEWMXAUEBRG7+ZqdZCSD2W3SDI7t6Tltx5Nfe7/fer5eL+n7Xu73u/rj8VBv21amafqIdZm3BXw+n+plWcrxeJQoiiTLMgWf5/n/gDC8Xq9S17UURSF5nktVVeowNbF7oE5A5I3jqG6kU8Rm+GdA5JpE2+gfbO1YF+guw2EY1G+3mzLlrmkaWZblax+dgPTucrnoMM7ns/rpdNICgK/ruivdCYg0ANM0VaA4jiVJEr1D+nbaNqgTEGkkw9RMmjViyjDkbsvSuGf/wOgR0mxmnNwxMIyCrNXXHhqDISyCINClZrl931cQmJlXRF9pCU7BMAx1gB7UqW4/Nf4AiGAYHg4H3UPz9IxcTuLJg4RKJpkkJAJCr2BC400g313XfbzlvbX5AaL384hIw/bsAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/df9e4d7ea5a3d27c05202cefb51cb500/8ac56/log-structure-storage.webp 240w,
/static/df9e4d7ea5a3d27c05202cefb51cb500/d3be9/log-structure-storage.webp 480w,
/static/df9e4d7ea5a3d27c05202cefb51cb500/e46b2/log-structure-storage.webp 960w,
/static/df9e4d7ea5a3d27c05202cefb51cb500/f992d/log-structure-storage.webp 1440w,
/static/df9e4d7ea5a3d27c05202cefb51cb500/383eb/log-structure-storage.webp 1758w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/df9e4d7ea5a3d27c05202cefb51cb500/8ff5a/log-structure-storage.png 240w,
/static/df9e4d7ea5a3d27c05202cefb51cb500/e85cb/log-structure-storage.png 480w,
/static/df9e4d7ea5a3d27c05202cefb51cb500/d9199/log-structure-storage.png 960w,
/static/df9e4d7ea5a3d27c05202cefb51cb500/07a9c/log-structure-storage.png 1440w,
/static/df9e4d7ea5a3d27c05202cefb51cb500/d3deb/log-structure-storage.png 1758w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/df9e4d7ea5a3d27c05202cefb51cb500/d9199/log-structure-storage.png&quot; alt=&quot;how log structure storage works&quot; title=&quot;how log structure storage works&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;Every time when there is an new write query, we append the data to the end of file.&lt;/li&gt;
&lt;li&gt;When file size reach certain threshold (e.g. several MB), we append data to another new file. We call each file as “segment”.&lt;/li&gt;
&lt;li&gt;Compact &amp;#x26; Merge the files at some points in background process.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;very-first-version-of-our-own-db&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#very-first-version-of-our-own-db&quot; aria-label=&quot;very first version of our own db permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Very first version of our own DB&lt;/h4&gt;
&lt;p&gt;The concept sounds very simple, let’s write a simple version of DB by using shell script.&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token shebang important&quot;&gt;#!/bin/bash&lt;/span&gt;

&lt;span class=&quot;token function-name function&quot;&gt;db_set&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token builtin class-name&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&lt;span class=&quot;token variable&quot;&gt;$1&lt;/span&gt;,&lt;span class=&quot;token variable&quot;&gt;$2&lt;/span&gt;&quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;&gt;&lt;/span&gt; database
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token function-name function&quot;&gt;db_get&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;grep&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;^&lt;span class=&quot;token variable&quot;&gt;$1&lt;/span&gt;,&quot;&lt;/span&gt; database &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;sed&lt;/span&gt; -e &lt;span class=&quot;token string&quot;&gt;&quot;s/^&lt;span class=&quot;token variable&quot;&gt;$1&lt;/span&gt;,//&quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;tail&lt;/span&gt; -n &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;$ db_set &lt;span class=&quot;token number&quot;&gt;123456&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;{&quot;name&quot;:&quot;London&quot;,&quot;attractions&quot;:[&quot;Big Ben&quot;,&quot;London Eye&quot;]}&apos;&lt;/span&gt;

$ db_set &lt;span class=&quot;token number&quot;&gt;42&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;{&quot;name&quot;:&quot;San Francisco&quot;,&quot;attractions&quot;:[&quot;Golden Gate Bridge&quot;]}&apos;&lt;/span&gt;

$ db_get &lt;span class=&quot;token number&quot;&gt;42&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;token builtin class-name&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;San Francisco&quot;&lt;/span&gt;,&lt;span class=&quot;token string&quot;&gt;&quot;attractions&quot;&lt;/span&gt;:&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Golden Gate Bridge&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;It works! Wow, we already write our first very simple database. So, let’s think about pros and cons of this kind of databases.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Pros: very good write performance.&lt;/li&gt;
&lt;li&gt;Cons: while searching data, we need to search from newest segment, one file after another. The performance could be worse if we search old data.&lt;/li&gt;
&lt;li&gt;Then, how can we improve the read performance ?&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;enhancement-adding-index&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#enhancement-adding-index&quot; aria-label=&quot;enhancement adding index permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Enhancement: adding index&lt;/h4&gt;
&lt;p&gt;Now one bottleneck is, we need to search the key one by one in a segment file. The time complexity is O(n). If we ever learned any programming language, we can intuitively think of the hashmap data structure (e.g. dict in python, object in javascript).&lt;/p&gt;
&lt;p&gt;If we add a hashmap for each segment, maintain the position of value for each key. Then we can reduce the searching performance around O(log n). This is actually what &lt;a href=&quot;https://github.com/basho/bitcask&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Bitcask&lt;/a&gt; did.&lt;/p&gt;
&lt;h4 id=&quot;how-it-works&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-it-works&quot; aria-label=&quot;how it works permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How it works:&lt;/h4&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/77b810dcf665996bd187b758f033410b/a8a6f/log-structure-storage-with-hash.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 48.75000000000001%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAABnElEQVQoz52SWY+bMBSF+f8/q+pTVXWSsA4xgQSMzTqhEHY4vWamFTNT9aFXOrZs2Z/OXTRQrOuqNvRjh6/WF3z3v8EQJxz5AaY84eBxnC4VPNmDiQ5u3MLhPb1fsP+vQttfDFOP58whiPFHFslLa2RlgzQRkFKiLHIw/pOA6t/6b6ApDHKnbzC1K6ArXhCnFYLrDZbtIskKmH6ObufwN+MT0JLmJ+BZqnQH+EkLFje45SPs6IHm0f8fkCUVwjhDlkpSCh5FsIMCdTu8AyppalnWRZUC/Qb8W8p3hPIO/xrCchhimcMKShT3Gss8Yx/a/jCvE6zkzaFQTTFhJ69NYWEFi0Uw3BDslsFPpw34eDSbs5nASlrbthBCUCoZ4oTj6fIDQgroug4e07gEB+iBhEypMfwGzkOMQwfnWqKqO5RlgYhKYJomGGPQFLXve3o0Uk1qGFxHIAI4Fxte5OEYPL0CswpZliJJEkzTTGND7vqZ3C2bszzP0TTN+5THZdyacoqPMKQOnYbbekv5LAYEKXWadKbBduk8TCs+xi8VxfGIWxWJMAAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/77b810dcf665996bd187b758f033410b/8ac56/log-structure-storage-with-hash.webp 240w,
/static/77b810dcf665996bd187b758f033410b/d3be9/log-structure-storage-with-hash.webp 480w,
/static/77b810dcf665996bd187b758f033410b/e46b2/log-structure-storage-with-hash.webp 960w,
/static/77b810dcf665996bd187b758f033410b/f992d/log-structure-storage-with-hash.webp 1440w,
/static/77b810dcf665996bd187b758f033410b/dde0f/log-structure-storage-with-hash.webp 1516w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/77b810dcf665996bd187b758f033410b/8ff5a/log-structure-storage-with-hash.png 240w,
/static/77b810dcf665996bd187b758f033410b/e85cb/log-structure-storage-with-hash.png 480w,
/static/77b810dcf665996bd187b758f033410b/d9199/log-structure-storage-with-hash.png 960w,
/static/77b810dcf665996bd187b758f033410b/07a9c/log-structure-storage-with-hash.png 1440w,
/static/77b810dcf665996bd187b758f033410b/a8a6f/log-structure-storage-with-hash.png 1516w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/77b810dcf665996bd187b758f033410b/d9199/log-structure-storage-with-hash.png&quot; alt=&quot;log structure storage engine with hashmap&quot; title=&quot;log structure storage engine with hashmap&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For write request:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Update key value in hashmap, append data to log file.&lt;/li&gt;
&lt;li&gt;When file is large enough, write both hashmap &amp;#x26; data as file.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For read request:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Load hashmap from newest segment, search whether the key is in hashmap.&lt;/li&gt;
&lt;li&gt;If not found, load next segment, and do the same thing.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;discussions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#discussions&quot; aria-label=&quot;discussions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Discussions&lt;/h4&gt;
&lt;p&gt;Okay, let’s stop here for a while. What is the pros and cons of this kind of database ? Can we make it even better ?&lt;/p&gt;
&lt;h3 id=&quot;sstables--lsm-tree&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sstables--lsm-tree&quot; aria-label=&quot;sstables  lsm tree permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;SSTables &amp;#x26; LSM Tree&lt;/h3&gt;
&lt;p&gt;Yes, here comes SSTables and LSM Tree.&lt;/p&gt;
&lt;p&gt;Let’s do almost exactly the same logic we mentioned above (log + index), but with a change: &lt;strong&gt;the data in each segment file are sorted by keys&lt;/strong&gt;&lt;/p&gt;
&lt;h4 id=&quot;the-benefits-of-sorted-data-in-segment-file&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-benefits-of-sorted-data-in-segment-file&quot; aria-label=&quot;the benefits of sorted data in segment file permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The benefits of sorted data in segment file&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Merge several segment files can be very efficient by merge sort algorithm, even for very large file that cannot be loaded into memory.&lt;/li&gt;
&lt;li&gt;Since segment data was sorted, we don’t need to store all key value pairs, we can keep sparse index and do binary search.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;how-it-works-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-it-works-1&quot; aria-label=&quot;how it works 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How it works&lt;/h4&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/71ed0488ba6f8432ad60effe1c923651/add4c/LSM-tree.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 63.33333333333333%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAYAAACpUE5eAAAACXBIWXMAAAsSAAALEgHS3X78AAABnElEQVQ4y5WTWZOCMBCE+f+/zQcLfcOrPEpdCQgSEgKhtyeuu+JVtalKSa6Zr3vGqO979N5DxuVywXg8xm63C+twxvmfEd0v5HFVVai0Huz9K6AzBm2awmQZjLU4HA7ITl/wP9Q3yk8Td0oi33XwTQPftqjrOsjuTP2U+RNp/06yjIbBrXPXi0zWM5H8CsV+v8e5KGDLElopdFQxIA2SSSWSa174k3xCw+9ms0Edx7CzWSBfLpfQ4i8fa64N7XqUH0mFexIJhWbw4nyGY2Fk3ZLGpSThnuwLYZIkWDNRSUrLpB+r/G50fResWK/XOB6PIZgQi+dnJkqp8ERVBQGil1XjsLaDUoYWlJwXtpPGYrEIQWSIXPnO2B2TyQSj0Qgbkj8RdlKA0OQtplOFOE45FbNrkpyC5NVqFWhEsgCIrxLY0bqobemdlpZpeOj5SJFMhUvO2UFTzOfzIO3WXreAAw+tdchzS18ML5UMlqKoaq6vHhljw0Mh2m63wTMhuZ69qPJj8yZJzmrq37X314tihdCJZGmfPM/Dv+nR+2/WrfSJ9FZkUQAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/71ed0488ba6f8432ad60effe1c923651/8ac56/LSM-tree.webp 240w,
/static/71ed0488ba6f8432ad60effe1c923651/d3be9/LSM-tree.webp 480w,
/static/71ed0488ba6f8432ad60effe1c923651/e46b2/LSM-tree.webp 960w,
/static/71ed0488ba6f8432ad60effe1c923651/f992d/LSM-tree.webp 1440w,
/static/71ed0488ba6f8432ad60effe1c923651/78e5d/LSM-tree.webp 1452w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/71ed0488ba6f8432ad60effe1c923651/8ff5a/LSM-tree.png 240w,
/static/71ed0488ba6f8432ad60effe1c923651/e85cb/LSM-tree.png 480w,
/static/71ed0488ba6f8432ad60effe1c923651/d9199/LSM-tree.png 960w,
/static/71ed0488ba6f8432ad60effe1c923651/07a9c/LSM-tree.png 1440w,
/static/71ed0488ba6f8432ad60effe1c923651/add4c/LSM-tree.png 1452w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/71ed0488ba6f8432ad60effe1c923651/d9199/LSM-tree.png&quot; alt=&quot;Memtable and SSTables&quot; title=&quot;Memtable and SSTables&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For write request:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Update key value in a balance tree, append data to log file (only for recovery)&lt;/li&gt;
&lt;li&gt;When the tree is large enough, write the data in key order as a segment file&lt;/li&gt;
&lt;li&gt;only need to kept very sparse index for each segment since segment file is sorted&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For read request:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;try to search it from memtable first&lt;/li&gt;
&lt;li&gt;if not found, search the newest SSTable&lt;/li&gt;
&lt;li&gt;do binary search via sparse index&lt;/li&gt;
&lt;li&gt;extract entire small block from disk into memory, if not found, search next next SSTable&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Background process:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;merge several SSTables(segment file) by merge sort&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For index:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We can have smaller index data stored in disk.&lt;/li&gt;
&lt;li&gt;For example if there are 10,000 key-value pairs in one segment file, we can only sparsely store 100 key-pairs in our index only. Then after doing binary search, we can locate the possible 100 key-value pairs in segment file.&lt;/li&gt;
&lt;li&gt;Because OS load file into memory by fixed size block, there isn’t much difference of I/O performance comparing to only load 1 key-value pair (disk I/O is usually the bottleneck of database performance). And scan 100 key-value in memory can still be very efficient.&lt;/li&gt;
&lt;li&gt;So, to sum up, more sparse index, we can save more disk space, but the searching performance can be worse.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;terms&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#terms&quot; aria-label=&quot;terms permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Terms&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;SSTables (Sorted String Tables) → the data stored in segment was sorted&lt;/li&gt;
&lt;li&gt;LSM Trees (Log Structured Merge tree) → balanced tree in memory, sorted log file in disk&lt;/li&gt;
&lt;li&gt;Real world databases use the concept of LSM tree &amp;#x26; SSTables: &lt;a href=&quot;https://cassandra.apache.org/_/index.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Cassandra&lt;/a&gt; / &lt;a href=&quot;https://github.com/google/leveldb&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;LevelDB&lt;/a&gt; / &lt;a href=&quot;https://hbase.apache.org/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;HBase&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Full-text search engine: &lt;a href=&quot;https://lucene.apache.org/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Lucence&lt;/a&gt; / &lt;a href=&quot;https://solr.apache.org/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Solr&lt;/a&gt; / &lt;a href=&quot;https://www.elastic.co/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;ElasticSearch&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;discussions-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#discussions-1&quot; aria-label=&quot;discussions 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Discussions&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;What is the potential bottleneck for this kind of database ?&lt;/li&gt;
&lt;li&gt;How can we improve for this design ?&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;summary&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#summary&quot; aria-label=&quot;summary permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Summary&lt;/h3&gt;
&lt;p&gt;In this article, we walk through the design of log structure storage engine, and the basic concepts of SSTables &amp;#x26; LSM tree. We can know that data was appended to segment file, so in general we can have good write performance. But the read performance, in worst case we have to read every segment file. In order to enhancement read performance, we can add index on segment file, including hash map or balanced tree with sparse index.&lt;/p&gt;
&lt;p&gt;We will learn more about page-oriented storage engine, then we can compare the pros and cons of these two categories of databases.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[希望我 20 歲就有的投資理財懶人包]]></title><description><![CDATA[這一陣子看了很多投資、理財學習資源（書、網站、影片），也為自己做了理財規劃，才發現自己原來這麼需要學會理財，也才知道原來投資要及早開始，時間才是資產成長的最大力量。深深覺得這些思維與知識，應該要是人人都能懂、都能取得，因此決定寫這篇文章，把最精華的部分濃縮起來。內容將主要包含三大部分：基礎理財、保險以及長期投資。]]></description><link>https://wei-ming.tw/posts/personal-finance-things-to-know</link><guid isPermaLink="false">https://wei-ming.tw/posts/personal-finance-things-to-know</guid><pubDate>Wed, 14 Apr 2021 23:12:04 GMT</pubDate><content:encoded>&lt;p&gt;這一陣子看了很多投資、理財學習資源（書、網站、影片），也為自己做了理財規劃，才發現自己原來這麼需要學會理財，也才知道原來投資要及早開始，時間才是資產成長的最大力量。&lt;/p&gt;
&lt;p&gt;深深覺得這些思維與知識，應該要是人人都能懂、都能取得，因此決定寫這篇文章，把最精華的部分濃縮起來。內容將主要包含三大部分：&lt;strong&gt;基礎理財&lt;/strong&gt;、&lt;strong&gt;保險&lt;/strong&gt;以及&lt;strong&gt;長期投資&lt;/strong&gt;。&lt;/p&gt;
&lt;p&gt;我認為這些知識將可以協助大部分的「我們」—— 家裡沒有有錢到不需要工作，經濟負擔也還沒有大到完全無法儲蓄的大多數人，擁有更安全、更有餘裕的人生。&lt;/p&gt;
&lt;p&gt;那我們就開始吧！&lt;/p&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;為什麼投資理財很重要？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E7%82%BA%E4%BB%80%E9%BA%BC%E6%8A%95%E8%B3%87%E7%90%86%E8%B2%A1%E5%BE%88%E9%87%8D%E8%A6%81%EF%BC%9F&quot; aria-label=&quot;為什麼投資理財很重要？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;為什麼投資理財很重要？&lt;/h2&gt;
&lt;p&gt;我想講兩個小小的故事&lt;/p&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 56.25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAABYlAAAWJQFJUiTwAAACOElEQVQoz1WSi04aYRCFef8HaGNab22jLU1EkRpjpKaaaLSmGi6CRaTAAssu12UvsLevs7/Y6mwm889scnLOnEnFcUwSqkrGUcRwMKDf79PpdDANA13XMU1T5XgyVv+SDMOQOPleYKSWL55GT2HZNm0BK5bLlCsViqUS9XqdWq1G80+TdqvNdDLlZTyDpuIlWDyfE81mzMdjYsfBHQ6ZCDNcF4IAP/JxFjYTe4wxMvACl6kzwfIs5r73n+EzYFR7wD89o5L+ysmbtyoLW9vY+e/E1XtKWoH3mRU2squk89vkLvdY3VlhPfuOSqf8GjCJaDwBvQ/mgIXWwRKJCEtGI0gYRw6mY9Add+hbPSaLEaad9BqzxfTFDpdGqN2JvKamMRTZhoCVq1VqjYaqWktDa2t0O10a9YbsUaPVbBMF0T+wJ4ZJs1xsIK45Ajr3fVUfBawiYA/CttlsUpW30Tewphae6+E6rpCJX5mTQgaxmBFbFtiOkqckyrkIKix85D6I5AsJ8EKXkT1kHnk4vo29mKlM3nEcCaCwefx2QOlLmvudDLfbn6lldvm9u0c9u09rP4dQ5ObxF+njLfK3R+TO9zi8ynF6d8KN9pO7YYHKoKguIRV4ngK73tjkcm1duVuR/mp9g+vNDxQ/fiISly+rF8rRnR9pNvfXyJ5nOLo5IF844rhwyMXDGWEcyA5FTijuhj2dSGrQ60mvE3R7ahZKjeUCrPlUXO0zcExVE4f7lq4c16ddNYtE8l+lWS2jr2VPPQAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/1c2eb8965dc8df2c08f8f636fcc050c2/8ac56/why-investment-important.webp 240w,
/static/1c2eb8965dc8df2c08f8f636fcc050c2/d3be9/why-investment-important.webp 480w,
/static/1c2eb8965dc8df2c08f8f636fcc050c2/e46b2/why-investment-important.webp 960w,
/static/1c2eb8965dc8df2c08f8f636fcc050c2/f992d/why-investment-important.webp 1440w,
/static/1c2eb8965dc8df2c08f8f636fcc050c2/882b9/why-investment-important.webp 1920w,
/static/1c2eb8965dc8df2c08f8f636fcc050c2/d3d72/why-investment-important.webp 2880w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/1c2eb8965dc8df2c08f8f636fcc050c2/8ff5a/why-investment-important.png 240w,
/static/1c2eb8965dc8df2c08f8f636fcc050c2/e85cb/why-investment-important.png 480w,
/static/1c2eb8965dc8df2c08f8f636fcc050c2/d9199/why-investment-important.png 960w,
/static/1c2eb8965dc8df2c08f8f636fcc050c2/07a9c/why-investment-important.png 1440w,
/static/1c2eb8965dc8df2c08f8f636fcc050c2/29114/why-investment-important.png 1920w,
/static/1c2eb8965dc8df2c08f8f636fcc050c2/d9ed5/why-investment-important.png 2880w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/1c2eb8965dc8df2c08f8f636fcc050c2/d9199/why-investment-important.png&quot; alt=&quot;&amp;#x6709;&amp;#x505A;&amp;#x9577;&amp;#x671F;&amp;#x6295;&amp;#x8CC7;&amp;#xFF0C;&amp;#x8207;&amp;#x6C92;&amp;#x6709;&amp;#x505A;&amp;#x9577;&amp;#x671F;&amp;#x6295;&amp;#x8CC7;&amp;#xFF0C;&amp;#x9577;&amp;#x671F;&amp;#x4F86;&amp;#x8AAA;&amp;#x7684;&amp;#x5DEE;&amp;#x5225;&amp;#x5F88;&amp;#x5927;&quot; title=&quot;&amp;#x6709;&amp;#x505A;&amp;#x9577;&amp;#x671F;&amp;#x6295;&amp;#x8CC7;&amp;#xFF0C;&amp;#x8207;&amp;#x6C92;&amp;#x6709;&amp;#x505A;&amp;#x9577;&amp;#x671F;&amp;#x6295;&amp;#x8CC7;&amp;#xFF0C;&amp;#x9577;&amp;#x671F;&amp;#x4F86;&amp;#x8AAA;&amp;#x7684;&amp;#x5DEE;&amp;#x5225;&amp;#x5F88;&amp;#x5927;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
    &lt;/span&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 15.833333333333332%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAYAAACTWi8uAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAnUlEQVQI102P2wpGYBBFvf9ruaOUopDwiZzJ8Uasv5kL/VPTrj0zazfWdV00TUPbtszzzL7vDMNAWZbUdc04jtoyE/84DqZp4jxP/ut9X1VLFm3bxnVd0jSlqirCMCQIAnzfx/M84jjGGEOSJBqU5znLsijkvm+e5/mg1rquOI5DFEV6JCog0a7r1CuKQkPEy7JMQ6X7vtfvtm37gD8ekt6XypHCfgAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/f0e43cd15004174535c804035604e196/8ac56/calculation.webp 240w,
/static/f0e43cd15004174535c804035604e196/d3be9/calculation.webp 480w,
/static/f0e43cd15004174535c804035604e196/e46b2/calculation.webp 960w,
/static/f0e43cd15004174535c804035604e196/f992d/calculation.webp 1440w,
/static/f0e43cd15004174535c804035604e196/882b9/calculation.webp 1920w,
/static/f0e43cd15004174535c804035604e196/70317/calculation.webp 2544w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/f0e43cd15004174535c804035604e196/8ff5a/calculation.png 240w,
/static/f0e43cd15004174535c804035604e196/e85cb/calculation.png 480w,
/static/f0e43cd15004174535c804035604e196/d9199/calculation.png 960w,
/static/f0e43cd15004174535c804035604e196/07a9c/calculation.png 1440w,
/static/f0e43cd15004174535c804035604e196/29114/calculation.png 1920w,
/static/f0e43cd15004174535c804035604e196/900ee/calculation.png 2544w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/f0e43cd15004174535c804035604e196/d9199/calculation.png&quot; alt=&quot;&amp;#x8A08;&amp;#x7B97;&quot; title=&quot;&amp;#x8A08;&amp;#x7B97;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;p&gt;通貨膨脹事實上侵蝕著我們的資產，要如何&lt;strong&gt;藉由正確的投資方法，並藉助他人的力量，以滿足生而為人的財務需求&lt;/strong&gt;，其實十分重要&lt;/p&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;p&gt;第二個故事是個悲傷的故事&lt;/p&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 56.25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAABYlAAAWJQFJUiTwAAACZElEQVQoz1WTCU8aURSF/f+/wC42qVUQKEUg2mirrUZTTQWEEYYdZgNkcViEArN8vWBt9CYn7+Um78y595zZ8H0fH1idnusyHo8pFAqoqkqz0aBSLmNZ1rqXuc1QUAvouk5OyWEPbVzPxfO99ftVbfCP7Ll6Dw/orRaaadIwDFrdLr3BQMibGLpJy2rTu+9hyr0r58ta8Ww8ky3loZVO0y+oDNQiVuaWcblCP59n0ekwnNtUrBJqM49SzWIMNOqdKiVDpWwWcVznSeEz4VRGvNsNcBsIkgvucbP9iUpsn6v3W9jpDNVeifBpgORljOiPEAfXCeIXUfYFp9ljlt7yNaE7neLZshN7iPNgM5SRZ6LaXfUmE2bLKVPnkeHMpt1vMZoN13hcTJjMx+s9/idcUf6R5Zv7CfLhMGebb8js7IrKbYp7ISapNAVLIXm9T+w8QvBoh8hJkL3jXSKnQa5qF8yd+WuFzOf4rTZzUeaIKaNqjYkY4YjDYieT5QjLNjEHBjWrQmfUlruO3mvSn3ZfuOx5mJkMuuzJzCkYuRyWolC/SVFPpdCk/9hu0x3e0+w2yFcVlEqWRqdOxSxTbKr0pvf05911hDY8UVaPJ7gTM9RQmFI4Ql5MeUbv4BAnLxmsp4j/inL4OyGGxDlKH3CqHBO/jPIt+5XL8jmO7wjhYoEa+UxOHK6Lqy0hqH2JYSSSaIKqfMCRGJ3fnrEVf8vH5AfeRTcJfX/aX/RniNBJgJPsER6i0Je/oysKOjLmKoNLTcPRDYH+hKYGEuyO3UbV8hQad2uUdMmfUaQ1koDPOuuxXd/lLyW1FjBNmuQUAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/2fc2e5804e56443a2d280c176c66091e/8ac56/why-insurance-important.webp 240w,
/static/2fc2e5804e56443a2d280c176c66091e/d3be9/why-insurance-important.webp 480w,
/static/2fc2e5804e56443a2d280c176c66091e/e46b2/why-insurance-important.webp 960w,
/static/2fc2e5804e56443a2d280c176c66091e/f992d/why-insurance-important.webp 1440w,
/static/2fc2e5804e56443a2d280c176c66091e/882b9/why-insurance-important.webp 1920w,
/static/2fc2e5804e56443a2d280c176c66091e/d3d72/why-insurance-important.webp 2880w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/2fc2e5804e56443a2d280c176c66091e/8ff5a/why-insurance-important.png 240w,
/static/2fc2e5804e56443a2d280c176c66091e/e85cb/why-insurance-important.png 480w,
/static/2fc2e5804e56443a2d280c176c66091e/d9199/why-insurance-important.png 960w,
/static/2fc2e5804e56443a2d280c176c66091e/07a9c/why-insurance-important.png 1440w,
/static/2fc2e5804e56443a2d280c176c66091e/29114/why-insurance-important.png 1920w,
/static/2fc2e5804e56443a2d280c176c66091e/d9ed5/why-insurance-important.png 2880w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/2fc2e5804e56443a2d280c176c66091e/d9199/why-insurance-important.png&quot; alt=&quot;&amp;#x4FDD;&amp;#x96AA;&amp;#x5F88;&amp;#x91CD;&amp;#x8981;&amp;#xFF0C;&amp;#x70BA;&amp;#x6211;&amp;#x5011;&amp;#x5206;&amp;#x64D4;&amp;#x4E0D;&amp;#x53EF;&amp;#x9810;&amp;#x671F;&amp;#x7684;&amp;#x98A8;&amp;#x96AA;&quot; title=&quot;&amp;#x4FDD;&amp;#x96AA;&amp;#x5F88;&amp;#x91CD;&amp;#x8981;&amp;#xFF0C;&amp;#x70BA;&amp;#x6211;&amp;#x5011;&amp;#x5206;&amp;#x64D4;&amp;#x4E0D;&amp;#x53EF;&amp;#x9810;&amp;#x671F;&amp;#x7684;&amp;#x98A8;&amp;#x96AA;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;p&gt;我們生命中其實充滿著不可預期的風險，如何運用財務工具，讓我們以及我們所愛的人，可以有尊嚴地活著，也很重要&lt;/p&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;具體來說，我們要如何好好為自己投資理財呢？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%85%B7%E9%AB%94%E4%BE%86%E8%AA%AA%EF%BC%8C%E6%88%91%E5%80%91%E8%A6%81%E5%A6%82%E4%BD%95%E5%A5%BD%E5%A5%BD%E7%82%BA%E8%87%AA%E5%B7%B1%E6%8A%95%E8%B3%87%E7%90%86%E8%B2%A1%E5%91%A2%EF%BC%9F&quot; aria-label=&quot;具體來說，我們要如何好好為自己投資理財呢？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;具體來說，我們要如何好好為自己投資理財呢？&lt;/h2&gt;
&lt;p&gt;我認為，大致上可以分為五個步驟，這五個步驟就是我認為最重要的基礎理財觀念。接下來我們會一步一步介紹，其中將會在保險＆長期投資這兩塊有最多的篇幅&lt;/p&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 21.666666666666668%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAECAYAAACOXx+WAAAACXBIWXMAABYlAAAWJQFJUiTwAAAA5UlEQVQY022PXUsCQRSG9///gK6ii4KgutIuUhQrl5BCXTSCWo0VWzAHZF139sPZnXkaF4KQXngvznneczjHMUbzK2MMx/rbO+b/1U6U7ukOP7h1JyxEQhQn9KcBndGcUESIOKM7mtHsj/FXMTuZ8ex/476FbGXOUsT0vE8eJgGbJMcRcc7F3YDTxiPTQLASG27uPc5bL8y+1sxDwVnT5eSqxdOrHdomtMcLGgOfdSR5XwouO0Ouex6HXY5SJbu0qJ0VCq0NmdKk1mWlUWVVX3LgMivQ9i1pczJXVJbvLa/z+6rO/gDmcCp/j7peKwAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/cee8d07f44119168427d1c23707dd15d/8ac56/steps.webp 240w,
/static/cee8d07f44119168427d1c23707dd15d/d3be9/steps.webp 480w,
/static/cee8d07f44119168427d1c23707dd15d/e46b2/steps.webp 960w,
/static/cee8d07f44119168427d1c23707dd15d/f992d/steps.webp 1440w,
/static/cee8d07f44119168427d1c23707dd15d/882b9/steps.webp 1920w,
/static/cee8d07f44119168427d1c23707dd15d/066c1/steps.webp 2456w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/cee8d07f44119168427d1c23707dd15d/8ff5a/steps.png 240w,
/static/cee8d07f44119168427d1c23707dd15d/e85cb/steps.png 480w,
/static/cee8d07f44119168427d1c23707dd15d/d9199/steps.png 960w,
/static/cee8d07f44119168427d1c23707dd15d/07a9c/steps.png 1440w,
/static/cee8d07f44119168427d1c23707dd15d/29114/steps.png 1920w,
/static/cee8d07f44119168427d1c23707dd15d/17fba/steps.png 2456w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/cee8d07f44119168427d1c23707dd15d/d9199/steps.png&quot; alt=&quot;&amp;#x7406;&amp;#x8CA1;&amp;#x7684;&amp;#x6B65;&amp;#x9A5F;&quot; title=&quot;&amp;#x7406;&amp;#x8CA1;&amp;#x7684;&amp;#x6B65;&amp;#x9A5F;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;step-1-釐清財務狀況&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#step-1-%E9%87%90%E6%B8%85%E8%B2%A1%E5%8B%99%E7%8B%80%E6%B3%81&quot; aria-label=&quot;step 1 釐清財務狀況 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Step 1. 釐清財務狀況&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;理財的第一步，其實是了解自己&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;了解自己具體來說，有什麼財務需求？&lt;/li&gt;
&lt;li&gt;現在的每個月花費是多少？ 未來想過什麼樣的生活？ 想投入什麼行業？&lt;/li&gt;
&lt;li&gt;接下是否有預計養育小孩、買房、買車，以及父母是否需要扶養？&lt;/li&gt;
&lt;li&gt;這些問題其實相當重要，不瞭解自己的財務需求，就沒有辦法準備緊急備用金，也無法知道保險要保多少，更無法分配預算，將部分資產做長期投資&lt;/li&gt;
&lt;li&gt;有些問題不容易一次就回答，但我們可以&lt;strong&gt;可以每一年，或每一季，給自己一個週末，排開所有事情，把時間留給自己，好好釐清自己的財務狀況與需求&lt;/strong&gt;。我習慣放在跨年後的第一個週末，因為那時候最常去規劃未來的事情&lt;/li&gt;
&lt;li&gt;先從養成記帳習慣開始：如果你喜歡紙本，那就用紙本。如果你喜歡用手機 App，這裡有很多可以供選擇。記帳不是一件容易維持的事情，可以找伴侶一起記帳，或是養成睡前記帳的習慣&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;step-2-償還債務&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#step-2-%E5%84%9F%E9%82%84%E5%82%B5%E5%8B%99&quot; aria-label=&quot;step 2 償還債務 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Step 2. 償還債務&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;債務會讓我們的資產不斷減少，尤其是信用卡循環利率動輒 5~15 %&lt;/li&gt;
&lt;li&gt;所以，信用卡費，請盡一切努力先還完。如果無法控制自己刷卡，不要辦信用卡&lt;/li&gt;
&lt;li&gt;如果是向親友借錢，就是欠人情，還是早點還。我們沒有那麼多親友可以借錢的&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;step-3-準備緊急預備金&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#step-3-%E6%BA%96%E5%82%99%E7%B7%8A%E6%80%A5%E9%A0%90%E5%82%99%E9%87%91&quot; aria-label=&quot;step 3 準備緊急預備金 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Step 3. 準備緊急預備金&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;如果你已經瞭解自己每個月生活的花費，而且償還債務了，接著，請為自己準備一筆&lt;strong&gt;緊急預備金&lt;/strong&gt;！&lt;/li&gt;
&lt;li&gt;顧名思義，這筆錢，是緊急的時候可以用的，例如：小意外/小疾病而暫時無法工作、突然被資遣，或是現在的工作真的不適合自己，想要裸辭換工作&lt;/li&gt;
&lt;li&gt;除此之外，這筆錢，也可以避免自己在突然需要用錢的情況下，不幸遇到股票大跌，只能賤賣股票&lt;/li&gt;
&lt;li&gt;大概準備多少夠呢？ 我認為 &lt;code class=&quot;language-text&quot;&gt;[至少 6 個月 x 每個月支出]&lt;/code&gt;，不過還是根據自己的需求與個性調整&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;這筆錢可以存哪裡？&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;最推薦的是&lt;a href=&quot;https://earning.tw/bank-account-recommend/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;高利活存帳戶&lt;/a&gt;，利率可以到 1%，存普通的銀行帳戶，利率通常只有 0.1% 以下。近幾年比較紅的就是永豐大戶跟台新 Richart 帳戶，不過台新今年已經調高門檻了。相信每一年都會不太一樣，請自行每年查詢。如果沒有利率高的活存帳戶，可以考慮定存&lt;/li&gt;
&lt;li&gt;然後，我非常不建議買儲蓄險/投資型保單，緊急備用金就是你並不知道什麼可能會用到，一需要就是很急，這兩項商品雖然低風險，但提前解約都會有很大的損失&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;step-4-為自己以及家人保險&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#step-4-%E7%82%BA%E8%87%AA%E5%B7%B1%E4%BB%A5%E5%8F%8A%E5%AE%B6%E4%BA%BA%E4%BF%9D%E9%9A%AA&quot; aria-label=&quot;step 4 為自己以及家人保險 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Step 4. 為自己以及家人保險&lt;/h2&gt;
&lt;p&gt;如果你已經償還債務，這一步可以跟第三步同時做，逐步把緊急備用金存夠，也逐步為自己和家人保保險&lt;/p&gt;
&lt;p&gt;在為自己以及家人買保險的過程，其實也是在釐清自己與家人財務狀況。可能需要花費一些心力，但其實是一個很值得的過程&lt;/p&gt;
&lt;h3 id=&quot;為什麼要買保險？一定要有保險嗎？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E7%82%BA%E4%BB%80%E9%BA%BC%E8%A6%81%E8%B2%B7%E4%BF%9D%E9%9A%AA%EF%BC%9F%E4%B8%80%E5%AE%9A%E8%A6%81%E6%9C%89%E4%BF%9D%E9%9A%AA%E5%97%8E%EF%BC%9F&quot; aria-label=&quot;為什麼要買保險？一定要有保險嗎？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;為什麼要買保險？一定要有保險嗎？&lt;/h3&gt;
&lt;!-- &lt;div style=&quot;opacity: 0&quot;
		 onclick=&quot;this.style=&apos;opacity: 1; transition: opacity 0.3s ease-in-out&apos;&quot;
&gt; --&gt;
&lt;ul&gt;
&lt;li&gt;如果你家真的很有錢，即使發生什麼意外、重大的疾病，都有辦法負擔，要不然，你就應該要買保險&lt;/li&gt;
&lt;li&gt;我們永遠無法預期明天會發生什麼事，而通常發生意外、重大的疾病的時候，都會有筆巨大的開銷，或失去收入，很可能就會掉入負債的循環&lt;/li&gt;
&lt;li&gt;一旦進到負債的循環，通常難以脫身&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- &lt;/div&gt; --&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;保險的本質是什麼？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E4%BF%9D%E9%9A%AA%E7%9A%84%E6%9C%AC%E8%B3%AA%E6%98%AF%E4%BB%80%E9%BA%BC%EF%BC%9F&quot; aria-label=&quot;保險的本質是什麼？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;保險的本質是什麼？&lt;/h3&gt;
&lt;!-- &lt;div style=&quot;opacity: 0&quot;
		 onclick=&quot;this.style=&apos;opacity: 1; transition: opacity 0.3s ease-in-out&apos;&quot;
&gt; --&gt;
&lt;ul&gt;
&lt;li&gt;保險是大家各掏一點錢出來，組成一個基金，即使一部分的人意外或疾病，突然有有鉅額開銷，也能夠從這筆基金應付這樣的緊急狀況&lt;/li&gt;
&lt;li&gt;就是人們互助一起分擔風險的一種方法。別忘了，一個人雖然走得快，但一群人可以走得遠。人類從來不是獨居動物，我們其實相當需要有其他人和我們一起分擔風險&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- &lt;/div&gt; --&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;所以我們到底應該保哪些？-額度要多少？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E6%89%80%E4%BB%A5%E6%88%91%E5%80%91%E5%88%B0%E5%BA%95%E6%87%89%E8%A9%B2%E4%BF%9D%E5%93%AA%E4%BA%9B%EF%BC%9F-%E9%A1%8D%E5%BA%A6%E8%A6%81%E5%A4%9A%E5%B0%91%EF%BC%9F&quot; aria-label=&quot;所以我們到底應該保哪些？ 額度要多少？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;所以我們到底應該保哪些？ 額度要多少？&lt;/h3&gt;
&lt;!-- &lt;div style=&quot;opacity: 0&quot;
		 onclick=&quot;this.style=&apos;opacity: 1; transition: opacity 0.3s ease-in-out&apos;&quot;
&gt; --&gt;
&lt;ul&gt;
&lt;li&gt;我相信絕大多數人，並不知道自己到底應該要保哪些保險、保多少額度，我們多數對於保險的知識，來自保險業務員&lt;/li&gt;
&lt;li&gt;但請一定要理解保險業務運作的商業模式：保險業務員主要的報酬來自於你投保之後的抽成，可以抽越多的保單，業務員一定會想辦法推薦，但那不一定是你需要的&lt;/li&gt;
&lt;li&gt;要釐清自己需要什麼保險，我們要先想一個問題，&lt;strong&gt;我們這輩子可能會面臨什麼樣的財務風險？&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;哪一些是最嚴重的？ 哪一些是相對還好的？ 現在身上有哪些責任要扛、家庭的開銷有多大？&lt;/li&gt;
&lt;li&gt;我們來嘗試著把人生會遇到的幾個財務風險列出來，並且根據影響程度、發生的機率來分析：&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 56.25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAAAsSAAALEgHS3X78AAAB8ElEQVQoz42TWW/aQBSF+f9vfe2WPrRKWlI1TVGcqE1CALVACGaxzSx2gETCKIjNYAK24fQOYUkrpPbh6GpGmm/OuXcmZnUsXPI8kuIaFyyHiluFM5RoeRzRTCAKJEKqjvyBzkMec99GwPlGoRCbqhQruQZeX5zgxfFHvDw/Qbaho+49AYMpx8gz4Q0NtN0cBsMywpE6uAU8hyvFRJeh0jZRJrCqvFuD7Au06eDEZ9Ay37B/vIe49gHX1hUCj2HGOKZcYMrYBh5JuVTMGQjUKeJat7ReA2ePDHetG3AnDeFk4HZKWPgS4iqHswMNVjKHhS3pAgavXMa4aiBm9zlkj22k1qLHVz3kQGRjHpCDKcNibiMaC7TyOozzX7jPFgHHhm8YuHz7BoV4XEWuofZgbMRIFqnZNTAZGfBJw34Jg54O3zfh0/64WoVvmhhRVa5800JfL6Ff1J8i/ylyTC5dchjO+HLCj76FydhEQE7n5NBO5/H90ylkuoCilsTRq30k3h2iRi1YRlZ6DlU9dKmH0V/AcAVUUQtaCvc5HdZ5Gql4Aj+PznCbyW+BW/DK4S5gSM9E9ZamurDt5XTVUHDXBBp12ue7Iot/AtdvLpICIkUf4uAr0p81NLOl/wNOJ7UldBeQpW6Q2Ivj9P0XNLIV/AajCBhuP57RYAAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/b72046fe543bcca3672b1b9b341b833d/8ac56/risks-light.webp 240w,
/static/b72046fe543bcca3672b1b9b341b833d/d3be9/risks-light.webp 480w,
/static/b72046fe543bcca3672b1b9b341b833d/e46b2/risks-light.webp 960w,
/static/b72046fe543bcca3672b1b9b341b833d/f992d/risks-light.webp 1440w,
/static/b72046fe543bcca3672b1b9b341b833d/eb054/risks-light.webp 1550w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/b72046fe543bcca3672b1b9b341b833d/8ff5a/risks-light.png 240w,
/static/b72046fe543bcca3672b1b9b341b833d/e85cb/risks-light.png 480w,
/static/b72046fe543bcca3672b1b9b341b833d/d9199/risks-light.png 960w,
/static/b72046fe543bcca3672b1b9b341b833d/07a9c/risks-light.png 1440w,
/static/b72046fe543bcca3672b1b9b341b833d/dca52/risks-light.png 1550w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/b72046fe543bcca3672b1b9b341b833d/d9199/risks-light.png&quot; alt=&quot;&amp;#x4E0D;&amp;#x540C;&amp;#x7A2E;&amp;#x7684;&amp;#x98A8;&amp;#x96AA;&amp;#x7684;&amp;#x6A5F;&amp;#x7387;&amp;#xFF0C;&amp;#x4EE5;&amp;#x53CA;&amp;#x5176;&amp;#x5C0D;&amp;#x8CA1;&amp;#x52D9;&amp;#x7684;&amp;#x5F71;&amp;#x97FF;&amp;#x7A0B;&amp;#x5EA6;&quot; title=&quot;&amp;#x4E0D;&amp;#x540C;&amp;#x7A2E;&amp;#x7684;&amp;#x98A8;&amp;#x96AA;&amp;#x7684;&amp;#x6A5F;&amp;#x7387;&amp;#xFF0C;&amp;#x4EE5;&amp;#x53CA;&amp;#x5176;&amp;#x5C0D;&amp;#x8CA1;&amp;#x52D9;&amp;#x7684;&amp;#x5F71;&amp;#x97FF;&amp;#x7A0B;&amp;#x5EA6;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;接著大致上把風險分成三塊，綠色、黃色、紅色&lt;/li&gt;
&lt;li&gt;綠色的部分雖然機率很高，但影響程度很小。如果有緊急預備金，是可以安然度過的&lt;/li&gt;
&lt;li&gt;黃色的部分，是我們這輩子難免會遇到，財務負擔也不小的風險，可能突然需要幾十萬的現金做手術、或有幾個月無法工作，我們應該重視它&lt;/li&gt;
&lt;li&gt;最後是紅色的部分，我們都不希望遇到，但&lt;strong&gt;一遇到就會讓整個家庭陷入巨大的財務困境&lt;/strong&gt;，如果你是家裡的經濟支柱，這一塊是絕對不能忽略的，請務必務必為自己買保險&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- &lt;/div&gt; --&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;每一種風險相對應的保險&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E6%AF%8F%E4%B8%80%E7%A8%AE%E9%A2%A8%E9%9A%AA%E7%9B%B8%E5%B0%8D%E6%87%89%E7%9A%84%E4%BF%9D%E9%9A%AA&quot; aria-label=&quot;每一種風險相對應的保險 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;每一種風險相對應的保險&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;接著，我們把每一種風險相對應的保險列出來，然後逐一介紹&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 56.25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAABYlAAAWJQFJUiTwAAABuElEQVQoz42SW2/TQBCF/f9feOENXhAVQhRRbk0oQb0DrRSom3tI0lzcOo0dJyRObO/azoftJi7QKupIR5qZnTl7ZnYVx5PUtSH1yyHVnslk5hLbYrEgtcjvdjuMRyP+t3/qIlPGM8G773U2dk7Z+lZHt2ZpYRAEjCdThqMx/YHB0Loh9H2BcG0C30trV1D8qMl2JZO5x9SRSD9Ib5s5gvcnTZ5s7fP07RG7ajvJD64qNEpZ+j31jkqFNeYJj/zZMZnsaz59fkOx8iPJV6LVvDooobbNJA7CEMdxcVwXJYyCWOUKwRJhuEjG0n9tU8tvUj59gdE5SNTolk2pa6GZ04RQRhfvfsmR2f6IEjd7nocQ4l5IKbFtO63xo1g3f1Nu9+lej2jpFqXILzSvaGqD9SPfji7ih2a1qbI2YvOoRr5l8eG4yOOXOzzLnPCzZaD8/UL3ISH0XOLVrGLLvOAsn0XXCjSqX2nWDimf59A6hfUKbwm9pX8Th/4cMTeQ3oTOZY9Ko0r9osG1aTycMFaY/rnluYx+2F55wKPnGTZyKkXNfhihSHa4uJMPfEmvq1I43+dc3cMYNPkD7mtGHiylX+sAAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/74e1e16f6bb5bb50d96e7bab222c8a98/8ac56/risk-insurance-map.webp 240w,
/static/74e1e16f6bb5bb50d96e7bab222c8a98/d3be9/risk-insurance-map.webp 480w,
/static/74e1e16f6bb5bb50d96e7bab222c8a98/e46b2/risk-insurance-map.webp 960w,
/static/74e1e16f6bb5bb50d96e7bab222c8a98/f992d/risk-insurance-map.webp 1440w,
/static/74e1e16f6bb5bb50d96e7bab222c8a98/882b9/risk-insurance-map.webp 1920w,
/static/74e1e16f6bb5bb50d96e7bab222c8a98/3241c/risk-insurance-map.webp 2874w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/74e1e16f6bb5bb50d96e7bab222c8a98/8ff5a/risk-insurance-map.png 240w,
/static/74e1e16f6bb5bb50d96e7bab222c8a98/e85cb/risk-insurance-map.png 480w,
/static/74e1e16f6bb5bb50d96e7bab222c8a98/d9199/risk-insurance-map.png 960w,
/static/74e1e16f6bb5bb50d96e7bab222c8a98/07a9c/risk-insurance-map.png 1440w,
/static/74e1e16f6bb5bb50d96e7bab222c8a98/29114/risk-insurance-map.png 1920w,
/static/74e1e16f6bb5bb50d96e7bab222c8a98/93ba6/risk-insurance-map.png 2874w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/74e1e16f6bb5bb50d96e7bab222c8a98/d9199/risk-insurance-map.png&quot; alt=&quot;&amp;#x4E0D;&amp;#x540C;&amp;#x7A2E;&amp;#x7684;&amp;#x98A8;&amp;#x96AA;&amp;#x7684;&amp;#x6A5F;&amp;#x7387;&amp;#xFF0C;&amp;#x4EE5;&amp;#x53CA;&amp;#x5176;&amp;#x5C0D;&amp;#x8CA1;&amp;#x52D9;&amp;#x7684;&amp;#x5F71;&amp;#x97FF;&amp;#x7A0B;&amp;#x5EA6;&quot; title=&quot;&amp;#x4E0D;&amp;#x540C;&amp;#x7A2E;&amp;#x7684;&amp;#x98A8;&amp;#x96AA;&amp;#x7684;&amp;#x6A5F;&amp;#x7387;&amp;#xFF0C;&amp;#x4EE5;&amp;#x53CA;&amp;#x5176;&amp;#x5C0D;&amp;#x8CA1;&amp;#x52D9;&amp;#x7684;&amp;#x5F71;&amp;#x97FF;&amp;#x7A0B;&amp;#x5EA6;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;h4 id=&quot;壽險&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%A3%BD%E9%9A%AA&quot; aria-label=&quot;壽險 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;壽險&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;理賠條件：死掉就給錢&lt;/li&gt;
&lt;li&gt;保險額度計算：&lt;code class=&quot;language-text&quot;&gt;[每一個你需要扶養的對象，到不需要扶養的狀況，總共需要多少錢]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;如果有伴侶、兄弟姊妹可以共同分擔，請和他們一起討論&lt;/li&gt;
&lt;li&gt;舉個實例：小貍的爸爸 65 歲，過去沒有儲蓄習慣，現在已經無法工作，平常生活費一個月 2.5 萬，只能靠兩個兒子支付，小貍和弟弟要一起分擔爸爸的經濟需求。以國人平均餘命 85 歲來估算，(85 - 65) = 20 年 x 12 個月 x 每個 2.5 萬 = 600萬，小貍和他弟弟共同分擔，兩個人都要投保 300 萬的壽險&lt;/li&gt;
&lt;li&gt;在有小孩後，請一定要重新計算額度，相信我，會差很多&lt;/li&gt;
&lt;li&gt;其他情況下，可以每三年重新算一次&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;失能險&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%A4%B1%E8%83%BD%E9%9A%AA&quot; aria-label=&quot;失能險 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;失能險&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;理賠條件：根據 &lt;a href=&quot;https://finfo.tw/articles/toolbox/disability_table&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;殘廢等級表&lt;/a&gt; 分 1 ~ 11 級，不同級會給不同比例的理賠&lt;/li&gt;
&lt;li&gt;值得注意的是，殘廢等級表主要涵蓋身體的缺失，年老而無法自理生活的情況，很可能不會被包含進去&lt;/li&gt;
&lt;li&gt;理賠方式：有分一次性給付，以及每年/每月給付兩種&lt;/li&gt;
&lt;li&gt;保險額度計算：&lt;code class=&quot;language-text&quot;&gt;[每一個你需要扶養的對象，每個月需要多少錢]＋[家人要扶養你，每個月要多少錢]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;舉個實例：假設小貍是家庭經濟支柱，只有他在賺錢，每個月生活費 6 萬，加上房貸 2 萬。如果小貍全身癱瘓要請看護，一個月要 3 萬。那麼小貍要保的額度，就要到每月 6 + 2 + 3 = 11 萬&lt;/li&gt;
&lt;li&gt;失能 / 長照險真的很重要，主要的經濟支柱無法工作其實比死掉還慘。我們簡單算一下，如果沒有保險理賠，十年的資金缺口有多大： 10 年 x 12 個月 x 11 萬  = 1320 萬，這只是 10 年喔，小孩還不見得長大，房貸也可能還沒還清&lt;/li&gt;
&lt;li&gt;一樣請和兄弟姊妹、伴侶一起討論，有小孩後，一定要重新計算額度&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;長照險&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E9%95%B7%E7%85%A7%E9%9A%AA&quot; aria-label=&quot;長照險 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;長照險&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;理賠條件：符合巴氏量表六項中的三項，或是認知功能(時間、場所、人) 3 項有 2 項缺失者。每年要重新評估&lt;/li&gt;
&lt;li&gt;值得注意的是，長照險衡量的標準，主要是自主生活的能力，身體部位的缺失，並不一定可以理賠到&lt;/li&gt;
&lt;li&gt;其他額度計算等項目同失能險&lt;/li&gt;
&lt;li&gt;請注意，其實還有類長照險，而且每一間保險公司的條款可能都不一樣，務必要仔細看過條款&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;長照險-vs-失能險&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E9%95%B7%E7%85%A7%E9%9A%AA-vs-%E5%A4%B1%E8%83%BD%E9%9A%AA&quot; aria-label=&quot;長照險 vs 失能險 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;長照險 v.s. 失能險&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;長照險與失能險並不是能互相取代的兩種保險，有交集，但也有個別無法涵蓋的部分&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 57.50000000000001%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAYAAABiDJ37AAAACXBIWXMAAAsSAAALEgHS3X78AAAB40lEQVQoz3VT2W7jMAzM/39QgOShARbYl1zdTZqzqK/4aprElhzfkqeUWufaLYGBaIEcDDV0p2kaqGhPFUWdg+UnRNkRaclRC4E4lQijGu+xQJLLS+1jf+fx8pQe4EYmdidCZMA6OFjsGOZ2gRen1FgQ3GON/4npqI/2guUR7OMbEVrwYptOB3MnwsTg+GtxrNySUGG5KzGzCgSRuBBeFLaJbAT82EGQ7PB+9ik38bYPMDUT/LEYnk1G6jJNuA0kocGa8ko0d6SaUNAbnfMEPnPwvBnj9/QX5SY2wR5T40o4s1NNOBiZGAwNncdJBSnq+zeUQqIUpR7z1Vthac014fYHwvH6iNHqgCXl50JC1NWVMMsyMMZQ1zVC7hGRjTBxaWQL5odHRJwI+ffIuSbc+AJrT2DrVxCyQVHkul+P3Ov10O/3wXmCQuRwTga5a5IhNim2sPI+MHyNyJREkyljFtrpCkdW4WU+w9PTAMPhEFJKdDjnUCrbyMozQuZqpxV8toMRxth4yt0vh5UytZdNIxGEIWzbxn6/v77ho/WqUC13VqW01BXyPEOalXqhU3ozKa97dxsXly9Am38ViFpgNBqh2+1iMhm3bRq3fWrUO5dvFd4qVYWe5+mR4jj+p+7xL1HxCR+oktiY8nvyAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/590e57454c1c2aa0e4e100f085c5b932/8ac56/insurance-compare.webp 240w,
/static/590e57454c1c2aa0e4e100f085c5b932/d3be9/insurance-compare.webp 480w,
/static/590e57454c1c2aa0e4e100f085c5b932/e46b2/insurance-compare.webp 960w,
/static/590e57454c1c2aa0e4e100f085c5b932/f992d/insurance-compare.webp 1440w,
/static/590e57454c1c2aa0e4e100f085c5b932/6a389/insurance-compare.webp 1549w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/590e57454c1c2aa0e4e100f085c5b932/8ff5a/insurance-compare.png 240w,
/static/590e57454c1c2aa0e4e100f085c5b932/e85cb/insurance-compare.png 480w,
/static/590e57454c1c2aa0e4e100f085c5b932/d9199/insurance-compare.png 960w,
/static/590e57454c1c2aa0e4e100f085c5b932/07a9c/insurance-compare.png 1440w,
/static/590e57454c1c2aa0e4e100f085c5b932/ccd6a/insurance-compare.png 1549w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/590e57454c1c2aa0e4e100f085c5b932/d9199/insurance-compare.png&quot; alt=&quot;72 &amp;#x9664;&amp;#x4EE5;&amp;#x5E74;&amp;#x5316;&amp;#x5831;&amp;#x916C;&amp;#x7387;&amp;#xFF0C;&amp;#x7B49;&amp;#x65BC;&amp;#x8CC7;&amp;#x7522;&amp;#x7FFB;&amp;#x500D;&amp;#x7684;&amp;#x6642;&amp;#x9593;&amp;#xFF08;&amp;#x5E74;&amp;#xFF09;&quot; title=&quot;72 &amp;#x9664;&amp;#x4EE5;&amp;#x5E74;&amp;#x5316;&amp;#x5831;&amp;#x916C;&amp;#x7387;&amp;#xFF0C;&amp;#x7B49;&amp;#x65BC;&amp;#x8CC7;&amp;#x7522;&amp;#x7FFB;&amp;#x500D;&amp;#x7684;&amp;#x6642;&amp;#x9593;&amp;#xFF08;&amp;#x5E74;&amp;#xFF09;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;table style=&quot;border-collapse: collapse; width: 600px;&quot;&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; width: 100px; padding: 5px&quot;&gt;險種&lt;/td&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;優點&lt;/td&gt;
						&lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;缺點&lt;/td&gt;
        &lt;/tr&gt;
				&lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;失能險&lt;/td&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;理賠條件明確、不用每年重新評估&lt;/td&gt;
						&lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;年紀大而無法自理，並不一有殘疾，賠不到&lt;/td&gt;
        &lt;/tr&gt;
				&lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;長照險&lt;/td&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;涵蓋年老失能的狀況&lt;/td&gt;
						&lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;理賠容易有爭議、每年要重新評估&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;ul&gt;
&lt;li&gt;不過，困難的點其實在這裡，長照/失能險的保險費通常不便宜，資源有限的情況下很難兩個都保&lt;/li&gt;
&lt;li&gt;我個人是會推薦年輕/壯年一點的時候買定期的失能險，因為理賠條件明確，也是年輕/壯年時期比較容易遇到的狀況&lt;/li&gt;
&lt;li&gt;年紀稍為大一點之後，補上長照險&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;重大傷病險&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E9%87%8D%E5%A4%A7%E5%82%B7%E7%97%85%E9%9A%AA&quot; aria-label=&quot;重大傷病險 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;重大傷病險&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;其實分成三種：重大疾病/特定傷病/重大傷病，涵蓋範圍分別是重大疾病 &amp;#x3C; 特定傷病 &amp;#x3C; 重大傷病，範圍越廣，保費越貴&lt;/li&gt;
&lt;/ul&gt;
&lt;table style=&quot;border-collapse: collapse; width: 600px;&quot;&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; width: 100px; padding: 5px&quot;&gt;險種&lt;/td&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;涵蓋範圍&lt;/td&gt;
        &lt;/tr&gt;
				&lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;重大疾病險&lt;/td&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;針對七項疾病，包含心肌梗塞、冠狀動脈繞道手術、腦中風、末期腎病變、&lt;strong&gt;癌症&lt;/strong&gt;、癱瘓及重大器官移植&lt;/td&gt;
        &lt;/tr&gt;
				&lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;特定傷病險&lt;/td&gt;
						&lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;針對二十二項特定傷病(可能上述七項重疾)，像是阿爾茲海默氏症、帕金森氏症等&lt;/td&gt;
        &lt;/tr&gt;
				&lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;重大傷病險&lt;/td&gt;
						&lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;依據&lt;a href=&quot;https://www.nhi.gov.tw/Content_List.aspx?n=3AE7F036072F88AF&amp;topn=5FE8C9FEAE863B46&quot;&gt;健保重大傷病卡資格&lt;/a&gt;，裡面有數百項&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;ul&gt;
&lt;li&gt;理賠方式：通常是一次性大筆理賠&lt;/li&gt;
&lt;li&gt;注意：每一張保單的項目可能有所不同，請看清楚條款&lt;/li&gt;
&lt;li&gt;保險額度計算：&lt;code class=&quot;language-text&quot;&gt;建議 100 萬以上&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;癌症險&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E7%99%8C%E7%97%87%E9%9A%AA&quot; aria-label=&quot;癌症險 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;癌症險&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;理賠條件：罹患不同程度的癌症有不同比例的理賠&lt;/li&gt;
&lt;li&gt;理賠方式：通常是一次大筆理賠，但也有針對手術、門診理賠&lt;/li&gt;
&lt;li&gt;保險額度計算：&lt;code class=&quot;language-text&quot;&gt;建議重度癌症的一次性理賠達 100 萬&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;癌症險跟重大傷病險，其實有滿大的重疊，所以我會建議，家族有癌症病史的人，資源允許的話再保&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;醫療險&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E9%86%AB%E7%99%82%E9%9A%AA&quot; aria-label=&quot;醫療險 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;醫療險&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;分成住院日額、手術理賠、實支實付三種理賠方式&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;住院日額：住院一天給一筆錢&lt;/li&gt;
&lt;li&gt;手術理賠：某一項手術給某一筆錢&lt;/li&gt;
&lt;li&gt;實支實付：只要是有動手術，在額度內支付，通常可以包含雜費＆自費項目&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;我個人會推薦實支實付，因為現在多數手術不用住院，醫院也不想要讓你住院住太久。此外，現代手術有很多自費的醫療器材項目，過去的住院日額、手術理賠都無法涵蓋&lt;/li&gt;
&lt;li&gt;保險額度計算：&lt;code class=&quot;language-text&quot;&gt;建議實支實付至少 20 萬&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;如果有兩張保單，其中一張要可以副本理賠&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;保險的順序&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E4%BF%9D%E9%9A%AA%E7%9A%84%E9%A0%86%E5%BA%8F&quot; aria-label=&quot;保險的順序 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;保險的順序&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;我最前面有說到，如果可以運用的資金有限，保險可以逐步到位&lt;/li&gt;
&lt;li&gt;順序的話，我個人會認為是：&lt;strong&gt;失能/長照險 → 壽險 → 重大疾病/特定傷病 → 實支實付醫療險 → 癌症險 → 意外險&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;定期--平準--終身險的差別&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%AE%9A%E6%9C%9F--%E5%B9%B3%E6%BA%96--%E7%B5%82%E8%BA%AB%E9%9A%AA%E7%9A%84%E5%B7%AE%E5%88%A5&quot; aria-label=&quot;定期  平準  終身險的差別 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;定期 / 平準 / 終身險的差別&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;在保保險的時候，一定會聽到業務員介紹終身險，但其實我們還有定期險以及平準型的保險&lt;/li&gt;
&lt;/ul&gt;
&lt;table style=&quot;border-collapse: collapse; width: 600px;&quot;&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; width: 100px; padding: 5px&quot;&gt;保險形式&lt;/td&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;繳費方式＆保障範圍&lt;/td&gt;
        &lt;/tr&gt;
				&lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;定期險&lt;/td&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;每一年繳費，保障的是接下來這一年，隔年沒繳，就沒有保障。每一年費用不同&lt;/td&gt;
        &lt;/tr&gt;
				&lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;平準型&lt;/td&gt;
						&lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;將接下來 N 年（例如：10 年）的保費平均算，這 10 年內每年繳一樣的費用。10 年過完的下一個 10 年的費用就會不同&lt;/td&gt;
        &lt;/tr&gt;
				&lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;終身險&lt;/td&gt;
						&lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;這 N 年繳（例如：20 年）這輩子的保費，每年保費一樣，20 年繳完終身都有保障&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;乍聽之下終身險比較有保障？ 真的嗎？&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;羊毛出在羊身上，你想要一輩子的保障，錢當然要自己出&lt;/li&gt;
&lt;li&gt;把這輩子的保障，集中在 20 年繳完，當然保費不會太便宜，或保的額度要很低&lt;/li&gt;
&lt;li&gt;考慮通膨的情況下，40 年後你大約 60~70 歲，真正比較頻繁申請保險理賠的時候，物價大約已經成長 2 倍，可以想一下，真的要用到的時候，額度夠嗎？&lt;/li&gt;
&lt;li&gt;我們在人生的每個階段，需要的保障額度其實不一樣：出社會無小孩 / 有小孩 / 小孩長大獨立，每個階段的經濟負擔並不同&lt;/li&gt;
&lt;li&gt;沒錯，年紀太大就沒有辦法再保險了，這是所有業務員推薦你買終身險的原因。但如果你可以有紀律地長期投資，照理說到那個年紀，你應該要能夠負擔這些費用了&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;小小結論是：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;如果你真不是個有紀律的長期投資者，請考慮終身險&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;但如果有辦法，請有紀律地做長期投資，並買定期/平準型的保險就好&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;買保險的眉角&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E8%B2%B7%E4%BF%9D%E9%9A%AA%E7%9A%84%E7%9C%89%E8%A7%92&quot; aria-label=&quot;買保險的眉角 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;買保險的眉角&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;查詢&lt;a href=&quot;https://www.foi.org.tw/Article.aspx?Lang=1&amp;#x26;Arti=1224&amp;#x26;Role=1&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;保險公司訴訟率&lt;/a&gt;，最高的幾個不要保，你不會想要人生已經低潮還要跟保險公司訴訟&lt;/li&gt;
&lt;li&gt;找已經做保險很久的業務員，並且從親友問過去是否積極協助理賠。你不會想要你受傷/生病的時候，你的業務員還愛理不理，自己準備那些文件真的很麻煩&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://finfo.tw/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Finfo 保險資訊站&lt;/a&gt; 這個網站真的真的非常好用，它幫你把台灣所有保險公司的保單都整理好了，並且可以讓自己配保險組合，計算額度是否足夠。規劃保險的時候必用！&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;step-5-長期投資&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#step-5-%E9%95%B7%E6%9C%9F%E6%8A%95%E8%B3%87&quot; aria-label=&quot;step 5 長期投資 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Step 5. 長期投資&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;我們終於來到第五步驟了！ 在存夠緊急備用金，也為自己和家人保好保險後，我們可以把多的資產，扣掉教育基金等等的必要費用，拿來做長期投資&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;介紹長期投資的方法之前，一定要先讓你理解複利的力量&lt;/p&gt;
&lt;h4 id=&quot;複利的力量---七二法則&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E8%A4%87%E5%88%A9%E7%9A%84%E5%8A%9B%E9%87%8F---%E4%B8%83%E4%BA%8C%E6%B3%95%E5%89%87&quot; aria-label=&quot;複利的力量   七二法則 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;複利的力量 - 七二法則&lt;/h4&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;figure style=&quot;max-width: 400px&quot;&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 41.66666666666667%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAYAAAD5nd/tAAAACXBIWXMAABYlAAAWJQFJUiTwAAABG0lEQVQoz41SwaqCUBD1/z/AlW7d5SJBFBdChAsRhUDTFkKJi5BQ1IKgPL1zH7dn0uINDDPOPXc8c+Yq+LFpmhjweDwwDAOu1yuezyfmZ4zLfOk0Zf7R9z1M04Tv+zgcDqI2b8xcYr8Zz5R5gczyPIfruqjr+gO4xLVti67rcLlcRH6/3/8YEkBn8Xa7CQAjfRxHATwej0jTVOTb7RaapsEwDKiqCl3XURTFb0OOQTYcMQgCxHGMJEkQhiGyLENVVWLU0+mE/X4vLu12OziOI6ThNGQqpVHm+lmWhc1mA8/zsF6v32NLsDSyiaJIyEMCXOZbQwkmK1JfrVawbVuwLcvy30v52DKtaRrxR47I/Hw+C8G/PRs2lr58Ti88y1wwudcW2wAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/6294b6c8a567230601d461942835dd92/8ac56/72rule.webp 240w,
/static/6294b6c8a567230601d461942835dd92/d3be9/72rule.webp 480w,
/static/6294b6c8a567230601d461942835dd92/e46b2/72rule.webp 960w,
/static/6294b6c8a567230601d461942835dd92/f992d/72rule.webp 1440w,
/static/6294b6c8a567230601d461942835dd92/5540a/72rule.webp 1844w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/6294b6c8a567230601d461942835dd92/8ff5a/72rule.png 240w,
/static/6294b6c8a567230601d461942835dd92/e85cb/72rule.png 480w,
/static/6294b6c8a567230601d461942835dd92/d9199/72rule.png 960w,
/static/6294b6c8a567230601d461942835dd92/07a9c/72rule.png 1440w,
/static/6294b6c8a567230601d461942835dd92/80cfc/72rule.png 1844w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/6294b6c8a567230601d461942835dd92/d9199/72rule.png&quot; alt=&quot;72 &amp;#x9664;&amp;#x4EE5;&amp;#x5E74;&amp;#x5316;&amp;#x5831;&amp;#x916C;&amp;#x7387;&amp;#xFF0C;&amp;#x7B49;&amp;#x65BC;&amp;#x8CC7;&amp;#x7522;&amp;#x7FFB;&amp;#x500D;&amp;#x7684;&amp;#x6642;&amp;#x9593;&amp;#xFF08;&amp;#x5E74;&amp;#xFF09;&quot; title=&quot;72 &amp;#x9664;&amp;#x4EE5;&amp;#x5E74;&amp;#x5316;&amp;#x5831;&amp;#x916C;&amp;#x7387;&amp;#xFF0C;&amp;#x7B49;&amp;#x65BC;&amp;#x8CC7;&amp;#x7522;&amp;#x7FFB;&amp;#x500D;&amp;#x7684;&amp;#x6642;&amp;#x9593;&amp;#xFF08;&amp;#x5E74;&amp;#xFF09;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;這是一個簡單估算你的資產多久可以翻倍的方法&lt;/li&gt;
&lt;li&gt;假設你做投資，每年報酬率 6 % ，那麼 72/6 = 12，你的資產 12 年後可以翻倍&lt;/li&gt;
&lt;li&gt;每年報酬率 18 % → 72/18 = 4 年資產可以翻倍&lt;/li&gt;
&lt;li&gt;猜猜看巴菲特平均年化報酬率是多少？&lt;/li&gt;
&lt;li&gt;你期待每年可以有幾 % 的投資報酬率呢？ 你覺得你的能力跟巴菲特比起來是如何呢？&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;多數投資人都對自己有過度的信心，設定過高的報酬率目標，最後就是承受過高的風險，而蒙受損失&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;事實上，可以到每年 6~8 % 就已經相當不錯。這也是簡單的長期投資工具，長期來說可以為我們做到的&lt;/li&gt;
&lt;li&gt;在進到我最推薦的長期投資方式之前，先讓我們對投資標的有初步的理解&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;投資標的選擇&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E6%8A%95%E8%B3%87%E6%A8%99%E7%9A%84%E9%81%B8%E6%93%87&quot; aria-label=&quot;投資標的選擇 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;投資標的選擇&lt;/h4&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 56.25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAABYlAAAWJQFJUiTwAAACDUlEQVQoz32S227aQBRF+f9f6Hur9KlS06pRmzSJXEGMIEDSFgzGF/D4EhMnEHDA2KvHBqRIafuwNdZ4zpp99pma7VlYU4vOzw4jZ0T6POUxcRibfRx7gDHosdko0sjF0lvE/QGxO8EyDAY3N/zqdMnuYohnFKKaChStZpPrVgs/8EnTKctFSL1+haZpDIdDsixkGdoUkRRFd8xnMxq6zvn5OQP5vxEQAi1EtUkyoecadEUD3xSHHtvS0XLC09yW74BsI5eEDnm4K8oFsA5CUuVT3Cds5RJm95VqaunzqXvNUaOOLi1mmQ/5XoVoK8JnJS0TS1GS7IoFRPJQtVrurT1FFgTUwlWAWni4iUvw5JOIq1kykvMm84Ut54fcP5o8eGOSscts7PBoS87OdPct69z1+F3XScwxNf9JYcY2TgkU8NDr86XxHe22Sc+65e3HI06uzpiYBj/Omnw9kU60a/QfXb6dNGjVb9DOdC5PdVaeOFQLxYd2m/ZkRLRUrJ6VZCdZrhzJzyOZ9WVQdtVylWE5zf0AXio/DMVfBry7vODN52OuLKMaSplfnqlK5AGFZFkOpYh2z+Nfqp5NlEacduq8Pz2mNzV4Xgto41XuDsq33g4Y7t/bXxxWKoHx+o6u2UbrXOBLhmkJzPYgcbgDqlfAVw73e+IwpHRZruEqlAw9igPoBbDM8NDy/4B/AFB4MNvvPhBWAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/a04640d7b0c45e03987f825630cbb989/8ac56/asset-category.webp 240w,
/static/a04640d7b0c45e03987f825630cbb989/d3be9/asset-category.webp 480w,
/static/a04640d7b0c45e03987f825630cbb989/e46b2/asset-category.webp 960w,
/static/a04640d7b0c45e03987f825630cbb989/f992d/asset-category.webp 1440w,
/static/a04640d7b0c45e03987f825630cbb989/882b9/asset-category.webp 1920w,
/static/a04640d7b0c45e03987f825630cbb989/3938d/asset-category.webp 2878w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/a04640d7b0c45e03987f825630cbb989/8ff5a/asset-category.png 240w,
/static/a04640d7b0c45e03987f825630cbb989/e85cb/asset-category.png 480w,
/static/a04640d7b0c45e03987f825630cbb989/d9199/asset-category.png 960w,
/static/a04640d7b0c45e03987f825630cbb989/07a9c/asset-category.png 1440w,
/static/a04640d7b0c45e03987f825630cbb989/29114/asset-category.png 1920w,
/static/a04640d7b0c45e03987f825630cbb989/0b569/asset-category.png 2878w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/a04640d7b0c45e03987f825630cbb989/d9199/asset-category.png&quot; alt=&quot;&amp;#x6295;&amp;#x8CC7;&amp;#x6A19;&amp;#x7684;&amp;#x7684;&amp;#x9078;&amp;#x64C7;&amp;#xFF0C;&amp;#x98A8;&amp;#x96AA;&amp;#x8207;&amp;#x6D41;&amp;#x52D5;&amp;#x6027;&amp;#x7684;&amp;#x6BD4;&amp;#x8F03;&quot; title=&quot;&amp;#x6295;&amp;#x8CC7;&amp;#x6A19;&amp;#x7684;&amp;#x7684;&amp;#x9078;&amp;#x64C7;&amp;#xFF0C;&amp;#x98A8;&amp;#x96AA;&amp;#x8207;&amp;#x6D41;&amp;#x52D5;&amp;#x6027;&amp;#x7684;&amp;#x6BD4;&amp;#x8F03;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;如果想知道更詳細的資產類別，以及其報酬率，可以看市場先生的&lt;a href=&quot;https://rich01.com/invest-asset-return/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;這篇文章&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;最適合我們的投資方式&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E6%9C%80%E9%81%A9%E5%90%88%E6%88%91%E5%80%91%E7%9A%84%E6%8A%95%E8%B3%87%E6%96%B9%E5%BC%8F&quot; aria-label=&quot;最適合我們的投資方式 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;最適合我們的投資方式&lt;/h4&gt;
&lt;figure&gt;
	&lt;blockquote&gt;
		&lt;p&gt;定期定額買費用率低的全市場或大型股指數型股票 ETF ＋ 全市場債券 ETF，並且長期持有&lt;/p&gt;
	&lt;/blockquote&gt;
&lt;/figure&gt;
&lt;p&gt;一下子看到一堆專有名詞可能覺得有點可怕，我們來說文解字一下，我們先從「全市場指數型股票 ETF」的最右邊開始&lt;/p&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 24.166666666666664%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAAAsSAAALEgHS3X78AAABOElEQVQY0z2QS2vCUBBG8/e7aDcuCoWuSgtCu2spbiqlbqQKmsZnxGhMjJpoonnoTYynN4H2g2Fg4J6Ze5TZ+oS9FfTmCVPniOVmbA8rTHfKyNbKbmx0jtGBnaYR6Dq7Tgff8xiNxwwHAwzDoMjlckF5rLs0hyEvjS33tTWvzZBvvc7T5x2371d8dN94bj6wMnV+rm/Qq1VGlQpqq8VXo0GtVkOTi4rkeY6iGjHuPiWIMmxPYG5SnJ1ZXrdwDSxvxmjZI/BW7NQfwoVJOJvhuy4bWb7vkyQJf1EKUHca09YjCTiVw3N+Zrk1mTgDqWNOdk7LeWRZuO02QkIs20btdun3+6iqii5VpGmKIrKcQ3xmLys55f8u4lNEmOxJRFx+pUh2PCKCgFw+dByHiYQUoLF0OZAuhRD8Au1wbqsncKFZAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/b28937fb41ad2cf79d901513d4d1fcb6/8ac56/explain.webp 240w,
/static/b28937fb41ad2cf79d901513d4d1fcb6/d3be9/explain.webp 480w,
/static/b28937fb41ad2cf79d901513d4d1fcb6/e46b2/explain.webp 960w,
/static/b28937fb41ad2cf79d901513d4d1fcb6/f992d/explain.webp 1440w,
/static/b28937fb41ad2cf79d901513d4d1fcb6/9fbc2/explain.webp 1560w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/b28937fb41ad2cf79d901513d4d1fcb6/8ff5a/explain.png 240w,
/static/b28937fb41ad2cf79d901513d4d1fcb6/e85cb/explain.png 480w,
/static/b28937fb41ad2cf79d901513d4d1fcb6/d9199/explain.png 960w,
/static/b28937fb41ad2cf79d901513d4d1fcb6/07a9c/explain.png 1440w,
/static/b28937fb41ad2cf79d901513d4d1fcb6/9f9a4/explain.png 1560w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/b28937fb41ad2cf79d901513d4d1fcb6/d9199/explain.png&quot; alt=&quot;&amp;#x6295;&amp;#x8CC7;&amp;#x6A19;&amp;#x7684;&amp;#x7684;&amp;#x9078;&amp;#x64C7;&amp;#xFF0C;&amp;#x98A8;&amp;#x96AA;&amp;#x8207;&amp;#x6D41;&amp;#x52D5;&amp;#x6027;&amp;#x7684;&amp;#x6BD4;&amp;#x8F03;&quot; title=&quot;&amp;#x6295;&amp;#x8CC7;&amp;#x6A19;&amp;#x7684;&amp;#x7684;&amp;#x9078;&amp;#x64C7;&amp;#xFF0C;&amp;#x98A8;&amp;#x96AA;&amp;#x8207;&amp;#x6D41;&amp;#x52D5;&amp;#x6027;&amp;#x7684;&amp;#x6BD4;&amp;#x8F03;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;ETF = Exchanged Trade Fund 交易所交易基金&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;指的是，可以在交易所交易的基金。一般的基金，一天只能買/賣一次，每天只會有一個結算的資產價值，但如果是 ETF 這種基金，隨時都可以在交易時間內下單進行買賣&lt;/li&gt;
&lt;li&gt;什麼又是「基金」呢？ 一群人集合一筆錢，一起做投資，買下多種標的，共同分享報酬，就是基金&lt;/li&gt;
&lt;li&gt;ETF 就只是一種交易比較方便的基金，它可以是根據某個指標投資，也可以是人為管理，它可以投資極高風險的資產，也可以是投資股票。&lt;strong&gt;不要以為買 ETF 就是低風險&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;標的總類：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;可以有股票、債券、房地產，甚至最近也有虛擬貨幣的基金了&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;基金管理方式：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;指數型：意思是會有一個公式/指標，直接決定該基金要買進哪些公司、多少比例的股票。例如：元大 0050，追蹤的是台灣 50 指數，該基金會去買台灣市值前 50 大的公司的股票&lt;/li&gt;
&lt;li&gt;主動型：如果不是追蹤指數，我們可以簡單歸類為「人為主動管理型」，就是有個或一群基金管理人在操盤。銀行理專推的主要屬於這類型&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;投資標的範圍：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;全市場：指的是盡可能買下整個市場上所有標的。例如：全世界所有公司、全美國所有公司。實務上當然不可能做到，所以會進行抽樣&lt;/li&gt;
&lt;li&gt;大型股指的通常是該市場內，公司市值最高的前 N 間公司&lt;/li&gt;
&lt;li&gt;除此之外，還有科技類股、醫療股、5G/IOT、新興市場等等各種市場範圍的基金&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;為什麼要買「指數型」-etf&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E7%82%BA%E4%BB%80%E9%BA%BC%E8%A6%81%E8%B2%B7%E3%80%8C%E6%8C%87%E6%95%B8%E5%9E%8B%E3%80%8D-etf&quot; aria-label=&quot;為什麼要買「指數型」 etf permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;為什麼要買「指數型」 ETF?&lt;/h4&gt;
&lt;!-- &lt;div style=&quot;opacity: 0&quot;
		 onclick=&quot;this.style=&apos;opacity: 1; transition: opacity 0.3s ease-in-out&apos;&quot;
&gt; --&gt;
&lt;ul&gt;
&lt;li&gt;指數型 ETF 費用很低，讓我們的資產不會被基金公司吃掉&lt;/li&gt;
&lt;li&gt;人為管理型的 ETF，費用率動輒 1~2% 甚至更多，但 0050 是 0.355%，美股的 ETF 通常更低，例如投資全美國市場的 VTI ，費用率只有 0.03%&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;1~2% 跟 0.03% 差很多嗎？&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;假設你買了兩種基金，年化報酬率都是 6%，A 基金每年會被扣掉 1% 費用，B 基金每年會被扣掉 0.03% 費用，假設投入 100 萬，30 年後&lt;/li&gt;
&lt;li&gt;投入 A 基金的資產：100 萬 x (1.05)^30 = 432 萬&lt;/li&gt;
&lt;li&gt;投入 B 基金的資產：100 萬 x (1.0597)^30 = 569 萬&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;指數型 ETF 的指標明確，相對可驗證歷史成效。人為管理的基金，你根本不知道是哪些人在管、他們在想什麼&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- &lt;/div&gt; --&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;為什麼要買下全市場或大型股的指數型-etf？-而不是買幾間績優公司的股票？-或是人為管理的主動型基金？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E7%82%BA%E4%BB%80%E9%BA%BC%E8%A6%81%E8%B2%B7%E4%B8%8B%E5%85%A8%E5%B8%82%E5%A0%B4%E6%88%96%E5%A4%A7%E5%9E%8B%E8%82%A1%E7%9A%84%E6%8C%87%E6%95%B8%E5%9E%8B-etf%EF%BC%9F-%E8%80%8C%E4%B8%8D%E6%98%AF%E8%B2%B7%E5%B9%BE%E9%96%93%E7%B8%BE%E5%84%AA%E5%85%AC%E5%8F%B8%E7%9A%84%E8%82%A1%E7%A5%A8%EF%BC%9F-%E6%88%96%E6%98%AF%E4%BA%BA%E7%82%BA%E7%AE%A1%E7%90%86%E7%9A%84%E4%B8%BB%E5%8B%95%E5%9E%8B%E5%9F%BA%E9%87%91%EF%BC%9F&quot; aria-label=&quot;為什麼要買下全市場或大型股的指數型 etf？ 而不是買幾間績優公司的股票？ 或是人為管理的主動型基金？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;為什麼要買下全市場或大型股的指數型 ETF？ 而不是買幾間績優公司的股票？ 或是人為管理的主動型基金？&lt;/h4&gt;
&lt;!-- &lt;div style=&quot;opacity: 0&quot;
		 onclick=&quot;this.style=&apos;opacity: 1; transition: opacity 0.3s ease-in-out&apos;&quot;
&gt; --&gt;
&lt;ul&gt;
&lt;li&gt;2008 年的時候，有一個人叫巴菲特，嘿對，就是眾所皆知的股神，他向投資界下戰帖，他決定買一個追蹤標普 500 的指數型基金，然後放著 10 年不管它，尋找有意挑戰的基金公司，可以組出比它好的投資組合&lt;/li&gt;
&lt;li&gt;有一間叫 Protégé Partners 的基金公司接受挑戰，他們總共動用了 200 位基金管理人，組了 5 個基金組合，每個都是由多個基金組成&lt;/li&gt;
&lt;li&gt;2018 年，結果出爐，巴菲特放著 10 年不管的追蹤標普 500 的指數型基金，整體報酬率完勝這五個基金組合&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 45.833333333333336%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsSAAALEgHS3X78AAABS0lEQVQoz1WRh5LDMAhE/f9/eJfiFNfYlmvikkJ4OPbldkYjhGBZwJvud2maRuI4kSRJJYwiidSOoljiZPZhp+lF/bHFhfrGF4Sh+fgLglDKshLvcslkv/fn4x/MWThnd1mWUlWVntp82KW955PnucU5jSsKp8Ja8cZxlMfjIW3bacVIQFXXQiGQaRKBAHXDMMpdu0IRqDWWgq/Xy95emqZWHeLNdmfkeV7Idre3ABJpG/CPoufzaXbXdSqklZ/fjd1GSNUsy9fkcZxkmiY5nc7mg4BZAmZFcZCoEAoDYlFthLTGrMD5HBjZNyGjWBRC6Nwciwin5LR6PJ6sw0/Lf0GQQManfziaj6TwM9tlPKtaXQTt+7rMf4TLArAhpOriu15va2ssoK6bdRQs4zvPCKnCWdqjIp9LIoQMH9xuvfR9b/YwDHZYIsTkgTdaB7AvpuipFQAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/d1146f0688fd7b4a5ad2dc7a0ae03bcb/8ac56/buffett-bet-result.webp 240w,
/static/d1146f0688fd7b4a5ad2dc7a0ae03bcb/d3be9/buffett-bet-result.webp 480w,
/static/d1146f0688fd7b4a5ad2dc7a0ae03bcb/e46b2/buffett-bet-result.webp 960w,
/static/d1146f0688fd7b4a5ad2dc7a0ae03bcb/5c6e0/buffett-bet-result.webp 1388w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/d1146f0688fd7b4a5ad2dc7a0ae03bcb/8ff5a/buffett-bet-result.png 240w,
/static/d1146f0688fd7b4a5ad2dc7a0ae03bcb/e85cb/buffett-bet-result.png 480w,
/static/d1146f0688fd7b4a5ad2dc7a0ae03bcb/d9199/buffett-bet-result.png 960w,
/static/d1146f0688fd7b4a5ad2dc7a0ae03bcb/c1bea/buffett-bet-result.png 1388w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/d1146f0688fd7b4a5ad2dc7a0ae03bcb/d9199/buffett-bet-result.png&quot; alt=&quot;&amp;#x5DF4;&amp;#x83F2;&amp;#x7279; 10 &amp;#x5E74;&amp;#x8CED;&amp;#x6CE8;&amp;#x7684;&amp;#x7D50;&amp;#x679C;&quot; title=&quot;&amp;#x5DF4;&amp;#x83F2;&amp;#x7279; 10 &amp;#x5E74;&amp;#x8CED;&amp;#x6CE8;&amp;#x7684;&amp;#x7D50;&amp;#x679C;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
    &lt;/span&gt;
	&lt;figcaption&gt;source:&lt;a href=&quot;https://www.berkshirehathaway.com/letters/2016ltr.pdf&quot;&gt;Berkshire&amp;apos;s open letter in 2016&lt;/a&gt;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;!-- &lt;/div&gt; --&gt;
&lt;!-- &lt;div style=&quot;opacity: 0&quot;
		 onclick=&quot;this.style=&apos;opacity: 1; transition: opacity 0.3s ease-in-out&apos;&quot;
&gt; --&gt;
&lt;ul&gt;
&lt;li&gt;這故事告訴我們，即使動用大量的專業基金管理人，絕大多數人為管理的基金，仍然難以贏過追蹤標普 500 指數(我們俗稱大盤指數)的指數型基金&lt;/li&gt;
&lt;li&gt;根據標普道瓊指數公司（S&amp;#x26;P Dow Jones Indices）在 2019 年的研究，他們發現，過去 10 年，有 85% 的主動型基金，表現不如標普 500 指數。如果時間拉長到 15 年，落後標普 500 指數的主動型基金將近 92%&lt;/li&gt;
&lt;li&gt;台灣有近千檔基金，美國有 8000 多檔，你覺得你找得到那 8% 可以勝過大盤的基金嗎？&lt;/li&gt;
&lt;li&gt;台灣有 1 千多家上市櫃公司，美國有 4~5 千家上市公司，全世界有超過 63 萬家公司，你打算怎麼找、怎麼買，讓自己的年化報酬率超過標普 500 指數？&lt;/li&gt;
&lt;li&gt;成千上萬的基金管理人全職投入，都難以做到。我們為什麼要浪費這麼多力氣研究、看盤，而不去買追蹤大盤指數的指數型 ETF，然後把時間省下來精進自己的專業，或為社會創造更多價值呢？&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- &lt;/div&gt; --&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;全市場或大型股的指數型股票-etf-長期會獲利的基礎假設&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%85%A8%E5%B8%82%E5%A0%B4%E6%88%96%E5%A4%A7%E5%9E%8B%E8%82%A1%E7%9A%84%E6%8C%87%E6%95%B8%E5%9E%8B%E8%82%A1%E7%A5%A8-etf-%E9%95%B7%E6%9C%9F%E6%9C%83%E7%8D%B2%E5%88%A9%E7%9A%84%E5%9F%BA%E7%A4%8E%E5%81%87%E8%A8%AD&quot; aria-label=&quot;全市場或大型股的指數型股票 etf 長期會獲利的基礎假設 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;全市場或大型股的指數型股票 ETF 長期會獲利的基礎假設&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;當我們買下全市場型，或大型股的指數型 ETF，可以想成投資整個市場的所有公司，或最大的那些公司&lt;/li&gt;
&lt;li&gt;照理說，如果整個國家的經濟有在成長，投資將近所有公司的話，應該可以獲得經濟成長的果實&lt;/li&gt;
&lt;li&gt;而如果整個國家所有公司、或最大的公司們，全部都沒有賺錢的話，那意味著國家的經濟衰退中。這種時候我們要擔心的可能不是股票跌，而是可能會失業&lt;/li&gt;
&lt;li&gt;如果我們回顧歷史，僅有在經濟大衰退來臨時，會有這種情況，短則幾個月，最長 5 年&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;還有一個理由你不該買人為管理的基金&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E9%82%84%E6%9C%89%E4%B8%80%E5%80%8B%E7%90%86%E7%94%B1%E4%BD%A0%E4%B8%8D%E8%A9%B2%E8%B2%B7%E4%BA%BA%E7%82%BA%E7%AE%A1%E7%90%86%E7%9A%84%E5%9F%BA%E9%87%91&quot; aria-label=&quot;還有一個理由你不該買人為管理的基金 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;還有一個理由你不該買人為管理的基金&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;就是&lt;strong&gt;利益衝突&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;我們只要想清楚一件事就好，這些基金公司，是如何賺錢的？&lt;/li&gt;
&lt;li&gt;基金公司的主要收入，其實是收「管理費」，我們把錢給他們管理的時候，他們就可以收一筆固定的費用。因此他們會希望我們把越多錢給他們管理，就可以賺越多。他們確實有誘因創造更高的報酬率。然而，他們也有誘因，希望我們不要把錢領出來。而什麼情況我們會想贖回？ 通常是基金一直賠錢，或是覺得賺得夠多的時候&lt;/li&gt;
&lt;li&gt;意思就是說，基金管理人，不會想要基金的報酬率太高，不然我們覺得賺飽就會贖回賣出，他們就收不到管理費了&lt;/li&gt;
&lt;li&gt;這就是利益衝突，整個基金公司的商業模式，讓公司的利益，與投資人的利益相衝突&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;為什麼還要再買全市場指數型債券-etf-？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E7%82%BA%E4%BB%80%E9%BA%BC%E9%82%84%E8%A6%81%E5%86%8D%E8%B2%B7%E5%85%A8%E5%B8%82%E5%A0%B4%E6%8C%87%E6%95%B8%E5%9E%8B%E5%82%B5%E5%88%B8-etf-%EF%BC%9F&quot; aria-label=&quot;為什麼還要再買全市場指數型債券 etf ？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;為什麼還要再買全市場指數型債券 ETF ？&lt;/h4&gt;
&lt;!-- &lt;div style=&quot;opacity: 0&quot;
		 onclick=&quot;this.style=&apos;opacity: 1; transition: opacity 0.3s ease-in-out&apos;&quot;
&gt; --&gt;
&lt;ul&gt;
&lt;li&gt;相比於現金、債券，股票是一個相對風險較高的資產，而債券這項資產的走勢，經常與股票無相關，或甚至些微負相關 (相關係數 0.3 ~ -0.3 之間)&lt;/li&gt;
&lt;li&gt;配置一定比例的債券，可以讓我們在股災來臨時，減少跌幅&lt;/li&gt;
&lt;li&gt;減少跌幅，不僅僅是讓資產不要減少這麼多，更重要的是避免過度恐慌，全數在低價時賣出&lt;/li&gt;
&lt;li&gt;最後是個有趣的數學現象，第一年賠 20% 的時候，第二年其實不是賺 20% 就會賺回來。你覺得第二年要賺多少 % 才賺回來？&lt;/li&gt;
&lt;li&gt;藉由不同屬性的資產配置，讓資產價值的波動幅度減少，以避免恐慌心理，並提高報酬率，就是「資產配置」的目的&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- &lt;/div&gt; --&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;資產配置的原則&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E8%B3%87%E7%94%A2%E9%85%8D%E7%BD%AE%E7%9A%84%E5%8E%9F%E5%89%87&quot; aria-label=&quot;資產配置的原則 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;資產配置的原則&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;每一種資產項目的占比不要大到影響力太大 (&gt;25%)，也不要小到沒有影響力 (&amp;#x3C;5%)&lt;/li&gt;
&lt;li&gt;每一種資產項目，盡可能涵蓋整個市場，費用率越低越好&lt;/li&gt;
&lt;li&gt;每一種資產項目之間，盡可能是零相關、低度負相關或低度正相關 (相關係數 0.3 ~ -0.3 之間)&lt;/li&gt;
&lt;li&gt;以股票為主，作為長期獲利的主力&lt;/li&gt;
&lt;li&gt;可以根據個人偏好做比例、標的選上的調整，要是你自己會相信的標的，不然一直換，不會有效益&lt;/li&gt;
&lt;li&gt;最基本且簡單的組合：股票 80% + 債券 20%，如果想要更低風險，就調高債券比例，如果想要追求更高報酬，就調高股票比例&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;為什麼要「定期定額」？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E7%82%BA%E4%BB%80%E9%BA%BC%E8%A6%81%E3%80%8C%E5%AE%9A%E6%9C%9F%E5%AE%9A%E9%A1%8D%E3%80%8D%EF%BC%9F&quot; aria-label=&quot;為什麼要「定期定額」？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;為什麼要「定期定額」？&lt;/h4&gt;
&lt;!-- &lt;div style=&quot;opacity: 0&quot;
		 onclick=&quot;this.style=&apos;opacity: 1; transition: opacity 0.3s ease-in-out&apos;&quot;
&gt; --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;節省時間與精力&lt;/strong&gt;：不用想什麼時候買進，省下研究、決策時間、價格到底是高還是底&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;人其實意志不堅&lt;/strong&gt;：人其實很容易被新聞、市場波動影響，而不斷改變自己的想法，最後的結果通常就是賠，或賺得不多&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;分散風險&lt;/strong&gt;：如果每隔一段期間就買，有時候雖然會買在高點，但也有機會買在低點&lt;/li&gt;
&lt;li&gt;符合一班上班族的資金流動，每個月領薪水，就可以撥一筆去投資，某種程度強迫自己儲蓄&lt;/li&gt;
&lt;li&gt;每年買一次、每季買一次、每月買一次，有差嗎？ 如果是長期持有，其實差異不大 → &lt;a href=&quot;https://rich01.com/sip-plan-frequency-excel-test/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;數據實證 by 市場先生&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- &lt;/div&gt; --&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;為什麼要長期持有？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E7%82%BA%E4%BB%80%E9%BA%BC%E8%A6%81%E9%95%B7%E6%9C%9F%E6%8C%81%E6%9C%89%EF%BC%9F&quot; aria-label=&quot;為什麼要長期持有？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;為什麼要長期持有？&lt;/h4&gt;
&lt;!-- &lt;div style=&quot;opacity: 0&quot;
		 onclick=&quot;this.style=&apos;opacity: 1; transition: opacity 0.3s ease-in-out&apos;&quot;
&gt; --&gt;
&lt;ul&gt;
&lt;li&gt;如果你是買股票，公司賺錢是需要時間的！&lt;/li&gt;
&lt;li&gt;如果你是買債券，領債券的利息，也需要時間！&lt;/li&gt;
&lt;li&gt;想要短期內獲得高報酬，只有兩種可能，一是找到發放高額股利的公司，二是找到股價飆漲的公司，而且你還要買在低點&lt;/li&gt;
&lt;li&gt;同上面有提到的問題，台灣有 1 千多家上市櫃公司，美國有 4~5 千家上市公司，全世界有超過 63 萬家公司，你打算怎麼找？&lt;/li&gt;
&lt;li&gt;而且，股價飆漲，就意味著價格波動較大，風險相對就比較高&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- &lt;/div&gt; --&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;長期投資的心法-總結&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E9%95%B7%E6%9C%9F%E6%8A%95%E8%B3%87%E7%9A%84%E5%BF%83%E6%B3%95-%E7%B8%BD%E7%B5%90&quot; aria-label=&quot;長期投資的心法 總結 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;長期投資的心法 (總結)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;雞蛋不要放在同一個籃子，盡可能買下整個市場的標的，而不是單獨一個&lt;/li&gt;
&lt;li&gt;遵守投資紀律，定期定額投入，並且長期持有，不要浪費時間分析標的、進出場時間、價格到底偏高還偏低&lt;/li&gt;
&lt;li&gt;選擇費用率低的指數型基金&lt;/li&gt;
&lt;li&gt;設定合理的投資報酬率目標，並做資產配置&lt;/li&gt;
&lt;li&gt;記得股息再投入，並且每年再平衡一次&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;標的選擇---台灣市場&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E6%A8%99%E7%9A%84%E9%81%B8%E6%93%87---%E5%8F%B0%E7%81%A3%E5%B8%82%E5%A0%B4&quot; aria-label=&quot;標的選擇   台灣市場 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;標的選擇 - 台灣市場&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;指數型股票 ETF&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;大型股 - 0050, 006208&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;很抱歉台灣沒有全市場型股票 ETF，台灣的債券 ETF 我之前有買過富邦美債 7-10 年，但發現費用率真的偏高，現在還沒有仔細研究是否有費用率相對低的債券 ETF&lt;/p&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;標的選擇---美國市場&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E6%A8%99%E7%9A%84%E9%81%B8%E6%93%87---%E7%BE%8E%E5%9C%8B%E5%B8%82%E5%A0%B4&quot; aria-label=&quot;標的選擇   美國市場 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;標的選擇 - 美國市場&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;指數型股票 ETF&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;美國全市場 - VTI, IWV, ITOT&lt;/li&gt;
&lt;li&gt;美國大型股 - SPY, VOO, IVV&lt;/li&gt;
&lt;li&gt;全世界市場股票 - VT&lt;/li&gt;
&lt;li&gt;美國以外市場股票 - VXUS&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;指數型債券 ETF&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;全世界債券 - BND&lt;/li&gt;
&lt;li&gt;美國國債 - SHY, IEI, IEF, TLT, GOVT&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;資產配置型 ETF&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;AOA, AOR, AOM, AOK&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;不想研究的話，推薦 VT + BND，直接買下全世界公司的股票＋債券&lt;/p&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;美股-vs-台股-vs-複委託&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E7%BE%8E%E8%82%A1-vs-%E5%8F%B0%E8%82%A1-vs-%E8%A4%87%E5%A7%94%E8%A8%97&quot; aria-label=&quot;美股 vs 台股 vs 複委託 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;美股 v.s. 台股 v.s. 複委託&lt;/h3&gt;
&lt;table style=&quot;border-collapse: collapse; width: 600px;&quot;&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; width: 100px; padding: 5px&quot;&gt;&lt;/td&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;優點&lt;/td&gt;
						&lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;缺點&lt;/td&gt;
        &lt;/tr&gt;
				&lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;台股&lt;/td&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;開戶容易、遺產好處理、不需要電匯費用&lt;/td&gt;
						&lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;基金管理費用高、交易手續費高、市場容易被少數法人影響&lt;/td&gt;
        &lt;/tr&gt;
				&lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;美國券商開戶買美股&lt;/td&gt;
						&lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;很方便買下全世界股票＆債券、多數零交易手續費、市場規模大不易被少數法人影響、基金管理費用低&lt;/td&gt;
						&lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;電匯一次 600~1200 台幣、遺產處理不易、一股的價格可能就很高，不易做資產配置&lt;/td&gt;
        &lt;/tr&gt;
				&lt;tr&gt;
            &lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;台股複委託買美股&lt;/td&gt;
						&lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;遺產好處理&lt;/td&gt;
						&lt;td style=&quot;border: 1px solid black; padding: 5px&quot;&gt;每次下單都要手續費且很貴&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;具體來說要如何開始長期投資呢？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%85%B7%E9%AB%94%E4%BE%86%E8%AA%AA%E8%A6%81%E5%A6%82%E4%BD%95%E9%96%8B%E5%A7%8B%E9%95%B7%E6%9C%9F%E6%8A%95%E8%B3%87%E5%91%A2%EF%BC%9F&quot; aria-label=&quot;具體來說要如何開始長期投資呢？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;具體來說要如何開始長期投資呢？&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;台灣股票：到任一證券商開一個證券戶即可&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;注意不要違約交割，不過定期定額的話不會有違約交割的問題&lt;/li&gt;
&lt;li&gt;一張買不起，可以買零股&lt;/li&gt;
&lt;li&gt;個人推富邦＆國泰證券，都有定期定額手續費 1 元優惠&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;美國股票：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;複委託：去台灣的證券商申請複委託，之後用 App 就可以下單&lt;/li&gt;
&lt;li&gt;美國券商直接開戶：eToro、德美利證券、第一證券、盈透證券&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;券商挑選依據：是否有想買的標的，交易手續費、出金、入金的難易度及費用、是否受監管、介面操作、遺產處理&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;如何檢視自己的投資成效&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%08%08%E5%A6%82%E4%BD%95%E6%AA%A2%E8%A6%96%E8%87%AA%E5%B7%B1%E7%9A%84%E6%8A%95%E8%B3%87%E6%88%90%E6%95%88&quot; aria-label=&quot;如何檢視自己的投資成效 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;如何檢視自己的投資成效&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;每年算一次投資報酬率&lt;/li&gt;
&lt;li&gt;範例：&lt;a href=&quot;https://docs.google.com/spreadsheets/d/182I2W922eyfp3cmw0xJF5JkusiZjgs2fWNz9rME9JZo/edit?usp=sharing&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;google sheet&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;馬上行動&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E9%A6%AC%E4%B8%8A%E8%A1%8C%E5%8B%95&quot; aria-label=&quot;馬上行動 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;馬上行動&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;開始記帳&lt;/li&gt;
&lt;li&gt;去券商開戶&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;其他理財經典問題&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%85%B6%E4%BB%96%E7%90%86%E8%B2%A1%E7%B6%93%E5%85%B8%E5%95%8F%E9%A1%8C&quot; aria-label=&quot;其他理財經典問題 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;其他理財經典問題&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;要買車嗎？&lt;/li&gt;
&lt;li&gt;買房子好還是租房子好？&lt;/li&gt;
&lt;li&gt;要買儲蓄險/投資型保單嗎？&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;學習資源&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%AD%B8%E7%BF%92%E8%B3%87%E6%BA%90&quot; aria-label=&quot;學習資源 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;學習資源&lt;/h2&gt;
&lt;p&gt;從有趣、好吸收，到比較進階排序如下：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/channel/UC45i13dEfEVac2IEJT_Nr5Q&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;柴鼠兄弟&lt;/a&gt; (youtube、書)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.cmoney.tw/learn/course/cmoney&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;CMoney 理財小學堂&lt;/a&gt;（文章）&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.instagram.com/goodgood.tw/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;好好理財&lt;/a&gt;（IG）&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.books.com.tw/products/0010493110&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;第一次領薪水就該懂的理財方法&lt;/a&gt;（書）&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://hahow.in/courses/5ca2cee872a72f0021514421/main?mts_s=ap&amp;#x26;mts_m=ha&amp;#x26;oasId=5e05de6f22d1190167014c22&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;小資族保險的第一堂入門課&lt;/a&gt; (線上課程)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://hahow.in/courses/5a2659df603553001e3d2919/main?mts_s=ap&amp;#x26;mts_m=ha&amp;#x26;oasId=5e05de6f22d1190167014c22&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;ETF 投資全球：帶你量身打造專屬資產配置&lt;/a&gt; (線上課程)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://hahow.in/courses/5e46b7f85b02f600245ade9b/main?mts_s=ap&amp;#x26;mts_m=ha&amp;#x26;oasId=5e05de6f22d1190167014c22&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;動盪時代的資產配置：王伯達人生財務規劃學&lt;/a&gt; (線上課程)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.facebook.com/Mr.Market.tw&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;市場先生&lt;/a&gt; (FB、Blog)&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.books.com.tw/products/0010834750&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;耶魯操盤手：非典型成功&lt;/a&gt;（書）&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.facebook.com/GreenHornFans/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;綠角財經筆記&lt;/a&gt;（FB、Blog）&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;實用工具&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%AF%A6%E7%94%A8%E5%B7%A5%E5%85%B7&quot; aria-label=&quot;實用工具 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;實用工具&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://finfo.tw/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Finfo 保險資訊站&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.moneydj.com/etf/x/Tool/Tool0001.xdjhtm&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;ETF 定期定額報酬率試算&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.portfoliovisualizer.com/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Portfolio Visualizer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Basic Tutorial of Kubernetes]]></title><description><![CDATA[Kubernetes is one of the most important tools for managing the deployments of thousands of services in modern DevOps. With kubernetes, we can easily manage our application, and we can more effectively manage our computing resources (CPU, memory, storage). In this article, we will introduce the fundamental concepts pod, service, deployment and ingress.]]></description><link>https://wei-ming.tw/posts/kubernetes-overview</link><guid isPermaLink="false">https://wei-ming.tw/posts/kubernetes-overview</guid><pubDate>Tue, 30 Mar 2021 19:12:04 GMT</pubDate><content:encoded>&lt;h3 id=&quot;what-is-kubernetes-k8s-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-is-kubernetes-k8s-&quot; aria-label=&quot;what is kubernetes k8s  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What is Kubernetes (k8s) ?&lt;/h3&gt;
&lt;figure&gt;
	&lt;img src=&quot;https://images.pexels.com/photos/2064123/pexels-photo-2064123.jpeg?auto=compress&amp;amp;cs=tinysrgb&amp;amp;dpr=2&amp;amp;h=750&amp;amp;w=1260&quot; alt=&quot;flight-instrument&quot;&gt;
	&lt;figcaption&gt;Photographer: Rafael Cosquiere (https://www.pexels.com/zh-tw/photo/2064123/) &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;Kubernetes is just like the control panel (flight instrucment) of an aircraft.&lt;/li&gt;
&lt;li&gt;For aviators, they have lots of component to control and manage, so there is a control panel for them.&lt;/li&gt;
&lt;li&gt;For developers, when we have lots of computer to manage, so there is Kubernetes for us!&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;figure&gt;
	&lt;blockquote&gt;
		&lt;p&gt;In short, Kubernetes is a tool for developers to manage a cluster of computers.&lt;/p&gt;
	&lt;/blockquote&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;figure&gt;
	&lt;img src=&quot;https://avatars.githubusercontent.com/u/13629408?s=200&amp;amp;v=4&quot; alt=&quot;kubernetes icon&quot;&gt;
	&lt;figcaption&gt; If you see the shape of Kubernetes logo, it&amp;apos;s a rudder! &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;think-of-you-have-lots-of-service-to-manage&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#think-of-you-have-lots-of-service-to-manage&quot; aria-label=&quot;think of you have lots of service to manage permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Think of you have lots of service to manage…&lt;/h3&gt;
&lt;figure&gt;
	&lt;img src=&quot;https://www.codekarle.com/images/Twitter.png&quot; alt=&quot;twitter system design&quot; style=&quot;width: 1000px&quot;&gt;
	&lt;figcaption&gt; Non-offical Twitter System Architecture &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You have Kafka, Cassandra, MySQL, Redis, Elasticsearch and many services. For each service, you need:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Deploy newer version to certain machines, rollback if deployment failed&lt;/li&gt;
&lt;li&gt;Restart the service once it failed&lt;/li&gt;
&lt;li&gt;Scale up when heavy loading&lt;/li&gt;
&lt;li&gt;…&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;why-should-we-use-kubernetes-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#why-should-we-use-kubernetes-&quot; aria-label=&quot;why should we use kubernetes  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Why should we use Kubernetes ?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;self-healing: auto restart services once if failed&lt;/li&gt;
&lt;li&gt;automated rollouts and rollbacks&lt;/li&gt;
&lt;li&gt;built-in load balancing&lt;/li&gt;
&lt;li&gt;easier service discovery&lt;/li&gt;
&lt;li&gt;secret and configuration management&lt;/li&gt;
&lt;li&gt;it abstracts away the hardware infrastructure and exposes your whole cluster as a single enormous computational resource&lt;/li&gt;
&lt;li&gt;better resource allocation: you can specify the CPU &amp;#x26; memory for each service, k8s will automatically allocate them for you.&lt;/li&gt;
&lt;li&gt;storage orchestration: you don’t need to think where to store your data*&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;who-invents-kubernetes-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#who-invents-kubernetes-&quot; aria-label=&quot;who invents kubernetes  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Who invents Kubernetes ?&lt;/h3&gt;
&lt;figure&gt;
	&lt;img src=&quot;https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png&quot; alt=&quot;google logo&quot; style=&quot;width: 150px; margin-top:80px; margin-bottom: 50px&quot;&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;15 years of experience of building production workloads at Google: Borg, Omega&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
	&lt;img src=&quot;http://p3.pstatp.com/large/288f00037daa7fdc8147&quot; alt=&quot;standing on huge man&quot; style=&quot;width: 500px&quot;&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;before-we-dive-into-details&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#before-we-dive-into-details&quot; aria-label=&quot;before we dive into details permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Before we dive into details&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Let’s have a very simple practice today.&lt;/p&gt;
&lt;figure style=&quot;width: 400px&quot;&gt;
&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/5308d7adc0f380a6ff36b219dc2310de/ae953/practice.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 74.58333333333333%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAAAsSAAALEgHS3X78AAACD0lEQVQ4y5VSy7LSQBDl/7/DjTsXunAlKCUPuTyvQrhJuAmBhDwI5A0kHKcbCYhwq5zKqZnp6j5zcror+I91PB7Ls2I4eFaXmBoelIWHoig4XnmrkPZ7iKIItZ6Cj00JTcXHD8XDIc8vhI8KiZeBE2jlojBJEjzrawyMGD0twJPicJwJr3/jvlJiLMSX8/lwODCSJEUolAZhxPuZp3J+NY5j7HY73iNOKFCIpLG2Ej6tIZtbaJaPXJBRvrp02UNJeKia/t8eEomqqvA8D4vFgpGmiXg5xvvPDbz7VEddcjF4XSMMAwRBgFpfeNiQ8P3F+9fDLMtgmiYrvF5ptkNbMtGWHS76qXvYiVzycKR5wsNIeLjFk2xfPHzUlFNcqBdeEaI4QZJmpYcEEkBiaC89vG3KLentYjKhRrfWkDQLM+Hr3N5cPHyk7r7yUwPJwy/dF3z49oyvvyy0prZ4KH882PTavYeKP2NEvzl89co57MhXhFQchiF3Ok1TvDWX1ytKMmyjlBHGWRmvkKGTyQTj8RidTgfL5RKr1YpHyHVdBp0ty+K4bdtwHEfEXNji7vtruOJuGAY2m81J4X6/56RWq4V+v492u41Go4FqtcqxXq+Her2ObreLZrPJGI1GqNVqIn+AwXCI2WzGPGWXfd/HdDqFLMvQdZ0HnVRTIt0J8/kciqJA0zRWRGcSQo068/wGanN8ApVkSAkAAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/5308d7adc0f380a6ff36b219dc2310de/8ac56/practice.webp 240w,
/static/5308d7adc0f380a6ff36b219dc2310de/d3be9/practice.webp 480w,
/static/5308d7adc0f380a6ff36b219dc2310de/e46b2/practice.webp 960w,
/static/5308d7adc0f380a6ff36b219dc2310de/cc785/practice.webp 1132w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/5308d7adc0f380a6ff36b219dc2310de/8ff5a/practice.png 240w,
/static/5308d7adc0f380a6ff36b219dc2310de/e85cb/practice.png 480w,
/static/5308d7adc0f380a6ff36b219dc2310de/d9199/practice.png 960w,
/static/5308d7adc0f380a6ff36b219dc2310de/ae953/practice.png 1132w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/5308d7adc0f380a6ff36b219dc2310de/d9199/practice.png&quot; alt=&quot;practice&quot; title=&quot;practice&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;core-concepts-of-kubernetes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#core-concepts-of-kubernetes&quot; aria-label=&quot;core concepts of kubernetes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Core concepts of Kubernetes&lt;/h2&gt;
&lt;h3 id=&quot;fundaments&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#fundaments&quot; aria-label=&quot;fundaments permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Fundaments&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Container&lt;/strong&gt;: a technique to package our application, and run it in an isolated environment. You can think of that we packed our our application, and run it in a virtualized computer.&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/e76760f4f73c7a06915e6fe8b5c8f2b8/19ab6/VM_container_compare.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 60.416666666666664%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAYAAABiDJ37AAAACXBIWXMAABYlAAAWJQFJUiTwAAACmUlEQVQoz21TaW/TQBD1//8IH5AAAUJQRIGiopa2pGmTJmmOps3RNJdz2N5d2+vbcQ6kfniMl35BwtLIzzPjeW/37Wp4eh4fH8EYw3w+x2KxwHQygeu6+N8TRRGm0yl0XYdt2//UtN1uhzAMEFOT49hglgXLMtXb9z36OcR6vcZms1E4SWI1JK9zzig4kjhWJNvtFlqSJJBSwvMDBIEPPwjgUeQk0vPgSg9xHMEjvDRpiO0oYosL2I6rsGEx+uaKUFutt/CGJbj1D6QyhNsvQDY//VVydwT35itWWYaIVNjNz1TbQ0w1Vn2vanmfVX4N2fmBbLODltJAp3MEUXwG35Ow29/hlF4opaK+B/vqFdJVphRawybEuAUuOOEG+KQNkePBNaxxm0gTUphtsJo3seodIo1DpHoN2eAYK2JORpfIhmdYk8KACEz6UYzqtLc+jH5FDc/3edktQdDwnFiLaSlNg6PBJcbk8o1lo8EkJoQbpiDsgtMeR2EIq74PTqpd6cKsfoRofSPlEkb5LUT7EAmJ02IypTKY4OJ+gtGSoTbUUX6YYkIk5fsxSpTnZExEJjFm0lGyKRxwwrbNlSk5FoIp8zQvcNDVzzEwSujMimg9nKJ5f4K7PLcsoTsrwBQTpOkaVukdvMobGp6AFV/Cb5BBUQLj9Dm85hcy5Tc0GQjURodoTI/Qmv1EqXeA89t9NPVjyh2jOj7AUozhSIHu8BcexkWMzDY6/TN0BwXCN7gfFdAfndNxc6H5kURvfoWBeY3eooIGNdW6p6SsTKrzXBlCGuCugbvFJfpWDbd6EZXeCap9WsnsQuXymuszaPktCHy6AXEKwQSMpaHCMplaThREWKUrFaEfqT5mcphLU/UJbiN56svoNPwB8RhhuughG9wAAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/e76760f4f73c7a06915e6fe8b5c8f2b8/8ac56/VM_container_compare.webp 240w,
/static/e76760f4f73c7a06915e6fe8b5c8f2b8/d3be9/VM_container_compare.webp 480w,
/static/e76760f4f73c7a06915e6fe8b5c8f2b8/e46b2/VM_container_compare.webp 960w,
/static/e76760f4f73c7a06915e6fe8b5c8f2b8/f992d/VM_container_compare.webp 1440w,
/static/e76760f4f73c7a06915e6fe8b5c8f2b8/de45f/VM_container_compare.webp 1664w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/e76760f4f73c7a06915e6fe8b5c8f2b8/8ff5a/VM_container_compare.png 240w,
/static/e76760f4f73c7a06915e6fe8b5c8f2b8/e85cb/VM_container_compare.png 480w,
/static/e76760f4f73c7a06915e6fe8b5c8f2b8/d9199/VM_container_compare.png 960w,
/static/e76760f4f73c7a06915e6fe8b5c8f2b8/07a9c/VM_container_compare.png 1440w,
/static/e76760f4f73c7a06915e6fe8b5c8f2b8/19ab6/VM_container_compare.png 1664w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/e76760f4f73c7a06915e6fe8b5c8f2b8/d9199/VM_container_compare.png&quot; alt=&quot;kubernetes icon&quot; title=&quot;kubernetes icon&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;div style=&quot;display: flex; justify-content: center&quot;&gt;
  &lt;figure style=&quot;width: 300px;&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/cff8260ae0ee0683ba05c873321d8ea2/0b6f4/VM.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 96.25000000000001%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAATCAYAAACQjC21AAAACXBIWXMAABYlAAAWJQFJUiTwAAADt0lEQVQ4y31UXW8TRxT1b0RqxUP7XPHUh7ZSK1He4KmilFRVgQBxoCQEx8Sxib8N2GkSETuJP+P12t619/vD6/U6balKcnpnHCIS1K50NGfvnHtn7s7ZCeGD5+TkhI+2bUMQBKiqCkmS0O/3YRgGOp0Ofx8MBjAN81zO+yc0mUwooQeZhEMSyrKM4XAAXdegaSoVVc64RgtomgadoAyHGJxqZZkW7fXg+2OEXNehBB3BNIBu6LQ7C5NgwndnWiYC4hoVNGiOxS3L4ovMuMkXm0x8PrLckOeN4I9HbPO0AwXeyOHcsU1MJ2PehqEphCHnR1MftmVw7tgGTHPG//zjCK7rUkHHQi9+A2L0Gqzir9ALcxBXr0JK34KY/hnd6PeQEzcgxa8TvwYxdRtydg6dyFXouZs4/nvKCwaBD9YtFTQg//YF2nc/hf78ayjPvkTzl0tQo99AfPYtOhTvPPgc7fnP0J2/jPbSV9Bi30G48wn0p1fwdupeKEgt6vsp+M00gt4Ogu4WRrUNaNU89PpLjJtZjBo5eM0c50aN4jWKN1IIxBLwz1te8K+j6azlkeehKqto6i5k/wjSeIq6ZqMx0NCguGCPIVge2gTB9lFnWpqrqzb63hSSM4LseqQdcLuFLMfBw3INiw0RPyTz+ClfwmKrj8e7B1itt7FA8R8zrzkYj9QFPClXueZWtoib6VcIN7p4UGlCM02yzchFjfwkjcdoklVa5DHGa2RmgRmbeEvV+BzjAs2zuT51JlCBOvmRxevkYYvtkPXdPuySYW36EySIokw+s3HY6qDXGxC3IHZkPsfiLMbmVMWC1FfOctvt7qxl23YQWS8jvFTE3YUU7i2k8XhlC2svykgXGggvlzC/mMH9R1muSebqiG1UuObOwyTuhTOkKWJlbZfMT8Z2HBuJ3yPIVGJIvYkivfsc6fIajVHk9mLY2IkiVlzGeukpXmyv8limHCXM9CnSs9z45goMS6eCro1c9RE2u0sodd7jCYo0bnaXkarcx0rhNiKv5pCszPNY8VRTEmd6lputhmHaVHBMH1TV6PawVFpBOQ9TgeuZGCg9DtezeOyijuWqmgz2G9OhjFAoVlHaaaO0fXgOxa0Wsi/3kMqVkcy+QaZQodjhR7pNys2/PqDL4vRQooltxDMHiKf3OdbPxj36+Hk6lAQWl7PEC4ilKqT9ULOPRPaADnaLDoV86Ps+3WkKXVE6v+vOQ+ciw7RmI4HFPtJR7pD8yD5fiN24x8fH/4N3F/DfWlbrX4DaOSlDX8BwAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/cff8260ae0ee0683ba05c873321d8ea2/8ac56/VM.webp 240w,
/static/cff8260ae0ee0683ba05c873321d8ea2/d3be9/VM.webp 480w,
/static/cff8260ae0ee0683ba05c873321d8ea2/e46b2/VM.webp 960w,
/static/cff8260ae0ee0683ba05c873321d8ea2/d4a71/VM.webp 984w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/cff8260ae0ee0683ba05c873321d8ea2/8ff5a/VM.png 240w,
/static/cff8260ae0ee0683ba05c873321d8ea2/e85cb/VM.png 480w,
/static/cff8260ae0ee0683ba05c873321d8ea2/d9199/VM.png 960w,
/static/cff8260ae0ee0683ba05c873321d8ea2/0b6f4/VM.png 984w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/cff8260ae0ee0683ba05c873321d8ea2/d9199/VM.png&quot; alt=&quot;kubernetes icon&quot; title=&quot;kubernetes icon&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
  &lt;/figure&gt;
  &lt;figure style=&quot;width: 300px;&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/e2bd3114fd8f64feb6519ae12c2680ee/d6a46/Container.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 95%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAATCAYAAACQjC21AAAACXBIWXMAABYlAAAWJQFJUiTwAAADXElEQVQ4y51UXU8bRxT1T6v6WKnKr+gf6EPf+tqHfjwkaVDUNK1a4ihKWgU1kQBToAQwrO3g2Otdg9f7/Wnv+mPjXRuC4PTODCYmectKR3PmzL1n7njuuHB5eQn2zcc0TeH7PkajEcIwRBLHSJKEa0EQcM5GtnZ6eorFj3kUGLm4uCRccHE8HsO2bQwGA4SUGEURYjJ1HAcBmTI+N59OpxD5F9cFFVhFlmXyBGbkeS7tHlCSR0k+TxY8uJoLncF1HTiU4zg25VqYzWYosKP1ehFVlNBxYo447l/zJOlfa3N9kTOwXOaRZRNRIRPSdEzHHX0SWC4zzvNcGEZRiH6/x8F2XuRs50V9Xl2/dzOWeXBDdgmqoqBarUBVFbTbKiTpkHOGSkXC8XEbitJCRZLQ6ZxAlptc1zodNJsN1KpVaFqHX1JhOBzCc21EgYe4H9FNenze74V0OT6i0OMjW/M9h+YBelRNGLh8ZHExwaMLmkwmwtDxI7ydnSMeUg/2Es6jeEgQ3KeeG4zGSKdXfJwSfyd4miHN38F2fWTMcDAcobP3F5ydhzDLz6DtPYW9/QB29SWM+hb00j2YShVeaxfGxhLM9hHcxiZMijHkA1h7Rbg7v0KrljDJqW2S4Rj6829xsnQLxtOv0X32DVq3v4C7+h20jV9Q//4z6JWXsHd+x5sfPodeK8FYvw35zpcwD/6GvvwVtPu3oP97n1fNK+zuPkG0/TPs3UcwXhURbN6BIz2HdVSCt/4jrJaEoLkFd/0n2O3X8Otr8Dfvwpb34b36Df3/7qFbWcXbnDf2EAadX+2a0Gm0gghK14Dh+TAcl+tu1ONzxh363bq2A1UnPYyg2RSjW7BonTf2gC7l8VELRVXHY6XLUWxpgpO23DzB3c1dLO0cXuk6itcxImeZ8KKhYppl4untdzSULQdlwxYw7fecUHrTxJbSfq+b9g2+bzqodXXkzJA1tk5HNA0Lpr4Ik8O1PRy3T2CQ5tCmQrc+gmVa4qWwv6mV1Rr+KbUI8gJaWFlr4OGjEh78ucbxx5NtvNj4ME7GyrqM0nYd0zwTjX1Yoaf0uk1QBWpilGgsHzZQlpocBxX5xvocLO6orogjn52dUakTeocZ7TD5ABlm0/wKGcfHMSKOeZyfn+N/1yFUeQUxjSEAAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/e2bd3114fd8f64feb6519ae12c2680ee/8ac56/Container.webp 240w,
/static/e2bd3114fd8f64feb6519ae12c2680ee/d3be9/Container.webp 480w,
/static/e2bd3114fd8f64feb6519ae12c2680ee/e46b2/Container.webp 960w,
/static/e2bd3114fd8f64feb6519ae12c2680ee/6e1e4/Container.webp 1008w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/e2bd3114fd8f64feb6519ae12c2680ee/8ff5a/Container.png 240w,
/static/e2bd3114fd8f64feb6519ae12c2680ee/e85cb/Container.png 480w,
/static/e2bd3114fd8f64feb6519ae12c2680ee/d9199/Container.png 960w,
/static/e2bd3114fd8f64feb6519ae12c2680ee/d6a46/Container.png 1008w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/e2bd3114fd8f64feb6519ae12c2680ee/d9199/Container.png&quot; alt=&quot;kubernetes icon&quot; title=&quot;kubernetes icon&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
  &lt;/figure&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/barry800414/k8s-example/tree/master/server&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Practice time!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;architecture&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#architecture&quot; aria-label=&quot;architecture permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Architecture&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Node: a real computer or a virtualized machine (e.g. ec2, gce) who has computing resource (CPU, memory)&lt;/li&gt;
&lt;li&gt;Cluster: a bunch of real computers or VMs managed by Kubernetes&lt;/li&gt;
&lt;li&gt;Pod: basic working unit of kubernetes&lt;/li&gt;
&lt;li&gt;Container: a container instance by containerized technology, e.g. docker&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/bc53199c77c23bd3fae67ff7bf7894c8/d9199/k8s-simplified-architecture.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 56.25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAIAAADwazoUAAAACXBIWXMAAAsSAAALEgHS3X78AAABQ0lEQVQoz4WSy06DQBSGff+nUTeaaKxWoNAWZoYBepkB5gIMl1pqqQsXFvEacVGSLydn8+X8OfnP2rb1WfToaR41OTcDOgljfc1mJNRIYoOQAb53RAPE4RebH0jetO3xrJNpJnAOInovrHO2upXWhSQjObtkZAQZQx9mD5s3JN9/y+sswcpbEMs1b7yFNteucKA5+jXEY8Q4PC17MbuDE4dCN4IOgW4IAIWomxECoRi6nHKY2CIxXisjFeOXfFxkRpM9VOXUCeMBmSqJFSzK2fF5qjL9bTdVqX7cz1VufcqHU3Ig5GQFQOgCAm2KuuQORV87HIwdcGYujWURLPoEue/GbOBhRMllhcgGryv3L8sSuXEMhx6WIIH91Pf64MRzY45kA/t0naHFj1zWDc+fRLH9By+2alMn1U6WPURRV3XXsPYdFBFEQJBL2J4AAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/bc53199c77c23bd3fae67ff7bf7894c8/8ac56/k8s-simplified-architecture.webp 240w,
/static/bc53199c77c23bd3fae67ff7bf7894c8/d3be9/k8s-simplified-architecture.webp 480w,
/static/bc53199c77c23bd3fae67ff7bf7894c8/e46b2/k8s-simplified-architecture.webp 960w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/bc53199c77c23bd3fae67ff7bf7894c8/8ff5a/k8s-simplified-architecture.png 240w,
/static/bc53199c77c23bd3fae67ff7bf7894c8/e85cb/k8s-simplified-architecture.png 480w,
/static/bc53199c77c23bd3fae67ff7bf7894c8/d9199/k8s-simplified-architecture.png 960w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/bc53199c77c23bd3fae67ff7bf7894c8/d9199/k8s-simplified-architecture.png&quot; alt=&quot;kubernetes simplified architecture&quot; title=&quot;kubernetes simplified architecture&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;p&gt;A cluster can contain many nodes, a node can contain many pods, and a pod can contain many containers&lt;/p&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;important-resource-types&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#important-resource-types&quot; aria-label=&quot;important resource types permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Important resource types&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Pod&lt;/li&gt;
&lt;li&gt;Service (NodePort, LoadBalancer) &amp;#x26; Ingress&lt;/li&gt;
&lt;li&gt;ReplicaSet&lt;/li&gt;
&lt;li&gt;Deployment&lt;/li&gt;
&lt;li&gt;Persistent Volume&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;pod&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#pod&quot; aria-label=&quot;pod permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Pod&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Purpose: the basic working unit for scaling/deployment&lt;/li&gt;
&lt;li&gt;each container in a pod share same host and port space&lt;/li&gt;
&lt;li&gt;each pod inside cluster has its own unique IP address&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/0b5cd1b1d46c446cce76574a8d37d107/d7ab4/k8s-pod.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 47.5%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAACZElEQVQoz5WSXU/aYBiGux+wg50s4Ej2A5ZI4i9csolmByZ+JyZbNlEzp1mmUbc4UVo+2tIWRaAFPxChoGCBIghCP+69BQ92tqzJm/TqffXukyel9tjdsZAcGqWTQW9Epr3sWdTLpBkvk6IJMwOmyX1IZt5s7n99vR3a8oaV8OBZOB30ckN/lEnTY79je25KLklQSlKXHDNdipvJPG8qqmgOWJXM5DVvZMpxx6kyiYP1aDJgy6poEDZk4p8Sn/BjsZmBeBH1UegmYeuC0dNFXBSiqBWDwL2Ih7qAXJFFw+FuAs0qV4/JR5vNmzD6dR5GUyQ5B60QhNngTeAM8Sw9SXXzEgrMr15Nidj5EmeTMhst0X7QeFu9FRy20DlG647T+PThBloSnNzUBTuvEr8lOX4fdsYpnKD0LAd570e/kgzhSuXIdM4LEtoaD1KIwQe6J7ivcrVY+mgD7TjQlmyDFDq+PfQNIDOc0LiToGeDvU6Zt3LFqNUqM5ZZY61OPWZdlzirXaYtNAWQiTUuFfjWqUTwWI1YVlMgPmu1bkJWX4v2nwrJhFUW1ULA7rXiuFR5nJ1uo67SaDckXJIdnSe28HDHol7hdC51+L14vo/KVQCPZOc54ueUn7jNHdjODqUM/YG60FJIFSUtc5vQh+dET6mS/hc3CLeVm5Mr4TzyJVs5vSd/gy6Xj3WF5IQdv0ZcxHPcW2pxbfHV+My4Z3V3xeXf+uya88+P+OYmPGu7qwOeXZ4bmZyfdPKXM5+mXixvL7veTb/3LK0vudd2/K6F1QW3b9bnWdnxu6c/Tj2n/vN69q/8D3ZWRq71gHvLAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/0b5cd1b1d46c446cce76574a8d37d107/8ac56/k8s-pod.webp 240w,
/static/0b5cd1b1d46c446cce76574a8d37d107/d3be9/k8s-pod.webp 480w,
/static/0b5cd1b1d46c446cce76574a8d37d107/e46b2/k8s-pod.webp 960w,
/static/0b5cd1b1d46c446cce76574a8d37d107/dd5f8/k8s-pod.webp 1014w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/0b5cd1b1d46c446cce76574a8d37d107/8ff5a/k8s-pod.png 240w,
/static/0b5cd1b1d46c446cce76574a8d37d107/e85cb/k8s-pod.png 480w,
/static/0b5cd1b1d46c446cce76574a8d37d107/d9199/k8s-pod.png 960w,
/static/0b5cd1b1d46c446cce76574a8d37d107/d7ab4/k8s-pod.png 1014w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/0b5cd1b1d46c446cce76574a8d37d107/d9199/k8s-pod.png&quot; alt=&quot;kubernetes pod&quot; title=&quot;kubernetes pod&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
  &lt;figcaption&gt; every pod has a unique IP iddress inside cluster (Cluster IP) &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;we can specify multiple containers you would like to use in a single pod&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;when-we-use-multiple-containers-in-a-pod-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#when-we-use-multiple-containers-in-a-pod-&quot; aria-label=&quot;when we use multiple containers in a pod  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;When we use multiple containers in a pod ?&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Sidecar pattern: log collecting&lt;/p&gt;
&lt;figure style=&quot;max-width: 500px;&quot;&gt;
&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/d0339e51943c457037ca1b2db39ec309/d3b46/sidecar-pattern.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 74.16666666666667%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAABYlAAAWJQFJUiTwAAACT0lEQVQ4y52USW/aQBSA+d+9Veq1h956qdRDEwlVTdIkAoLCnrAkaRa2pJAmQHDABhuDMV6wv9qUpWkjGvVJn2Q9j79582Y8Add18WM6naLrOpZlYZrmDD/894sxL4nAYvBkMkEQBDKZDOVyGUVRlrI/WUy0Ruh6lZmo6oBWq4kodhmPtVke93eclwifJrSxgTPPuc+wTjYXOnRbF0gPZ5jDG3rCOWO5gqFeMxlU0RWfivd8zUi6wjSG6ysEhx/FHRpXQVwljVjfx+zGsKUElhTHHaRwPFAzGN0DjLH0jyUzRSwmqO1tUQ/tIKViyJk44/wRw9MUE8mTaTmPLHY/ian31wsdbKTzJFYyT2s3TO3zNrdfdjHTBYx8DvFHiGG3gNK5QHmIYem9J8fJdaa/mE8QcFwb5TaNceNRO/LkUUaVJFo1hV5PIdRClEuXFCt3NGpZrIk4Fzp/VedLvU2ZItXiNPLbSMUDpMso2ndPeONRTyA3ozzen9K6L9FrprwKpaXA0TUG0U3UwyCOaax62PmWoP01QjW4RXs/wt32Pnoyy2S25PCsfz5WL77soR/ixzcMIp/oB9/R23y76mG/lMAuHCOnD+nEwojxCHo2jXaSpN8IM+7E0Dpx5EYIWWoyGKhohon4/hXaRZrh0R7ih9dzoWMzEE4Yto+9Dwvoc0ZCjtFjDkM+wZRPsZQztO4xhi4vKzTuq6gHG6jRDWzhbvXr2baNZVvPsrgoFjjOajMaDwLX1Yq3aSXane5sowL8RyyOiP//+5fKDO+m8rM/ATsRbq4k4hGBAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/d0339e51943c457037ca1b2db39ec309/8ac56/sidecar-pattern.webp 240w,
/static/d0339e51943c457037ca1b2db39ec309/d3be9/sidecar-pattern.webp 480w,
/static/d0339e51943c457037ca1b2db39ec309/e46b2/sidecar-pattern.webp 960w,
/static/d0339e51943c457037ca1b2db39ec309/f992d/sidecar-pattern.webp 1440w,
/static/d0339e51943c457037ca1b2db39ec309/3802d/sidecar-pattern.webp 1690w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/d0339e51943c457037ca1b2db39ec309/8ff5a/sidecar-pattern.png 240w,
/static/d0339e51943c457037ca1b2db39ec309/e85cb/sidecar-pattern.png 480w,
/static/d0339e51943c457037ca1b2db39ec309/d9199/sidecar-pattern.png 960w,
/static/d0339e51943c457037ca1b2db39ec309/07a9c/sidecar-pattern.png 1440w,
/static/d0339e51943c457037ca1b2db39ec309/d3b46/sidecar-pattern.png 1690w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/d0339e51943c457037ca1b2db39ec309/d9199/sidecar-pattern.png&quot; alt=&quot;when to separate pod&quot; title=&quot;when to separate pod&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ambassador/Adapter pattern: proxy / adaptor&lt;/p&gt;
&lt;figure style=&quot;max-width: 500px;&quot;&gt;
&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/a423145b2b3c4ce35c6c5748bce968c4/0d390/adapter-pattern.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 80.41666666666667%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAABYlAAAWJQFJUiTwAAAB+ElEQVQ4y6WTDW+aUBSG+f//RBNtmkbd5rdoq0zobG3rtCTWMQENfgDChQu8u9Lhx2qi20je3HtyLw/nvJzDRVGE7bNdfd9HElNKEYbh7uzShzsEqKqKfr+PXq+HyWQCx3H+D6hpKp6e+pAkCYqifABeAuaSTXI1CEIQ4n24eGmWcYZhQBGFFAH1YdsmlguDgX34Hon1N15yIXvx9TGH8UsO/lKAqbdgKHV4yw7IogNTq8OxZr+BYQw9peSDDOhBebnBuJcBnfMwf5QxG31CZLRY3IQzLYLY+tnMEijHmgVKt4BBNoPnqwyMehWrRh3WbROb1i20Zh7E0UEDwCMkbq2tPM+D67rx/tASLog8zMQSfF5AJIh4zVxjkM4iaHeB9j1mjc+wzSlkeQxRFDEcDjEajeL2GgwGcSzL8q50LggZ8LEI62sdtsRjzdaVUIMlNmCLTehCHu5GO/LwVLm7kiklMH9WsWEiegOrtzLU74XYP6LxsJS9h3/CTsWxh2/tHPqpNB7SKcwrZayZhybfgNu6g8ZvM9TP/uV9yczDuVQB7iQYpRrkqxs8p7KY5r8AQg9Gs3hQ8gV9GIQE+kMB606JeVh9l1hlHlZgd2vMw2u4trrL8CyQUg8rXcJmcQ/LONZm+Y2dCSzDxT/McvQ+z0eK9jN+6Sz/AvZeyJ3DEgnVAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/a423145b2b3c4ce35c6c5748bce968c4/8ac56/adapter-pattern.webp 240w,
/static/a423145b2b3c4ce35c6c5748bce968c4/d3be9/adapter-pattern.webp 480w,
/static/a423145b2b3c4ce35c6c5748bce968c4/e46b2/adapter-pattern.webp 960w,
/static/a423145b2b3c4ce35c6c5748bce968c4/f992d/adapter-pattern.webp 1440w,
/static/a423145b2b3c4ce35c6c5748bce968c4/098de/adapter-pattern.webp 1472w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/a423145b2b3c4ce35c6c5748bce968c4/8ff5a/adapter-pattern.png 240w,
/static/a423145b2b3c4ce35c6c5748bce968c4/e85cb/adapter-pattern.png 480w,
/static/a423145b2b3c4ce35c6c5748bce968c4/d9199/adapter-pattern.png 960w,
/static/a423145b2b3c4ce35c6c5748bce968c4/07a9c/adapter-pattern.png 1440w,
/static/a423145b2b3c4ce35c6c5748bce968c4/0d390/adapter-pattern.png 1472w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/a423145b2b3c4ce35c6c5748bce968c4/d9199/adapter-pattern.png&quot; alt=&quot;when to separate pod&quot; title=&quot;when to separate pod&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h4 id=&quot;when-we-should-not-use-multiple-containers-in-a-pod-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#when-we-should-not-use-multiple-containers-in-a-pod-&quot; aria-label=&quot;when we should not use multiple containers in a pod  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;When we should NOT use multiple containers in a pod ?&lt;/h4&gt;
&lt;p&gt;when we want to scale up different applications inside a pod in different scale, we should separate it as different pods&lt;/p&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/f96601ecdf2e1623fb2066b002b3f6ec/56caf/when-to-separate-pod.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 62.5%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAYAAACpUE5eAAAACXBIWXMAABYlAAAWJQFJUiTwAAACuklEQVQ4y32TXW/TdhTG802ZxC3adsUuuOCGD4CQJg2BgAHLWEe3aVtfpLIW0lKt9CVxY2zHjh0n8UsSx7GTJnGTOv3tH6c0N4wjnZu/9Tw+5/zOyfGZuLy85P9iNpsRDFoE4x7dJKLT95leTK51ucGwR3wWXGUoBKn4AoNRTJQMiM+HRKMeF1ei0WSEJG+ibD+ktHEfRfqLcNhdGu6ZKxSsPLvWKwpGnngYkjKjrL+j8m+eyv4zykLU6ruZ6GwyRJc3sF/fQfnxFvbJKqGo9Nrw2FinpK1TVP7mWF8nCl0myQhD28H65TbSD19RP/gJL2hkosE4otHWCYMebtOl03Pp9r2loXmwipH/Dvnp19R2RYVxl4los6Yd0PVdPLdOq6bQciuLCscxhlPEdqpoVZl6W6UTO0tD/XSd2uo9zJW7VA9/FzMbME3PMZsSrlVHVzScRoVWXM9E59Mx23KetcNHrH14xJb0jCQRMxZm0/SCnKFtoDy8hfTgJpb0G9F4QJpOkIwC6tYTtD/ucyqt4cfNK8opzcDA8D9S9VWqLYV9T8aIF23nGuYJYa1OULNxqxKRoH0hoBinW+hPv6X4/Q3sfx7ji1WZx1hQlvUC88604p+olbec+ApJOl0YllQBxd6jaO0KOJtE7QYTUaVtHBG2Pdpihm3HwG8q15Qr5TXU599wNP/Z8a/ZW1b95Yzce2uFvVqe9/bPFEwBpd/OoNiiFcd10avCLHTwu+bCMOljNUuc+VX6jobnKWLR/SWU+e5tSo+zfFt5Qe+sw/xQdrXXbBTF4I/E4MtP8HrWYm3Ekjc6BnbdQVF1OpFLELtLQyfUsVplTL9Mo6sxmSbZpXg9k1q7jCXe68FHRuJqFpRH7MiveFN6meWOIN4dfNpD0fJnb5kv3XKK2jjkg/KGQ3Ub2d4nEaA+Vfgfc3qydNpMZuUAAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/f96601ecdf2e1623fb2066b002b3f6ec/8ac56/when-to-separate-pod.webp 240w,
/static/f96601ecdf2e1623fb2066b002b3f6ec/d3be9/when-to-separate-pod.webp 480w,
/static/f96601ecdf2e1623fb2066b002b3f6ec/e46b2/when-to-separate-pod.webp 960w,
/static/f96601ecdf2e1623fb2066b002b3f6ec/f992d/when-to-separate-pod.webp 1440w,
/static/f96601ecdf2e1623fb2066b002b3f6ec/dc596/when-to-separate-pod.webp 1712w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/f96601ecdf2e1623fb2066b002b3f6ec/8ff5a/when-to-separate-pod.png 240w,
/static/f96601ecdf2e1623fb2066b002b3f6ec/e85cb/when-to-separate-pod.png 480w,
/static/f96601ecdf2e1623fb2066b002b3f6ec/d9199/when-to-separate-pod.png 960w,
/static/f96601ecdf2e1623fb2066b002b3f6ec/07a9c/when-to-separate-pod.png 1440w,
/static/f96601ecdf2e1623fb2066b002b3f6ec/56caf/when-to-separate-pod.png 1712w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/f96601ecdf2e1623fb2066b002b3f6ec/d9199/when-to-separate-pod.png&quot; alt=&quot;when to separate pod&quot; title=&quot;when to separate pod&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;service&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#service&quot; aria-label=&quot;service permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Service&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Purpose: make cluster’s internal and external networking more convenient and feasible&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use cases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Pod-to-Pod communication&lt;/li&gt;
&lt;li&gt;Pod to connect external service&lt;/li&gt;
&lt;li&gt;External client to connect internal pod&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;pod-to-pod-communication&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#pod-to-pod-communication&quot; aria-label=&quot;pod to pod communication permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Pod-to-Pod communication&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Pod can fail / be deleted / be created at any time, we are not possible to setup our application by IP address mannually&lt;/li&gt;
&lt;li&gt;By using service, we can refer to one or more pods by a selector&lt;/li&gt;
&lt;li&gt;When a service can to muliple pods, the service can load balancing the requests&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/c0ad4b3326ad9017ccf041fe2537b84a/89305/service-usage-example.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 62.5%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAYAAACpUE5eAAAACXBIWXMAABYlAAAWJQFJUiTwAAAB10lEQVQ4y5VSa2/TUAzt//8RTBqvAV9hQqhsdC2sq0jXUqFMYx+gabIuj9I2yc3z5mC7TRVWVQhLVm78OPax3cIjybIMeZ7vaZqmorWf367rYj6fw3Ec+L6PqqrQursfwbQGMGdXsP075FkhDq21KL852fNcSrQFQKlYijNw1ihYliVal+Y7tI0TfLw+gTkdIFEpBWRb3QQrpRCGawS+hygKkSbJY2ICJoBNIzWDoih2AU36G9AQKo7FLpqm4mPhPAFkSrUyorda47UxwdF5D8f9IaaLJVYqwYvBCEdnXbIZcJZr/I4Vnl4aFNfFy69jTIMF5esGoHRYYRVFGFsOrm5+YPhrhkUUI05SjCwbfbIZPy0CixGRjf39m1v5+tRIRTNvYQvEwkvIiQp3WhKdqsiFVsIzKwvkiWJuMkOZoy6hadZCmajvZvgXIDk0/fNMEj4VKsBv/rpeAEVAmoC4yMzebJ01CALJ3wOsl9KUMFQ4605w2h6i3ZnAsv3t4vRuu/mhDmtAucWt/cFb4vmbDp48+4DjV+cwby008/bO5hBgvSyWOE5w/xAgou3WJ7a7jubZ/AuQZc2UL8Z4+76H9qdrmuVqL+a/AXt9E53P33Dx5Ts8/zDgHzPY5i//PHPBAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/c0ad4b3326ad9017ccf041fe2537b84a/8ac56/service-usage-example.webp 240w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/d3be9/service-usage-example.webp 480w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/e46b2/service-usage-example.webp 960w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/f992d/service-usage-example.webp 1440w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/882b9/service-usage-example.webp 1920w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/5a99d/service-usage-example.webp 2153w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/c0ad4b3326ad9017ccf041fe2537b84a/8ff5a/service-usage-example.png 240w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/e85cb/service-usage-example.png 480w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/d9199/service-usage-example.png 960w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/07a9c/service-usage-example.png 1440w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/29114/service-usage-example.png 1920w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/89305/service-usage-example.png 2153w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/c0ad4b3326ad9017ccf041fe2537b84a/d9199/service-usage-example.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;h4 id=&quot;pod-to-connect-external-service&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#pod-to-connect-external-service&quot; aria-label=&quot;pod to connect external service permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Pod to connect external service&lt;/h4&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/c835c65367ab3eb16fcef772e8d67523/b7756/service-connect-to-external-server.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 38.75%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAYAAAD5nd/tAAAACXBIWXMAABYlAAAWJQFJUiTwAAABoklEQVQoz3WRW2/TQBCF8//f4KE8IHhAXEpA4SIqVAWFlrahaqO0pBg7ie2sk5g4iR3fQKJ28MfYoaAgMdLRzszZPXPZmpp5KM/DnS/wlkuqWFD60/m84hyJoziitKIo/ovSao97fe6d92gORrRth/udKx5c6pxaireGVcVPPhnYX2f/CP78C4o/XE2fTOkOTQzlYE+nXJgm3cGAkfi6UuILJ3eWQcCWFb9xE950mEYhSbSqEPgy5sRl4kwIVwGx5NI4JA6FC3zW+ZpQcj2rzcfePudai7MvTWxXI8vyjWAglWN5ZNpj9ppdHtbf8+hZi9f7HTTDFiEpIt0uFnPSJCVJQ1qXT2kc3eHVyV0axzto4zbZj0xEr6mtpJNEBAdDxYu9M+ovT9htHNF4c4qmW/j+Atd18byZ3EtIv8WV4O67Wzw/2KF+cJsrdUx2nZPnObVQxikRySjKGaP3LfrDUdVV2XkkKymLlpNkWUacRBjOBR3tkM7nD9Wp3L6IrTcj+7K3cj++76PUCHM4wLbMyi9zGyxFONpafpp8x19sf1TJ/QLsLEysK7f/1gAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/c835c65367ab3eb16fcef772e8d67523/8ac56/service-connect-to-external-server.webp 240w,
/static/c835c65367ab3eb16fcef772e8d67523/d3be9/service-connect-to-external-server.webp 480w,
/static/c835c65367ab3eb16fcef772e8d67523/e46b2/service-connect-to-external-server.webp 960w,
/static/c835c65367ab3eb16fcef772e8d67523/f992d/service-connect-to-external-server.webp 1440w,
/static/c835c65367ab3eb16fcef772e8d67523/882b9/service-connect-to-external-server.webp 1920w,
/static/c835c65367ab3eb16fcef772e8d67523/652ff/service-connect-to-external-server.webp 2294w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/c835c65367ab3eb16fcef772e8d67523/8ff5a/service-connect-to-external-server.png 240w,
/static/c835c65367ab3eb16fcef772e8d67523/e85cb/service-connect-to-external-server.png 480w,
/static/c835c65367ab3eb16fcef772e8d67523/d9199/service-connect-to-external-server.png 960w,
/static/c835c65367ab3eb16fcef772e8d67523/07a9c/service-connect-to-external-server.png 1440w,
/static/c835c65367ab3eb16fcef772e8d67523/29114/service-connect-to-external-server.png 1920w,
/static/c835c65367ab3eb16fcef772e8d67523/b7756/service-connect-to-external-server.png 2294w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/c835c65367ab3eb16fcef772e8d67523/d9199/service-connect-to-external-server.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;h4 id=&quot;external-client-to-connect-internal-pod&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#external-client-to-connect-internal-pod&quot; aria-label=&quot;external client to connect internal pod permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;External client to connect internal pod&lt;/h4&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/c0ad4b3326ad9017ccf041fe2537b84a/89305/service-usage-example.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 62.5%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAYAAACpUE5eAAAACXBIWXMAABYlAAAWJQFJUiTwAAAB10lEQVQ4y5VSa2/TUAzt//8RTBqvAV9hQqhsdC2sq0jXUqFMYx+gabIuj9I2yc3z5mC7TRVWVQhLVm78OPax3cIjybIMeZ7vaZqmorWf367rYj6fw3Ec+L6PqqrQursfwbQGMGdXsP075FkhDq21KL852fNcSrQFQKlYijNw1ihYliVal+Y7tI0TfLw+gTkdIFEpBWRb3QQrpRCGawS+hygKkSbJY2ICJoBNIzWDoih2AU36G9AQKo7FLpqm4mPhPAFkSrUyorda47UxwdF5D8f9IaaLJVYqwYvBCEdnXbIZcJZr/I4Vnl4aFNfFy69jTIMF5esGoHRYYRVFGFsOrm5+YPhrhkUUI05SjCwbfbIZPy0CixGRjf39m1v5+tRIRTNvYQvEwkvIiQp3WhKdqsiFVsIzKwvkiWJuMkOZoy6hadZCmajvZvgXIDk0/fNMEj4VKsBv/rpeAEVAmoC4yMzebJ01CALJ3wOsl9KUMFQ4605w2h6i3ZnAsv3t4vRuu/mhDmtAucWt/cFb4vmbDp48+4DjV+cwby008/bO5hBgvSyWOE5w/xAgou3WJ7a7jubZ/AuQZc2UL8Z4+76H9qdrmuVqL+a/AXt9E53P33Dx5Ts8/zDgHzPY5i//PHPBAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/c0ad4b3326ad9017ccf041fe2537b84a/8ac56/service-usage-example.webp 240w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/d3be9/service-usage-example.webp 480w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/e46b2/service-usage-example.webp 960w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/f992d/service-usage-example.webp 1440w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/882b9/service-usage-example.webp 1920w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/5a99d/service-usage-example.webp 2153w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/c0ad4b3326ad9017ccf041fe2537b84a/8ff5a/service-usage-example.png 240w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/e85cb/service-usage-example.png 480w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/d9199/service-usage-example.png 960w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/07a9c/service-usage-example.png 1440w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/29114/service-usage-example.png 1920w,
/static/c0ad4b3326ad9017ccf041fe2537b84a/89305/service-usage-example.png 2153w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/c0ad4b3326ad9017ccf041fe2537b84a/d9199/service-usage-example.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/41ae15afcfbfac0830741fde01637f3d/5e1f2/node-port-illustration.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 71.25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAABYlAAAWJQFJUiTwAAACNklEQVQ4y3VT247SUBTl//9Bn3xRR42J+GLigzEx8mDkNqXQ0lIKpfeWlgK9sDzrlI7M6JxkJ3u366y99uX0LpcLzuczqrLC6XTE9+lH9H++RH/wAsp6gLps2v9VhdvDe7fWnV7TNDgcDijLUtgZTmTC8lSsvBmizEXTXFDV1QOGxLzzlJDG7z0CsiyT7MfjEXEYI4lTJFGKKIzgui7yPEdRFJKMF5Mkged58H2/NeEHQSBxvbquEcexDGzbxtq2sNs58AOCfOnneSaJqDKKIliWBcfZSttuNyLpDmEYIE1T9AgkGUnbjJ7I7oo4EpdD6VMRyw38NgFVk4D/O3ySxC0h6ya4LbmQQIJccZEKq6pELXpYFAcZN00tv2XZ/kre4ijggZBT5KFKZiNgy5LEBctayQTsc7bfSyyTUpFUKLCBiEPh78X/R4RhGMI0lhgrCt6PVbwdz/FFWSDP2h5yMMQ6joPVUse36Qzvpgu8Edh7e4tC4B4RysGsLWiGgU+KjruJiq+qhoMcCiSOxFTl2Gv80g18mMxxN1Iwe46w7UUiViaQPsvllHlOp5O0nZiqs7ExUBf4PNPRVzTMN88Q/m1wIvvEOL/uKdXVdQNX9NnQFvix0PH6XserkYqJUHjM/0PIhpPEFiVRHX1OtCMknon2+1Tu4NI04QjFHMw/QyEhl9Q0DQyHv6FrmlifnVzo2zfM6ZJMUe4xGg3lJoRPCbvsfDm0LmbPuMje9XndYujTuvfNp/sHM/gnOAUAcO0AAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/41ae15afcfbfac0830741fde01637f3d/8ac56/node-port-illustration.webp 240w,
/static/41ae15afcfbfac0830741fde01637f3d/d3be9/node-port-illustration.webp 480w,
/static/41ae15afcfbfac0830741fde01637f3d/e46b2/node-port-illustration.webp 960w,
/static/41ae15afcfbfac0830741fde01637f3d/f992d/node-port-illustration.webp 1440w,
/static/41ae15afcfbfac0830741fde01637f3d/882b9/node-port-illustration.webp 1920w,
/static/41ae15afcfbfac0830741fde01637f3d/1c229/node-port-illustration.webp 2134w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/41ae15afcfbfac0830741fde01637f3d/8ff5a/node-port-illustration.png 240w,
/static/41ae15afcfbfac0830741fde01637f3d/e85cb/node-port-illustration.png 480w,
/static/41ae15afcfbfac0830741fde01637f3d/d9199/node-port-illustration.png 960w,
/static/41ae15afcfbfac0830741fde01637f3d/07a9c/node-port-illustration.png 1440w,
/static/41ae15afcfbfac0830741fde01637f3d/29114/node-port-illustration.png 1920w,
/static/41ae15afcfbfac0830741fde01637f3d/5e1f2/node-port-illustration.png 2134w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/41ae15afcfbfac0830741fde01637f3d/d9199/node-port-illustration.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
	&lt;figcaption&gt; NodePort &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/3bd36cbd6975d13e09b3c0d5c0aa1b59/e996b/load-balancer-illustration.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 84.16666666666667%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAARCAYAAADdRIy+AAAACXBIWXMAAAsSAAALEgHS3X78AAACp0lEQVQ4y41UaW/TQBD1//8JqEJVJb71G0JCKqWAgNIWlTZNmsO57PiK7yuxkyZ9zNtgaCtAXWm0u97ZN29m3lq7v78HjWNZl+jZF+ha5+iYp4hyT31/6NPM/xqacsIvwFWOs8FrfLw+xKf2IfzMeATyHFCNh5vNVpy2iJMCphVjPHFhmCHmfiZnG2y320dg/zPt7u4Odb2SzQY/bsZ4+eod9g7eiL3F0YcrBbher5U9Z2hVVQlgzdAIwhh9fYrR2MRA5sl0hjzPsVqtUJalmhlguVwiyzJ1RmvWxNEWiwXSNEVRlLCtGRzbQuB7CIK5Mlv2RVEoZ868OJ1OMZuZME0DpmEoH9d1kCTJLmUC+r4Pz3MRhoGs5xI1RRxHak8gDjLxXBeO4yCKQgGIlU8Q+IKRqHMFyDQ4GJ2OjOYSXNZFwVQqdcZAq1UtKS9kn2E+9xS453nS0PgPII0dImUVWaKmUYBc5iJLFMPlYgeyljpyZgb0KwSoFJ8sjZE+ZEhzJR3XsdGfTHCqj/BVH6M1GiOVS1VVg/WmH5mGUt++OcP5xMTZxMBY7paSxW+GHH4QQO938bnVxv51Hy8ub3GsT1BLikr40l3Kx7JtDHtdHLc62L/qYe+ygwtRRFU8AWQaZONJIzqWjbbYSC4zXZaEsqHII6aapxhYFk76I7wX688slE8B2W12jd0rpCasH+u0WJTqnOwoH0tkovducXR1g4PWQLH8blh/Z0gwAqdkK1JgpxvA5ukxaCxZjF0P3yTVLyMDQ+dJDZsuU3fDoY5Op60ES42xGc1QKUc77Y30Abo3LfiOhUQCk8gjhtQXWTb6CqVJKn2RzcP3zGfI79SfJXWcy6OgD79rlAHr0lxYrxsZbRUbslNycvmKQuXTkGj+RJx3P5kaPwGe3AyyUzgqdAAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/3bd36cbd6975d13e09b3c0d5c0aa1b59/8ac56/load-balancer-illustration.webp 240w,
/static/3bd36cbd6975d13e09b3c0d5c0aa1b59/d3be9/load-balancer-illustration.webp 480w,
/static/3bd36cbd6975d13e09b3c0d5c0aa1b59/e46b2/load-balancer-illustration.webp 960w,
/static/3bd36cbd6975d13e09b3c0d5c0aa1b59/c139f/load-balancer-illustration.webp 1050w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/3bd36cbd6975d13e09b3c0d5c0aa1b59/8ff5a/load-balancer-illustration.png 240w,
/static/3bd36cbd6975d13e09b3c0d5c0aa1b59/e85cb/load-balancer-illustration.png 480w,
/static/3bd36cbd6975d13e09b3c0d5c0aa1b59/d9199/load-balancer-illustration.png 960w,
/static/3bd36cbd6975d13e09b3c0d5c0aa1b59/e996b/load-balancer-illustration.png 1050w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/3bd36cbd6975d13e09b3c0d5c0aa1b59/d9199/load-balancer-illustration.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
	&lt;figcaption&gt; LoadBalancer &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/6d23bce8375bdca5ac4cd5e37fc04afa/32ac3/ingress-illustration.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 32.916666666666664%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAYAAAAIy204AAAACXBIWXMAAAsSAAALEgHS3X78AAABZklEQVQoz22RW2+CQBCF/f+/oL/ANK3W3hIftG3SPtRY6wUUq4kXUKTCsiCCIkVOZ9dofHCTk53ZZL+cM5PLsgznEidNU/i+D8/zTvdms0EUhdhut/DWa4yXDkzXw8RmMLkn+2gbI4cLJ45jOI4DxthJnHNYlgXPZVCnOvJfbZQVDTcNBWW1j3y9BYO5yP2lOwil6R5JklK9RxhGcGwbNukIDoJA9ity2zdmKLVUvPQGeGz38KoNcNdUyDFH7qF2hY/+LbThCNfFd5SeP8mJI+O5rithYRhK2fYSK18A57hvdSXoqdPDmzZEqakegBafggULrOmDuWCwlpzcrAkYyZgCKmoBtH4t+NyFps9Q+FZQ7f4QWEWVnBYaHcwZvzzDJEnkMsTMhERcAXQcGwG993QDRXJYEUCKXBFAcjgXM8yyPQ7KsD/bttj0breTOtY+xY1EEvpYG+tQDBP1iQFlZqI2msKlZP+zEAfhYOYTFAAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/6d23bce8375bdca5ac4cd5e37fc04afa/8ac56/ingress-illustration.webp 240w,
/static/6d23bce8375bdca5ac4cd5e37fc04afa/d3be9/ingress-illustration.webp 480w,
/static/6d23bce8375bdca5ac4cd5e37fc04afa/e46b2/ingress-illustration.webp 960w,
/static/6d23bce8375bdca5ac4cd5e37fc04afa/c7643/ingress-illustration.webp 1249w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/6d23bce8375bdca5ac4cd5e37fc04afa/8ff5a/ingress-illustration.png 240w,
/static/6d23bce8375bdca5ac4cd5e37fc04afa/e85cb/ingress-illustration.png 480w,
/static/6d23bce8375bdca5ac4cd5e37fc04afa/d9199/ingress-illustration.png 960w,
/static/6d23bce8375bdca5ac4cd5e37fc04afa/32ac3/ingress-illustration.png 1249w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/6d23bce8375bdca5ac4cd5e37fc04afa/d9199/ingress-illustration.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
	&lt;figcaption&gt; Ingress &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;replicaset&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#replicaset&quot; aria-label=&quot;replicaset permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;ReplicaSet&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Purpose: to maintain a stable number of replica Pods running&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use case:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;High Availability (HA): to ensure service always being available&lt;/li&gt;
&lt;li&gt;Load Balance&lt;/li&gt;
&lt;li&gt;For example: Login service, API service, …&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;figure style=&quot;max-width: 500px&quot;&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/400e1ae8ff7ae286875cad7c3eb199bc/587b0/replica-set.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 66.25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAYAAACpUE5eAAAACXBIWXMAAAsSAAALEgHS3X78AAAB9klEQVQ4y31TWW7bQAz1/Y/QAm0+ijZtruB8tUhiI40lu4ptBQkcL1osydoXa3slxxlDRowQIIbD4bzhIzk9kNR1jaZp0Lbt0e4K+5IkQZomyLL0aLOfhe9J6bHTsiwYxgbL5SvZJjzPRVVV4sJ+v4fv+yjLPfI8E4BFkYt9EPjvQHt8kcHm8xnu7m6PoHEcE0BO4B4B7kSw42zx9KQLIJYoCsWDEpC1x/Q4IIoiohKTHQhKXcmyjB6IKLMCTduILHnPfgFG2khAfCBNTbTLUtArKNuM6uY5DgoC4n1dHc7bN9qCskxVKktCwYYf4NmwsNg6iAkgyXKsPR8vpoWl4yLNC4RJipXrUZxJZzukxOAkw+YNcLQ2caHO8fnPEF9pvV+ZuF9uyJ7h0+8BLsY6xhsLN4s1vihT8g3xTXvG4GV5HnBq2riazPFjqOBSnUIzt9Ao218THZfk+zmeQbddKCuDfHN8H4xw9U/HZG2cAkrKh7VFGIaiEVyrimrF6u12wsfTwVqSL6C4RtTxTFO6Q8ozxt3nEUrTVKhLTZF7XvlcfoR3XT7N8ADouI6YvbGq4vFRg6ZpYmYVZYTXxQLbrX06h+fGRQIyHR5m27agEsD1df+g/T4eHv7SmS3Ouol8CMhUdlQz/in8/TgbyzSFSj//pG6G/wH4uOEoJgVH5wAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/400e1ae8ff7ae286875cad7c3eb199bc/8ac56/replica-set.webp 240w,
/static/400e1ae8ff7ae286875cad7c3eb199bc/d3be9/replica-set.webp 480w,
/static/400e1ae8ff7ae286875cad7c3eb199bc/e46b2/replica-set.webp 960w,
/static/400e1ae8ff7ae286875cad7c3eb199bc/dbca2/replica-set.webp 970w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/400e1ae8ff7ae286875cad7c3eb199bc/8ff5a/replica-set.png 240w,
/static/400e1ae8ff7ae286875cad7c3eb199bc/e85cb/replica-set.png 480w,
/static/400e1ae8ff7ae286875cad7c3eb199bc/d9199/replica-set.png 960w,
/static/400e1ae8ff7ae286875cad7c3eb199bc/587b0/replica-set.png 970w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/400e1ae8ff7ae286875cad7c3eb199bc/d9199/replica-set.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
	&lt;figcaption&gt; ReplicaSet &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/barry800414/k8s-example/tree/master/k8s/replicaSet&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Demo time !&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;deployment&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#deployment&quot; aria-label=&quot;deployment permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Deployment&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Purpose: to deploy our application more gracefully&lt;/li&gt;
&lt;li&gt;Use case: almost every application&lt;/li&gt;
&lt;li&gt;Before introducting Deployment, let’s see what kind of strategies we can use for deploying new version of application:&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/32d381edc7b38cc0569bbfd3c340f006/b6c94/deployment-all-delete-create.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 53.75%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAAAsSAAALEgHS3X78AAACGUlEQVQoz2WS227aQBCGef8nqHrT20qphJpEbRUlVdqEJuHo4NolYK+B4BM+4bMNmL/DEieotTXe8TezM7sz09gB2Gy3WG/W2Gw22JJey3r9xqqq4nrNjvV63e12aOw/RZ4hCHwkcYSyKLgDZ76HJIlRFDnfkBPziWVZijzLaM048zwPaZpyn8aWMidk8IIAYRQho4BFWXLm+j7COD6wokScJHBpc0wsTTOeLM0SeL5LtohuWaIhGxY+tgWcD/+gORDxVRzh11jFp76IU0Hi7Jv0hNZgiNPrFr7c3OHsRwtXdz3cS5e4fjzBT7GJ78IJ2qMLNKIsB7NsMNOCZtpYuB6cMIRmL8EomUY23fPhkEwXOtjsGbOFAZ245SygL6eYmyqeLQZ3ZaJBlcSUqWCqwsV3HZR5Do10TZ0QmyCgaxZ7tvdjCpfVvkSriOyMi6qoyKgMFLDCkGn4cHOPM+E3XAro2A4ktYfPrfe4Fc/hLB0s6cTi5AHN23d4kC84M+jEj+MWZx35CmmS7rtc4dk00X8aYzSbI4pC3gDTXkBW+nTNMaLwwHRrDonY3FAREouoibo1gzTpUQyGkprJx+b4qf8zqq3n+DQexStPE5oGN3hj9ObkF65iKkFII5TTlV+cqxepAyrKBN1uh8Yhfk0myzIEYQDDNGDbNp8/URTJr4tOp0O1ZYeAxyf7V6//j5llWWi325Al6T/fv2h/N1OA+XsZAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/32d381edc7b38cc0569bbfd3c340f006/8ac56/deployment-all-delete-create.webp 240w,
/static/32d381edc7b38cc0569bbfd3c340f006/d3be9/deployment-all-delete-create.webp 480w,
/static/32d381edc7b38cc0569bbfd3c340f006/e46b2/deployment-all-delete-create.webp 960w,
/static/32d381edc7b38cc0569bbfd3c340f006/58a7f/deployment-all-delete-create.webp 1429w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/32d381edc7b38cc0569bbfd3c340f006/8ff5a/deployment-all-delete-create.png 240w,
/static/32d381edc7b38cc0569bbfd3c340f006/e85cb/deployment-all-delete-create.png 480w,
/static/32d381edc7b38cc0569bbfd3c340f006/d9199/deployment-all-delete-create.png 960w,
/static/32d381edc7b38cc0569bbfd3c340f006/b6c94/deployment-all-delete-create.png 1429w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/32d381edc7b38cc0569bbfd3c340f006/d9199/deployment-all-delete-create.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
	&lt;figcaption&gt; Delete all old pods, and then create all new pods &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/b3be12fbd77a0b3bd8fe4fb497d29274/07a9c/deployment-all-create-then-replace.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 40.416666666666664%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAYAAAD5nd/tAAAACXBIWXMAAAsSAAALEgHS3X78AAABpklEQVQoz1VSf2+bMBDl+3+M9a9qq5Q2UtdJrapqVapkyrqEEmEcfnRAEhIYtBQbk5C3w+mqzNKT7bt37x6Hjf1+jw7d2u12EEJASIHtdvtfXPPo3O1N02ielFLn8B7vYOBoNUohy1L8yTIoOn/ESaBt2497J5SmGxRFji3ljpehO5IbWdfkTKImoUO39t1h50hpwf2Rk5ZQq5rEBWqq/fdFhrtOcfbTxKVpoz+d4cpiGLFr3D+dYzDr43byBV40wTRaozexcEn5/tTGHXMwsC7w3ewRzon3GUkewijJlRMv4ISxRphmWGUR/MiGF9rwY4bilcbwJsAoz8JI78s8x2LtE48Rj+F5ySFVRTMkm2Hgw+MOXIehKl9RUTFnHHPuIqJiUQmKlQg8V/MCdw5VS5p1Du7MCRzLxeoww06QhSFOh2N8m1ooyxJSSIxmN/g6/AQvnqHIX5BnG/zyn3Ey+IEhNZKiQvGS4+6xh+vxKaKV30kdBOMkwch2YPqBfg6qVuDBEybsAYvkN/3xBjsauhfHeCAej2L9Ikpybc3HMPkImyzRgn8B52lWIdk16TYAAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/b3be12fbd77a0b3bd8fe4fb497d29274/8ac56/deployment-all-create-then-replace.webp 240w,
/static/b3be12fbd77a0b3bd8fe4fb497d29274/d3be9/deployment-all-create-then-replace.webp 480w,
/static/b3be12fbd77a0b3bd8fe4fb497d29274/e46b2/deployment-all-create-then-replace.webp 960w,
/static/b3be12fbd77a0b3bd8fe4fb497d29274/f992d/deployment-all-create-then-replace.webp 1440w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/b3be12fbd77a0b3bd8fe4fb497d29274/8ff5a/deployment-all-create-then-replace.png 240w,
/static/b3be12fbd77a0b3bd8fe4fb497d29274/e85cb/deployment-all-create-then-replace.png 480w,
/static/b3be12fbd77a0b3bd8fe4fb497d29274/d9199/deployment-all-create-then-replace.png 960w,
/static/b3be12fbd77a0b3bd8fe4fb497d29274/07a9c/deployment-all-create-then-replace.png 1440w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/b3be12fbd77a0b3bd8fe4fb497d29274/d9199/deployment-all-create-then-replace.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
	&lt;figcaption&gt; Create all new pods, and then delete all old pods &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/3748cf441d26967ecb55ad5bb343df5c/5faa8/deployment-delete-one-and-add.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 42.91666666666667%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsSAAALEgHS3X78AAAB1ElEQVQoz32RaW/TQBBA/f9/B19QVRBqSgFBD1oJSHPYKW18xGe8jo/S2GlF7Bx9TNwK8aFipZFGb9/Mzu5qm+2W1WrFer1iK/lms2ljtX6B/cfbbDfsltY0NeX8jqoq2eVN01Avl5TlvGV1/czql1hNVZYtW0rN46M0rGWjWixELtsJduJyJ1bVM2v+YU/FzY5J1DJAtaj+DgOPaHs9g85ozMHgisOTc3rWhLfGDZ2LLh8uvnIyeo1uDzk4/s6XQYczY59jfY8bv8epvs+p8Ybzq3d8vHxFdhehBbd3eFmBl+YoiThNcfOCcJah8ox0HgiPCeKUbK5QhUvyyyctYsm9NqJ0grp1qVe/paHrEkchaaKI4ynxNMK1bbLZjEyah0Ek+8ImDkV+S6JmhH4o3hTfC8TJiULJXb99U80YDpg4NrY0MXSDZJYwMnRsa4zjOOhDnUQO+zkyxLOwTLNlM/Gur0bima036PdZyF9on8wJepBgBZf8sI6kOOGz5TLwY+ywL+w9SimOHY9hoBh7XbrOkbCYMzeg502xgz7fzEMW9xVaX8Z3lFxNWYzDHkWRS2GENU2IEpub8JI8z9HlWjsviM0nT9goijFj8ZTNtd/l4eGePx/WlTngqY4iAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/3748cf441d26967ecb55ad5bb343df5c/8ac56/deployment-delete-one-and-add.webp 240w,
/static/3748cf441d26967ecb55ad5bb343df5c/d3be9/deployment-delete-one-and-add.webp 480w,
/static/3748cf441d26967ecb55ad5bb343df5c/e46b2/deployment-delete-one-and-add.webp 960w,
/static/3748cf441d26967ecb55ad5bb343df5c/f992d/deployment-delete-one-and-add.webp 1440w,
/static/3748cf441d26967ecb55ad5bb343df5c/6a202/deployment-delete-one-and-add.webp 1444w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/3748cf441d26967ecb55ad5bb343df5c/8ff5a/deployment-delete-one-and-add.png 240w,
/static/3748cf441d26967ecb55ad5bb343df5c/e85cb/deployment-delete-one-and-add.png 480w,
/static/3748cf441d26967ecb55ad5bb343df5c/d9199/deployment-delete-one-and-add.png 960w,
/static/3748cf441d26967ecb55ad5bb343df5c/07a9c/deployment-delete-one-and-add.png 1440w,
/static/3748cf441d26967ecb55ad5bb343df5c/5faa8/deployment-delete-one-and-add.png 1444w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/3748cf441d26967ecb55ad5bb343df5c/d9199/deployment-delete-one-and-add.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
	&lt;figcaption&gt; Delete one, and create one, and so on &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/b63e90f8013c2a1df5f7ad0f05da9ce0/8b936/deployment-rolling-update.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 47.5%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAAB2ElEQVQoz21S2ZKbQAzk//8lz/uSw5tKbG9ly8t61zbYGBg7w3Aa8PjgdGc0Cbm7SpQkhJBabUgp0XUdCLfbDX3fo7peUZal9glFUeCqcsP7ART/bgQjCALUdY0oinA6nUAxDzhs20aapkiSBJa1QhiG4JzjeDxqfxji7+YGBVVV6+KypOIIh6xQjYVumCYZQhEiU75QubO86Nq2a3UjmviPCauqQqOMEIY7pJnALloiPUSI4xg8cRFme0RxhDSP4PAX1QVom05tJDU118vl14R1dYWnpnLCGA/WK+beBu+XE7w6M7ysP+PJeQtzfY8nawybzTB6fgORMjBh41hKCCH0j2kbGs64tQ1m/h4je4uPDsNsL/DO3mPOXEycZ3zxLJi+jUf7DhtuYrq6w8KfwtzeK+LUwcpCcz8c10DfYb7nGG8Zxi6D+VVgtHFh7gJ8cjkmPsejsomzwJIzfFBbbPgMCzb9zuGt/3l5vTI9yvMZhbIwy3A4SsRKJpmy6HDQcVqUCNIcuVQ1uUSWx4gV113baYW0bYs8z3FRXBrDdQie62LHmPbpqtZqhYY+aBqsLQuJ4oog5QlFXvxfNoPT/zASsO/7Wm8EIp0rbRIo53ke6qb+R9gDvgGGE/R/BoLWhAAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/b63e90f8013c2a1df5f7ad0f05da9ce0/8ac56/deployment-rolling-update.webp 240w,
/static/b63e90f8013c2a1df5f7ad0f05da9ce0/d3be9/deployment-rolling-update.webp 480w,
/static/b63e90f8013c2a1df5f7ad0f05da9ce0/e46b2/deployment-rolling-update.webp 960w,
/static/b63e90f8013c2a1df5f7ad0f05da9ce0/338ac/deployment-rolling-update.webp 1368w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/b63e90f8013c2a1df5f7ad0f05da9ce0/8ff5a/deployment-rolling-update.png 240w,
/static/b63e90f8013c2a1df5f7ad0f05da9ce0/e85cb/deployment-rolling-update.png 480w,
/static/b63e90f8013c2a1df5f7ad0f05da9ce0/d9199/deployment-rolling-update.png 960w,
/static/b63e90f8013c2a1df5f7ad0f05da9ce0/8b936/deployment-rolling-update.png 1368w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/b63e90f8013c2a1df5f7ad0f05da9ce0/d9199/deployment-rolling-update.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
	&lt;figcaption&gt; Create several and delete several, and so on (rolling update) &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;p&gt;And actually, Deployment works by ReplicaSet:&lt;/p&gt;
&lt;figure style=&quot;max-width: 400px&quot;&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 782px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/3b61e9f04e0c79aa493e7f608d7d7b7e/2e195/deployment-replicaSet-pod.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 21.666666666666668%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAECAYAAACOXx+WAAAACXBIWXMAAAsSAAALEgHS3X78AAAA+0lEQVQY0y2P3U7CQBhEef8H8C+mRhO90CujIFHvNNFAJCAFIuAFP7ZdSgtt13a7ND3C4pecZDKTTL6plGVJlmXkef6PIk1TdpdrhVjNWMbOlh+jVZ6ZzI8TZuEaJ0qYBivW8tf4laIoSJIEITw8z2WxEATBEpVpJs6QauuY2/ejLYfUO6fMxDepTLkbjLnsDrHePrgZTrhu2QRRvC+Ucl/oug6+vyAMAyjBC6Y8dc+pNS2qDYtn+wIRzqEoue+POGsPOHltctUbc/DSYOQKKmbadqrW2rDTSinz/qbYEMkQmUWGWK7QG22yub+k1rZ5tL946PSof/YJEskfqlQmPvxtYi8AAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/3b61e9f04e0c79aa493e7f608d7d7b7e/8ac56/deployment-replicaSet-pod.webp 240w,
/static/3b61e9f04e0c79aa493e7f608d7d7b7e/d3be9/deployment-replicaSet-pod.webp 480w,
/static/3b61e9f04e0c79aa493e7f608d7d7b7e/c0b7e/deployment-replicaSet-pod.webp 782w&quot; sizes=&quot;(max-width: 782px) 100vw, 782px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/3b61e9f04e0c79aa493e7f608d7d7b7e/8ff5a/deployment-replicaSet-pod.png 240w,
/static/3b61e9f04e0c79aa493e7f608d7d7b7e/e85cb/deployment-replicaSet-pod.png 480w,
/static/3b61e9f04e0c79aa493e7f608d7d7b7e/2e195/deployment-replicaSet-pod.png 782w&quot; sizes=&quot;(max-width: 782px) 100vw, 782px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/3b61e9f04e0c79aa493e7f608d7d7b7e/2e195/deployment-replicaSet-pod.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/barry800414/k8s-example/tree/master/k8s/deployment&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Demo time !&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;persistent-volume&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#persistent-volume&quot; aria-label=&quot;persistent volume permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Persistent Volume&lt;/h3&gt;
&lt;p&gt;Pods can be deleted/removed at any time, and all the files inside pod will disappear by default. However, for some of service, persistent storage is crucial. (e.g. DB service)&lt;/p&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/b23b3384947b362bdcf4afb79ec64ec3/01294/volume.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 28.750000000000004%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAAsSAAALEgHS3X78AAABZ0lEQVQY032RXU/TYBiG+zdJPJLfYeJv8MwDWDRiDAQDw2gQN4FE2q5D+76t/Rjrxrsy3Ec2gtsq3WgvaznTxCu58uQ+eXLnebRo1ERNBGoqaA/OCWITv2cQDWw6I1ko6Awld8uEP+R5/pcZeXZfmJVZ2zdecqC/pqpvsXv6gjdHG+x8rvDJq1BvVaiFG9SCTW7mIx7I+R/a/qHF2wOTnb0v7FZ19t5ZHB4Ljv1tmp0PSHWCHlbLhUUZVqtl4ao0y3KSQYtENVioc9L5FM31v3PZ7RJFbeI4ZjqZ4IUBdWebi8jHd1v4F4LJ7Aej4RilFNfXfa6u+izmPxm+f0pYeYx6tc5tUEP7KgVCSL7ZotRxXPSmxUd7i1bXxfc8ZNhgfNsvG6ZpynL50PJXMieuPsF4toZ8/ohZWEc7s09puAYNx8Aqpil1TOcMcXlC0LNo9yWeMknuZv/cq/gB6Tgi6TVJYpvV4obfMTquFyF3VDEAAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/b23b3384947b362bdcf4afb79ec64ec3/8ac56/volume.webp 240w,
/static/b23b3384947b362bdcf4afb79ec64ec3/d3be9/volume.webp 480w,
/static/b23b3384947b362bdcf4afb79ec64ec3/e46b2/volume.webp 960w,
/static/b23b3384947b362bdcf4afb79ec64ec3/f992d/volume.webp 1440w,
/static/b23b3384947b362bdcf4afb79ec64ec3/18043/volume.webp 1615w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/b23b3384947b362bdcf4afb79ec64ec3/8ff5a/volume.png 240w,
/static/b23b3384947b362bdcf4afb79ec64ec3/e85cb/volume.png 480w,
/static/b23b3384947b362bdcf4afb79ec64ec3/d9199/volume.png 960w,
/static/b23b3384947b362bdcf4afb79ec64ec3/07a9c/volume.png 1440w,
/static/b23b3384947b362bdcf4afb79ec64ec3/01294/volume.png 1615w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/b23b3384947b362bdcf4afb79ec64ec3/d9199/volume.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
	&lt;figcaption&gt; We need a persistent storage even pod was deleted and re-created &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/61490ed023feef280c92bc909851b446/e84a7/persistent-volume-claim.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 46.25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsSAAALEgHS3X78AAAB0klEQVQoz2WSa2+aYBiG/YXLftuyZKcvO2TdMYtZtDZNq22tJ6xbQWiVWc8DUfCEglXxGkI1W/aQi+cOL9zv/T4hsrh3KHeTPicoWpJS/YjszXfytzHKnTOkTgqxlcJZ2Gxrs9n4eIGed8tYmReYly+Z65XgWWQ6H5LIH/LlOMbHxDcO4l/5EI8Sz0W5uHvn855k5TUTx3ww9Nh460CPSp+Rnz5GevKIqRwLDcezIeeFIvmCSianIFypiFKXlHBJUT3mV13hZ/WCkd3fJ/TvgXb1G1qnz2iePsc11NDQmpiU5CI1tYoiS6jVW9qNJudXJ1yrGSrlGkr1GmPY3Rsul8uAlefrdWi+W4vMXZucmKYoCQhSIUQUyJbPKLfS1DoySjPPaDrAe/jYsiwMw0DXdfp9IxzDlm3CwNm/vM06wFfMnRmmOQiwrD6jkcVqeb8/6mKxYL0O57jr+4ThTP4tzz/KbDbDtm3aHYO7hka720frDZlOp0iSSK/Xw3VdxuMxk8kEx3HCGYa/wf8Eu3se0cMCr94c+SR4+ymFpvdpNOoMBoOg53JZ8vkcmvY7NPw72c5o11erFT+kBsm0RCotkhWqfqrl/n3TNFEUGVmWgw229QfGCpf9NIKMegAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/61490ed023feef280c92bc909851b446/8ac56/persistent-volume-claim.webp 240w,
/static/61490ed023feef280c92bc909851b446/d3be9/persistent-volume-claim.webp 480w,
/static/61490ed023feef280c92bc909851b446/e46b2/persistent-volume-claim.webp 960w,
/static/61490ed023feef280c92bc909851b446/25b5c/persistent-volume-claim.webp 1317w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/61490ed023feef280c92bc909851b446/8ff5a/persistent-volume-claim.png 240w,
/static/61490ed023feef280c92bc909851b446/e85cb/persistent-volume-claim.png 480w,
/static/61490ed023feef280c92bc909851b446/d9199/persistent-volume-claim.png 960w,
/static/61490ed023feef280c92bc909851b446/e84a7/persistent-volume-claim.png 1317w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/61490ed023feef280c92bc909851b446/d9199/persistent-volume-claim.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
	&lt;figcaption&gt; Inside kubernetes, the concept was splitted into PersistentVolume and PersistentVolumeClaim &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;figure&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/08d5536a26713e2604e3cdc325f69cf9/2b608/persistent-volume-flow.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 50.83333333333333%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsSAAALEgHS3X78AAAB10lEQVQoz4VSyY7TQBD1N3Lld7hzQkgcRuIKAiHBYRBiOYCYzFiyEkxCJrbjfe3Y8R47th9djSYwMBIll9vdrq5671VJ4zgiTVPQut/v4XkegiBAGIbCfd8X59M04S4b+haZdoHs+gu6JodEca5ro++P2O12MAwDlmVhu93CNE3Ytg3HcVAUBY/p0XUdDocDukOLbgCq4Br62X3oT+6hcReQmtSD/eYB9qaC/9kwDIJJkiTQdQ2O66HJGSL5JaLLZzhWDFKaxPh4/g4uRxTHMTabjUBGCHVdh65p2HLUtM+yTDChuNnsAuv1D3R8z4HiRhAJf2zquhbV6SKtURSBseSkZ11XJ7QUQ9SFttPIn0F8S/SiwIkfUhA1gS6TXsMw3qJsuTE0w0fCckH/bxMJCZ/j2DjyBIwxQY0aEfgB18iCH9s4dDXiJMPjs9d4+Og5zt9foSoLlGUpvKoqNE3zizIrK7xQljBi9k/FjTPH5eITvmkzTq+DYQYwrBC7tOCT4UKWZSwWC6iqKrQXCOPdHq8+KNhYPuIoFI2gprRNi+/GFeaqjPn6K45Df6sYzSaNV57nAmHbtr+bcmNUdbVaYbla8uQMeqTgrfIUqvP5pBH5ON495PTvJ+Ee8R2pxkXrAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/08d5536a26713e2604e3cdc325f69cf9/8ac56/persistent-volume-flow.webp 240w,
/static/08d5536a26713e2604e3cdc325f69cf9/d3be9/persistent-volume-flow.webp 480w,
/static/08d5536a26713e2604e3cdc325f69cf9/e46b2/persistent-volume-flow.webp 960w,
/static/08d5536a26713e2604e3cdc325f69cf9/f992d/persistent-volume-flow.webp 1440w,
/static/08d5536a26713e2604e3cdc325f69cf9/96506/persistent-volume-flow.webp 1540w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/08d5536a26713e2604e3cdc325f69cf9/8ff5a/persistent-volume-flow.png 240w,
/static/08d5536a26713e2604e3cdc325f69cf9/e85cb/persistent-volume-flow.png 480w,
/static/08d5536a26713e2604e3cdc325f69cf9/d9199/persistent-volume-flow.png 960w,
/static/08d5536a26713e2604e3cdc325f69cf9/07a9c/persistent-volume-flow.png 1440w,
/static/08d5536a26713e2604e3cdc325f69cf9/2b608/persistent-volume-flow.png 1540w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/08d5536a26713e2604e3cdc325f69cf9/d9199/persistent-volume-flow.png&quot; alt=&quot;service usage example&quot; title=&quot;service usage example&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
	&lt;figcaption&gt; The work flow of using persistent storage in kubernetes &lt;/figcaption&gt;
&lt;/figure&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/barry800414/k8s-example/tree/master/k8s/persistentVolume&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Demo time !&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h3 id=&quot;important-resource-types-recap&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#important-resource-types-recap&quot; aria-label=&quot;important resource types recap permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Important resource types recap&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Pod: basic working unit&lt;/li&gt;
&lt;li&gt;Service (NodePort, LoadBalancer) &amp;#x26; Ingress: for networking&lt;/li&gt;
&lt;li&gt;ReplicaSet: to keep stable number of replica pods&lt;/li&gt;
&lt;li&gt;Deployment: to deploy application more gracefully&lt;/li&gt;
&lt;li&gt;Persistent Volume: to save data persistently&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;tips-for-inspecting-issues-in-kubernetes-cluster-while-on-duty&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#tips-for-inspecting-issues-in-kubernetes-cluster-while-on-duty&quot; aria-label=&quot;tips for inspecting issues in kubernetes cluster while on duty permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Tips for inspecting issues in Kubernetes cluster while on duty&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Common tasks for onduty person:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;ensure applications running correctly&lt;/li&gt;
&lt;li&gt;scale up/down service if needed&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;how-to-monitor-whether-application-is-running-properly-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-to-monitor-whether-application-is-running-properly-&quot; aria-label=&quot;how to monitor whether application is running properly  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How to monitor whether application is running properly ?&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Pod: status, age&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Monitoring service like Grafana &amp;#x26; Prometheus&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;worker: understand the source of jobs, usually a queue.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;how many tasks are there in a queue ?&lt;/li&gt;
&lt;li&gt;what is the producing / consuming velocity ?&lt;/li&gt;
&lt;li&gt;what is the oldest task in the queue ?&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;server: request per second / latency (response time)&lt;/li&gt;
&lt;li&gt;cronjob: log&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;reference&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#reference&quot; aria-label=&quot;reference permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Reference&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://www.manning.com/books/kubernetes-in-action&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Kubernetes in Action&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[JS Memory Leak 簡單也不簡單]]></title><description><![CDATA[Jest 是一款測試執行套件，是 Javascript 領域裡面最有名的測試執行套件，由 Facebook 維護。寫過 Javascript 的人多少使用過它，但卻有可能遇到記憶體不足的問題。本篇便是解釋如何解決記憶體不足的問題。]]></description><link>https://wei-ming.tw/posts/js-memory-leak</link><guid isPermaLink="false">https://wei-ming.tw/posts/js-memory-leak</guid><pubDate>Sun, 24 Jan 2021 19:12:04 GMT</pubDate><content:encoded>&lt;h2 id=&quot;故事&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E6%95%85%E4%BA%8B&quot; aria-label=&quot;故事 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;故事&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;跑 AIQUA UI unit testing 的時候，發生記憶體不足的問題&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token constant&quot;&gt;FAIL&lt;/span&gt; src&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;HtmlCreative&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;test&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;js
  ● Test suite failed to run 

  &lt;span class=&quot;token constant&quot;&gt;ENOMEM&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; not enough memory&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;CI 環境上有 6GB 的記憶體，真的不夠嗎？&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;實驗與觀察&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%AF%A6%E9%A9%97%E8%88%87%E8%A7%80%E5%AF%9F&quot; aria-label=&quot;實驗與觀察 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;實驗與觀察&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;我們在用的是 Jest 這款 task runner&lt;/li&gt;
&lt;li&gt;它有提供兩個指令 &lt;code class=&quot;language-text&quot;&gt;--runInBand&lt;/code&gt; &amp;#x26; &lt;code class=&quot;language-text&quot;&gt;--logHeapUsage&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;--runInBand&lt;/code&gt;：只用一個 worker，一個測試跑完才跑下個測試&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;--logHeapUsage&lt;/code&gt;：輸出 heap memory 的使用量&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;實驗結果&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%AF%A6%E9%A9%97%E7%B5%90%E6%9E%9C&quot; aria-label=&quot;實驗結果 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;實驗結果&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token constant&quot;&gt;PASS&lt;/span&gt;  src&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;JourneyChart&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;test&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;js&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;9.628&lt;/span&gt;s&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;160&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;MB&lt;/span&gt; heap size&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token constant&quot;&gt;PASS&lt;/span&gt;  src&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;ReachMethodNode&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;test&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;js&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;195&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;MB&lt;/span&gt; heap size&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;token constant&quot;&gt;PASS&lt;/span&gt;  src&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;validateGoalEvents&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;test&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;js&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2588&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;MB&lt;/span&gt; heap size&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token constant&quot;&gt;PASS&lt;/span&gt;  src&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;booleanString&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;test&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;js&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2603&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;MB&lt;/span&gt; heap size&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;End&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;p&gt;&lt;img src=&quot;https://i.imgflip.com/4v8c5f.jpg&quot;&gt; &lt;/p&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;其他人也遇到了一樣的問題嗎？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%85%B6%E4%BB%96%E4%BA%BA%E4%B9%9F%E9%81%87%E5%88%B0%E4%BA%86%E4%B8%80%E6%A8%A3%E7%9A%84%E5%95%8F%E9%A1%8C%E5%97%8E%EF%BC%9F&quot; aria-label=&quot;其他人也遇到了一樣的問題嗎？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;其他人也遇到了一樣的問題嗎？&lt;/h2&gt;
&lt;figure style=&quot;max-width: 600px; border: solid 2px rgb(200, 200, 200);&quot;&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/c209dbd56a0a621acd9c86802ad68e1e/2093e/github-issue-1.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 21.666666666666668%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAECAYAAACOXx+WAAAACXBIWXMAAAsSAAALEgHS3X78AAAAzklEQVQY021Oy07EMBDr//8JVzhyRuLEQ0ICcaPdbmk32UzSpHk01ExGHLFk2Y6jxJ22GwadhD5VlH1HLjtrFc2cS6mwxmENG4x18CEw2ZMTbSTHvffoYilwPoAMwegrcspc8AW7YosJYYuIfOZWL7518gD3LRuy8jEOCLroIgIFWCJctQaxKlalmrfiL0qJJ16XcsZxHKi14udPG16XDzyMT+hu3+9x83yHcZzQDyecpwnDacRX32Pg/D3PmJeFl5AsK23NP3i7fOLx/IJftugxv6M4a5EAAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/c209dbd56a0a621acd9c86802ad68e1e/8ac56/github-issue-1.webp 240w,
/static/c209dbd56a0a621acd9c86802ad68e1e/d3be9/github-issue-1.webp 480w,
/static/c209dbd56a0a621acd9c86802ad68e1e/e46b2/github-issue-1.webp 960w,
/static/c209dbd56a0a621acd9c86802ad68e1e/f992d/github-issue-1.webp 1440w,
/static/c209dbd56a0a621acd9c86802ad68e1e/48a02/github-issue-1.webp 1858w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/c209dbd56a0a621acd9c86802ad68e1e/8ff5a/github-issue-1.png 240w,
/static/c209dbd56a0a621acd9c86802ad68e1e/e85cb/github-issue-1.png 480w,
/static/c209dbd56a0a621acd9c86802ad68e1e/d9199/github-issue-1.png 960w,
/static/c209dbd56a0a621acd9c86802ad68e1e/07a9c/github-issue-1.png 1440w,
/static/c209dbd56a0a621acd9c86802ad68e1e/2093e/github-issue-1.png 1858w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/c209dbd56a0a621acd9c86802ad68e1e/d9199/github-issue-1.png&quot; alt=&quot;&amp;#x4F9D;&amp;#x8CF4;&amp;#x53CD;&amp;#x8F49;&amp;#x7BC4;&amp;#x4F8B;&amp;#x4E09;&quot; title=&quot;&amp;#x4F9D;&amp;#x8CF4;&amp;#x53CD;&amp;#x8F49;&amp;#x7BC4;&amp;#x4F8B;&amp;#x4E09;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;figure style=&quot;max-width: 600px; border: solid 2px rgb(200, 200, 200);&quot;&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/a1b1f474e4b1a1a26a65bb70a41dbf01/e0202/github-issue-2.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 33.33333333333333%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAYAAAAIy204AAAACXBIWXMAAAsSAAALEgHS3X78AAABJ0lEQVQoz51Q7Y6CMBDk/V/v5EPB8yIoQimlrQjF6rhdYkwu9+s2WWaXbGdnNjocfqDNFUIqKG0wUC2V5v42OczLHbP7nQtkP9C85fmAxo643z2iVgj0RFBfWrSiQ9MKWmAxzQ6OyBYaYqRc+xVv08wzId+19w9EoCj234iTFLs8x9cmpgUK/4nn84kofEJorWEMWR40FBGKrkNQL/ueayk/2JKLnv6HWWMt4ziOK2Egm6aJFabZljBBXuyRZBmy7Y4zTlNs4oQcFEjSjFwk2O5ynOsal6ZBXV/gnGNhTOi9R1lWOFJWpzPKqsLpXDM2Tcsqg4orqVBUGz1ADwpdJ0kpuaHbu2X5EC7UhG2B4E0Y+uOxpPvu+WGwq4i0uz7QGA9h/Z83fAEowxVa7TnhYgAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/a1b1f474e4b1a1a26a65bb70a41dbf01/8ac56/github-issue-2.webp 240w,
/static/a1b1f474e4b1a1a26a65bb70a41dbf01/d3be9/github-issue-2.webp 480w,
/static/a1b1f474e4b1a1a26a65bb70a41dbf01/e46b2/github-issue-2.webp 960w,
/static/a1b1f474e4b1a1a26a65bb70a41dbf01/79a63/github-issue-2.webp 1395w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/a1b1f474e4b1a1a26a65bb70a41dbf01/8ff5a/github-issue-2.png 240w,
/static/a1b1f474e4b1a1a26a65bb70a41dbf01/e85cb/github-issue-2.png 480w,
/static/a1b1f474e4b1a1a26a65bb70a41dbf01/d9199/github-issue-2.png 960w,
/static/a1b1f474e4b1a1a26a65bb70a41dbf01/e0202/github-issue-2.png 1395w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/a1b1f474e4b1a1a26a65bb70a41dbf01/d9199/github-issue-2.png&quot; alt=&quot;&amp;#x4F9D;&amp;#x8CF4;&amp;#x53CD;&amp;#x8F49;&amp;#x7BC4;&amp;#x4F8B;&amp;#x4E09;&quot; title=&quot;&amp;#x4F9D;&amp;#x8CF4;&amp;#x53CD;&amp;#x8F49;&amp;#x7BC4;&amp;#x4F8B;&amp;#x4E09;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;解決方案&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E8%A7%A3%E6%B1%BA%E6%96%B9%E6%A1%88&quot; aria-label=&quot;解決方案 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;解決方案&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;降版到 Jest 23 -&gt; 失敗！&lt;/li&gt;
&lt;li&gt;Add &lt;code class=&quot;language-text&quot;&gt;--expose-gc&lt;/code&gt; -&gt; 成功 !?&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;--max-old-space-size&lt;/code&gt; -&gt; 成功 ! &lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;--expose-gc&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#--expose-gc&quot; aria-label=&quot;  expose gc permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;code class=&quot;language-text&quot;&gt;--expose-gc&lt;/code&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;執行 Node.js 時，在 global 物件底下新增 &lt;code class=&quot;language-text&quot;&gt;gc&lt;/code&gt; function&lt;/li&gt;
&lt;li&gt;gc = garbage collect&lt;/li&gt;
&lt;li&gt;善意提醒 Node.js 清理 unused heap memory&lt;/li&gt;
&lt;li&gt;process.memoryUsage()&lt;/li&gt;
&lt;li&gt;Q: heapTotal &amp;#x26; heapUsed 到底不同在哪邊？&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;為什麼加---expose-gc-有用？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E7%82%BA%E4%BB%80%E9%BA%BC%E5%8A%A0---expose-gc-%E6%9C%89%E7%94%A8%EF%BC%9F&quot; aria-label=&quot;為什麼加   expose gc 有用？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;為什麼加 &lt;code class=&quot;language-text&quot;&gt;--expose-gc&lt;/code&gt; 有用？&lt;/h2&gt;
&lt;figure style=&quot;max-width: 600px&quot;&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 930px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/4503e009875ff32b7f5108af3730f744/416ee/jest-source-1.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 34.166666666666664%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAYAAAAIy204AAAACXBIWXMAAAsSAAALEgHS3X78AAABA0lEQVQoz5VR2W6EMAzk/z+wh6qyZdkuG0g4Q+4wdQI8VKq0qqXRSPbEHsfFajwqblB1Gl+EWhjUXGfcepNrk/IIIcD55yjm1eD9KvBadXgjvtwHvJR3fNQcfHZgo8WsHIk9rHuOwjsHoxWwRWyrRMcYqmuFpmnQdgI3sTu/tBpilNlp3DbE+DcKT5O11shBYs5afJYlvpseDz5lZ4GEPsT8ANRsy3TyjjNyQ6XU0S9gkRLLvMCuDsE7/CfSkF8OE3POISaFund0IJuxSAVGXyH4iJ4ZDK0BbySGWaFs94M6+r/DYYC1NrszB/t8sQhHa6ZVQ0wcci1QPqTcwacmkiY5/AH7UiAzpcJrqwAAAABJRU5ErkJggg==&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/4503e009875ff32b7f5108af3730f744/8ac56/jest-source-1.webp 240w,
/static/4503e009875ff32b7f5108af3730f744/d3be9/jest-source-1.webp 480w,
/static/4503e009875ff32b7f5108af3730f744/6eb96/jest-source-1.webp 930w&quot; sizes=&quot;(max-width: 930px) 100vw, 930px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/4503e009875ff32b7f5108af3730f744/8ff5a/jest-source-1.png 240w,
/static/4503e009875ff32b7f5108af3730f744/e85cb/jest-source-1.png 480w,
/static/4503e009875ff32b7f5108af3730f744/416ee/jest-source-1.png 930w&quot; sizes=&quot;(max-width: 930px) 100vw, 930px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/4503e009875ff32b7f5108af3730f744/416ee/jest-source-1.png&quot; alt=&quot;&amp;#x4F9D;&amp;#x8CF4;&amp;#x53CD;&amp;#x8F49;&amp;#x7BC4;&amp;#x4F8B;&amp;#x4E09;&quot; title=&quot;&amp;#x4F9D;&amp;#x8CF4;&amp;#x53CD;&amp;#x8F49;&amp;#x7BC4;&amp;#x4F8B;&amp;#x4E09;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;--max-old-space-sizesize&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#--max-old-space-sizesize&quot; aria-label=&quot;  max old space sizesize permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;code class=&quot;language-text&quot;&gt;--max-old-space-size=SIZE&lt;/code&gt;&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;當 unused heap memory 接近指定的用量的時候，V8 引擎會花更多時間在 garbage collection 上&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt; &lt;span class=&quot;token constant&quot;&gt;PASS&lt;/span&gt;  src&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;JourneyChart&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;test&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;js&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;6.902&lt;/span&gt;s&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;135&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;MB&lt;/span&gt; heap size&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
 &lt;span class=&quot;token constant&quot;&gt;PASS&lt;/span&gt;  src&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;CreativePanel&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;test&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;js&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;131&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;MB&lt;/span&gt; heap size&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
 &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;
 &lt;span class=&quot;token constant&quot;&gt;PASS&lt;/span&gt;  src&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;ScenarioToolbar&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;test&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;js&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;893&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;MB&lt;/span&gt; heap size&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
 &lt;span class=&quot;token constant&quot;&gt;PASS&lt;/span&gt;  src&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;CreativeImagesAction&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;test&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;js&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;916&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;MB&lt;/span&gt; heap size&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
 
 &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;everytime it reachs &lt;span class=&quot;token number&quot;&gt;1024&lt;/span&gt;MB&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; it will swipe ununsed memory&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
 
 &lt;span class=&quot;token constant&quot;&gt;PASS&lt;/span&gt;  src&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;validateAudiencePlatform&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;test&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;js&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;180&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;MB&lt;/span&gt; heap size&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
 &lt;span class=&quot;token constant&quot;&gt;PASS&lt;/span&gt;  src&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;validateHtmlCreative&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;test&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;js&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;186&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;MB&lt;/span&gt; heap size&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
 &lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;
 &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;end&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;p&gt;&lt;img src=&quot;https://cdn0-manfashion.techbang.com/system/excerpt_images/11969/mobile_inpage/c0194e50f4db09e33d417305df523752.jpg?1598596622&quot;&gt;&lt;/p&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;兩種層級的-memory-leak&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%85%A9%E7%A8%AE%E5%B1%A4%E7%B4%9A%E7%9A%84-memory-leak&quot; aria-label=&quot;兩種層級的 memory leak permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;兩種層級的 Memory Leak&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Node.js 心裡有偵測到 unused memory 很多，但 Node.js &lt;del&gt;不說&lt;/del&gt; 不釋放&lt;/li&gt;
&lt;li&gt;Node.js 真的沒偵測到那塊 unused memory&lt;/li&gt;
&lt;/ul&gt;
&lt;figure style=&quot;max-width: 600px&quot;&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 800px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/1d70bda16bd858959ab41d0ae8a09930/5a190/true-memory-leak.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAAAsSAAALEgHS3X78AAAAa0lEQVQY07XOzQpAQBSGYX8lQoOGLGTHBSi3YD1bZeP+L8KrvsSeU0/nNNOZ+Tzvx0rRaw7EIEeCCiGsupFId3f56hMOzQ0K7JgxYkMHhwwLVn3m9PCrSi0Ej5StXCkHLV2pYnWrs1qpv68Tkx8EpnHbKfIAAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/1d70bda16bd858959ab41d0ae8a09930/8ac56/true-memory-leak.webp 240w,
/static/1d70bda16bd858959ab41d0ae8a09930/d3be9/true-memory-leak.webp 480w,
/static/1d70bda16bd858959ab41d0ae8a09930/d00b9/true-memory-leak.webp 800w&quot; sizes=&quot;(max-width: 800px) 100vw, 800px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/1d70bda16bd858959ab41d0ae8a09930/8ff5a/true-memory-leak.png 240w,
/static/1d70bda16bd858959ab41d0ae8a09930/e85cb/true-memory-leak.png 480w,
/static/1d70bda16bd858959ab41d0ae8a09930/5a190/true-memory-leak.png 800w&quot; sizes=&quot;(max-width: 800px) 100vw, 800px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/1d70bda16bd858959ab41d0ae8a09930/5a190/true-memory-leak.png&quot; alt=&quot;&amp;#x4F9D;&amp;#x8CF4;&amp;#x53CD;&amp;#x8F49;&amp;#x7BC4;&amp;#x4F8B;&amp;#x4E09;&quot; title=&quot;&amp;#x4F9D;&amp;#x8CF4;&amp;#x53CD;&amp;#x8F49;&amp;#x7BC4;&amp;#x4F8B;&amp;#x4E09;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;小結&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%B0%8F%E7%B5%90&quot; aria-label=&quot;小結 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;小結&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Jest options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;--runInBand&lt;/code&gt;: 讓 Jest 只用一個 worker 跑測試，且一個跑完才跑下一個&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;--logHeapUsage&lt;/code&gt;: 輸出跑到每一個測試時的 heap 使用量&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Node.js options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;--expose-gc&lt;/code&gt;: 讓 Node.js 的 global 變數有 gc 函數，用於要求做 garbage collection&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;--max-old-space-size=SIZE&lt;/code&gt;: 設定 unused 記憶體的上限，接近上限值時會較頻繁做 garbage collection&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;更進一步&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E6%9B%B4%E9%80%B2%E4%B8%80%E6%AD%A5&quot; aria-label=&quot;更進一步 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;更進一步&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;我們要如何偵測真的 Memory Leak ？&lt;/li&gt;
&lt;li&gt;上面提的都是 Node.js 的環境，Browser 環境會不同嗎？&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;browser-環境&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#browser-%E7%92%B0%E5%A2%83&quot; aria-label=&quot;browser 環境 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Browser 環境&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;沒有 global.gc() 可用，基本上沒有任何方法可以要求瀏覽器做 garbage collection&lt;/li&gt;
&lt;li&gt;查看 heap 使用量: console.memory / window.performance.memory&lt;/li&gt;
&lt;li&gt;devtools&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;我們要如何偵測真的-memory-leak？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E6%88%91%E5%80%91%E8%A6%81%E5%A6%82%E4%BD%95%E5%81%B5%E6%B8%AC%E7%9C%9F%E7%9A%84-memory-leak%EF%BC%9F&quot; aria-label=&quot;我們要如何偵測真的 memory leak？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;我們要如何偵測真的 Memory Leak？&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;所謂 ”真的 Memory Leak“，代表的就是我們的 code 沒寫好，有一塊記憶體沒有釋放掉&lt;/li&gt;
&lt;li&gt;任何自動化的程式基本上無從得知那一塊沒被釋放掉的記憶體，到底是真的有要用，還是沒有&lt;/li&gt;
&lt;li&gt;不過，我們可以用工具提醒我們「可能」有 Memory Leak&lt;/li&gt;
&lt;li&gt;我們也可以盡可能知道什麼寫法會造成 Memory Leak&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;偵測可能的-memory-leak-方法&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%81%B5%E6%B8%AC%E5%8F%AF%E8%83%BD%E7%9A%84-memory-leak-%E6%96%B9%E6%B3%95&quot; aria-label=&quot;偵測可能的 memory leak 方法 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;偵測可能的 Memory Leak 方法&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/lloyd/node-memwatch&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;node-memwatch&lt;/a&gt;: 連續 5 次 garbage collection，heap usage 仍然上升&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://plasma-umass.org/BLeak/&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;BLeak&lt;/a&gt;: 在 browser 端自動化偵測 Memory Leak 的工具，有 24 頁的論文可以看&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://docs.google.com/presentation/d/1wUVmf78gG-ra5aOxvTfYdiLkdGaR9OhXRnOlIcEmu2s/pub?start=false&amp;#x26;loop=false&amp;#x26;delayms=3000&amp;#x26;slide=id.g1d65bdf6_0_0&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;3-snapshot technique&lt;/a&gt;: Google 當初解 Gmail website memory leak 的方法&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Snapshot 1 -&gt; do stuff -&gt; snapsht 2 -&gt; do same stuff -&gt; snapshot 3 -&gt; Compare snapshot 1, 2, 3&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://media-codings.com/articles/automatically-detect-memory-leaks-with-puppeteer&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Detect memory leak by puppteer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;哪些-pattern-會造成-memory-leak-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%93%AA%E4%BA%9B-pattern-%E6%9C%83%E9%80%A0%E6%88%90-memory-leak-&quot; aria-label=&quot;哪些 pattern 會造成 memory leak  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;哪些 Pattern 會造成 memory leak ?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;不小心用到全域變數&lt;/li&gt;
&lt;li&gt;忘記移除 timer &lt;/li&gt;
&lt;li&gt;忘記移除 event listener&lt;/li&gt;
&lt;li&gt;closure&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;總結&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E7%B8%BD%E7%B5%90&quot; aria-label=&quot;總結 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;總結&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;兩種層級的 memory leak&lt;/li&gt;
&lt;li&gt;沒有自動化的工具告訴我們是否真的有 memory leak ，以及 leak 在哪邊&lt;/li&gt;
&lt;li&gt;但 Chrome devtools 很實用&lt;/li&gt;
&lt;li&gt;我們也可以記得哪些 pattern 會有 memory leak&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;&lt;/hr&gt;
&lt;h2 id=&quot;待探索&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%BE%85%E6%8E%A2%E7%B4%A2&quot; aria-label=&quot;待探索 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;待探索&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Chrome devtools 的 heap snapshot 功能&lt;/li&gt;
&lt;li&gt;自動化在 browser 端檢測 memory leak 的方法，並加入 e2e testing&lt;/li&gt;
&lt;li&gt;react 上面會有 memory leak 的 pattern&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[直白理解什麼是 Dependency Inversion （依賴反轉）]]></title><description><![CDATA[Dependency Inversion 是一種程式設計技巧，有助於改變程式之間相互依賴的關係，寫出更容易被重複使用、更能擴充的程式，降低維護成本。是邁向資深工程師必學的概念。如果你聽過 SOLID 原則，Dependency Inversion 就是裡面的 "D"。]]></description><link>https://wei-ming.tw/posts/solid-dependency-inversion</link><guid isPermaLink="false">https://wei-ming.tw/posts/solid-dependency-inversion</guid><pubDate>Fri, 04 Dec 2020 16:12:04 GMT</pubDate><content:encoded>&lt;p&gt;第一次聽到 Dependency Inversion(依賴反轉) 這個詞，是在面試的時候。AmazingTalker 的 take home 專案裡面提到，期待面試者寫出來的程式碼，符合 &lt;strong&gt;SOLID 原則&lt;/strong&gt;。而其中 SOLID 的 &lt;strong&gt;D&lt;/strong&gt;，指的就是 &lt;strong&gt;D&lt;/strong&gt;ependency Inversion。&lt;/p&gt;
&lt;p&gt;使用依賴反轉，可以讓程式碼之間減少依賴，寫出維護成本更低的程式碼。&lt;/p&gt;
&lt;p&gt;而這一篇文章希望可以用最直白的方法，讓我們更好理解什麼是依賴反轉。&lt;/p&gt;
&lt;p&gt;以下的例子來自於 &lt;a href=&quot;https://bit.ly/clean-architecture-kingstone&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;無瑕的程式碼 ： 整潔的軟體設計與架構篇(Clean Architecture: A Craftsman’s Guide to Software Structure and Design)&lt;/a&gt; 這本書。&lt;/p&gt;
&lt;h2 id=&quot;情境&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E6%83%85%E5%A2%83&quot; aria-label=&quot;情境 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;情境&lt;/h2&gt;
&lt;p&gt;“請寫一支程式，可以輸出 Hello World 字串到終端機上”&lt;/p&gt;
&lt;p&gt;如果我們用 C 語言寫會是這樣：&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;c&quot;&gt;&lt;pre class=&quot;language-c&quot;&gt;&lt;code class=&quot;language-c&quot;&gt;&lt;span class=&quot;token macro property&quot;&gt;&lt;span class=&quot;token directive-hash&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;token directive keyword&quot;&gt;include&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;lt;stdio.h&gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Hello World&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;很簡單對吧！&lt;/p&gt;
&lt;h2 id=&quot;更多情境&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E6%9B%B4%E5%A4%9A%E6%83%85%E5%A2%83&quot; aria-label=&quot;更多情境 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;更多情境&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;如果我今天想要把 Hello World 字串寫到檔案裡面呢？&lt;/li&gt;
&lt;li&gt;如果儲存檔案的裝置換成磁帶呢？&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;我們要每一種裝置都重寫一份 code 嗎？ 如果是，那其實我們這支程式&lt;strong&gt;依賴&lt;/strong&gt;於裝置。
當我們有新的裝置要輸出，就要重新修改原本的程式碼。&lt;/p&gt;
&lt;p&gt;圖像化表示的話，會是這樣：&lt;/p&gt;
&lt;figure style=&quot;max-width: 450px&quot;&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 642px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/1f36c776542a9ab74f09fffa4125bafe/1bba8/di-1.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 43.75%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsSAAALEgHS3X78AAABdElEQVQoz21RWWoCQRSc6EfIZ3ICv7yEQ66Sy3gID+EFZpB8ua+4grsg7iuCH9rSlVfNzGQkaSj69aOqqNfPGg6HIAaDAUajEbrdrtrtdpjNZo4lB0CkXC5HWFerVXu5XEKgx+OxbrVa6PV6fGOxWKBYLMLK5XIolUrgLUK4rqsmkwnENDBsNpvGsN1u26fTCZfLRUut0+k0HMfhG8fjEY1GA9Z2u8V6vcZms/Fvdb1eMZ1OA8NMJhNlXalU7NVqZRLKramljumY0iTc7/dME0BI6na7keQbvhCsO51OgnyBFq4x9HXs12o1WIzKx+FwMJD6oZTiH36Lx2s8Hv+IxWLvUr8lk8kv8oWnPSCMer3+axiCoqEkdJlKRo+mUikzsvzxpyfWTBnWsW8SeqmeDO/3+9PI8/ncX0rC4/8xDEY+n8/g5kJQWmsu6N8te3ztIdCxb7Ysf8WNhqGYot/vB4b5fN4YFgoFm3yBFp4O69jPZrP4AUanMSS4f/hXAAAAAElFTkSuQmCC&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/1f36c776542a9ab74f09fffa4125bafe/8ac56/di-1.webp 240w,
/static/1f36c776542a9ab74f09fffa4125bafe/d3be9/di-1.webp 480w,
/static/1f36c776542a9ab74f09fffa4125bafe/7eb86/di-1.webp 642w&quot; sizes=&quot;(max-width: 642px) 100vw, 642px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/1f36c776542a9ab74f09fffa4125bafe/8ff5a/di-1.png 240w,
/static/1f36c776542a9ab74f09fffa4125bafe/e85cb/di-1.png 480w,
/static/1f36c776542a9ab74f09fffa4125bafe/1bba8/di-1.png 642w&quot; sizes=&quot;(max-width: 642px) 100vw, 642px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/1f36c776542a9ab74f09fffa4125bafe/1bba8/di-1.png&quot; alt=&quot;&amp;#x4F9D;&amp;#x8CF4;&amp;#x53CD;&amp;#x8F49;&amp;#x7BC4;&amp;#x4F8B;&amp;#x4E00;&quot; title=&quot;&amp;#x4F9D;&amp;#x8CF4;&amp;#x53CD;&amp;#x8F49;&amp;#x7BC4;&amp;#x4F8B;&amp;#x4E00;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;那麼，我們有可能改變這樣的依賴關係嗎？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E9%82%A3%E9%BA%BC%EF%BC%8C%E6%88%91%E5%80%91%E6%9C%89%E5%8F%AF%E8%83%BD%E6%94%B9%E8%AE%8A%E9%80%99%E6%A8%A3%E7%9A%84%E4%BE%9D%E8%B3%B4%E9%97%9C%E4%BF%82%E5%97%8E%EF%BC%9F&quot; aria-label=&quot;那麼，我們有可能改變這樣的依賴關係嗎？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;那麼，我們有可能改變這樣的依賴關係嗎？&lt;/h2&gt;
&lt;p&gt;有的，藉由&lt;strong&gt;定義一個彼此溝通合作的介面&lt;/strong&gt;，我們可以某種形式地反轉它。&lt;/p&gt;
&lt;p&gt;在 C 語言裡面，其實定義了 FILE type 的指標，必須要實作五個函數 open, close, read, write, seek。只要有實作五個函數，我們使用 fprintf，就可以使用這個指標作為輸出裝置。&lt;/p&gt;
&lt;p&gt;終端機實作了這五個函數，作業系統在串接硬碟時也實作了這五個函數，讓我們可以不論是要輸出到終端機，還是檔案，都可以不用修改原本的程式碼。&lt;/p&gt;
&lt;p&gt;舉個實例是這樣：&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;c&quot;&gt;&lt;pre class=&quot;language-c&quot;&gt;&lt;code class=&quot;language-c&quot;&gt;&lt;span class=&quot;token macro property&quot;&gt;&lt;span class=&quot;token directive-hash&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;token directive keyword&quot;&gt;include&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;lt;stdio.h&gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// 這邊都不用改&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;printHelloWorld&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;FILE &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;out&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;fprintf&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;out&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Hello World&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// 想輸出到終端機&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;printHelloWorld&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;stdout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// 想輸出到檔案&lt;/span&gt;
  FILE &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;filePointer &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;printHellowWorld&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;filePointer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token comment&quot;&gt;// 想輸出到其他裝置&lt;/span&gt;
  FILE &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt;deviceFilePointer &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;printHellowWorld&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;deviceFilePointer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;如此一來，我們已經改變了依賴關係，這隻程式實際上不再依賴裝置本身，而是依賴&lt;strong&gt;介面&lt;/strong&gt;，而&lt;strong&gt;裝置也依賴介面&lt;/strong&gt;。也就是說，兩隻程式的關係變成這樣：&lt;/p&gt;
&lt;figure style=&quot;max-width: 600px&quot;&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/6952e6f5cf3318a0861fe2be58038e8d/5819f/di-2.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 27.083333333333332%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAAAsSAAALEgHS3X78AAAA+ElEQVQY01WQW4qEMBBF7VW2C+iFjczsxC8/FEHxASo+8S2KimgSqqtkOswIgVDee3ISJQxDsG0bLMticRxDnudfyu+Xpulz33cwTVMYhsFpT7PP/7IsteM4QNd15vs+DMMACgIIAlmWsXmeoSgKCUySRF2WBfBQEUUR37YN8FD1L/A8T8Acwz10XQdK0zQwTROM48g45wT+xuyDCmj2chwHcIl1XTnB0eb1AWL2hzFGfYZ96PselLZt/wHrupaGGFCDIADXdQXCbkO8sjTErCaEuLsEpEXD++5YZtd1QVVVEojzp+d5tyE+x22IVvINMauRIXXJjtYbbascxyhWljcAAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/6952e6f5cf3318a0861fe2be58038e8d/8ac56/di-2.webp 240w,
/static/6952e6f5cf3318a0861fe2be58038e8d/d3be9/di-2.webp 480w,
/static/6952e6f5cf3318a0861fe2be58038e8d/e46b2/di-2.webp 960w,
/static/6952e6f5cf3318a0861fe2be58038e8d/20e4c/di-2.webp 1042w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/6952e6f5cf3318a0861fe2be58038e8d/8ff5a/di-2.png 240w,
/static/6952e6f5cf3318a0861fe2be58038e8d/e85cb/di-2.png 480w,
/static/6952e6f5cf3318a0861fe2be58038e8d/d9199/di-2.png 960w,
/static/6952e6f5cf3318a0861fe2be58038e8d/5819f/di-2.png 1042w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/6952e6f5cf3318a0861fe2be58038e8d/d9199/di-2.png&quot; alt=&quot;&amp;#x4F9D;&amp;#x8CF4;&amp;#x53CD;&amp;#x8F49;&amp;#x7BC4;&amp;#x4F8B;&amp;#x4E8C;&quot; title=&quot;&amp;#x4F9D;&amp;#x8CF4;&amp;#x53CD;&amp;#x8F49;&amp;#x7BC4;&amp;#x4F8B;&amp;#x4E8C;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;p&gt;事實上，依賴關係並不是直接反轉過來，而是兩端依賴一個共用的介面。有了介面之後，我們可以讓兩端可以在不修改內部邏輯的前提下，完成不同的任務。&lt;/p&gt;
&lt;p&gt;這樣會方便很多，左邊我們可以改成輸出病例、銀行交易紀錄，右邊可以改成終端機、硬碟、磁帶…。&lt;/p&gt;
&lt;figure style=&quot;max-width: 600px&quot;&gt;
	&lt;span class=&quot;gatsby-resp-image-wrapper&quot; style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; &quot;&gt;
      &lt;a class=&quot;gatsby-resp-image-link&quot; href=&quot;/static/d9398a889ba8d3b64a173e04044dae1d/5819f/di-3.png&quot; style=&quot;display: block&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;
    &lt;span class=&quot;gatsby-resp-image-background-image&quot; style=&quot;padding-bottom: 71.25%; position: relative; bottom: 0; left: 0; background-image: url(&amp;apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAAAsSAAALEgHS3X78AAACn0lEQVQ4y3VUy04iURBtECay0Z/wG/yOWSlOMsaFGxdOZq9f4EY2JK7UGfkBNi5M1AQjj+AjBIWAyrublwrKQ+mGrjmnh56YId7khtv3Vp06VacKpVAoSDQalbOzM6NcLouqqvsKlog4r6+vlf9XJBKx3niuVCr77+/vEo/HjWKxKI1GQ3hpAtTM5XL66+urlEqlXzYgAk0AHh8f/wOE7e/BYCDw16vVqglAU6nVatJqteT5+dkYDoeCSAewdfr9/ik4Ktls1pFMJpWrqyslnU47eLezs+MaAwboQ9/Hx0fhVoAszWaTdA1d16Ver+/SeGNjw618sjY3N6032O4RkL7EsADz+bwXD9yL2MtIfR62bifW/f29O5VKzaK2Mw8PDzOZTGYW9i6PxzMFGxfu5mG/DIaLmqZ58e1VYKQiHfXi4qJ0eXnZQU23mTIZgP1XGOu4b8disfbT05PBuzFRB87bKFn39PS0dHt7q+JdtVJmHQEk/X6fv6yhY6zoarfblbu7O0F0eXt7k/Pz81U7dXREADWlKJbC7XZbKIoJFiajfxSFKR0eHv5MJBICUYadTmdIh2Aw+IMlISBsA4ZhWKLA30QdTTK0DoigswXwvWunjPqt3NzcEHDw8vIyICBSX7EZgsweAelLDIhiUnovDtwLePiOqBRlmg4A+Ya0rJTIngsgS2O8aQpIUeC3AL+/omAatHA4rIVCoTJq1oPBts0ABnPY6wBcA/Aagq9D+Tn7Hdn40Bl9sC4DUANLjYUVSM7aSa/X42+AxltbW5/2oc/n+zIevYBpmsKRZQ9yQBSOCw7c+mg04uPBmJ0To+iAwi72HoK6wJC95/gwevak6BTFqiEZgjZrY7AtOPD2LB8dHU2wOzk5mfhzoC8xuP8AVFvEI3yFOOgAAAAASUVORK5CYII=&amp;apos;); background-size: cover; display: block;&quot;&gt;&lt;/span&gt;
  &lt;picture&gt;
        &lt;source srcset=&quot;/static/d9398a889ba8d3b64a173e04044dae1d/8ac56/di-3.webp 240w,
/static/d9398a889ba8d3b64a173e04044dae1d/d3be9/di-3.webp 480w,
/static/d9398a889ba8d3b64a173e04044dae1d/e46b2/di-3.webp 960w,
/static/d9398a889ba8d3b64a173e04044dae1d/20e4c/di-3.webp 1042w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/webp&quot;&gt;
        &lt;source srcset=&quot;/static/d9398a889ba8d3b64a173e04044dae1d/8ff5a/di-3.png 240w,
/static/d9398a889ba8d3b64a173e04044dae1d/e85cb/di-3.png 480w,
/static/d9398a889ba8d3b64a173e04044dae1d/d9199/di-3.png 960w,
/static/d9398a889ba8d3b64a173e04044dae1d/5819f/di-3.png 1042w&quot; sizes=&quot;(max-width: 960px) 100vw, 960px&quot; type=&quot;image/png&quot;&gt;
        &lt;img class=&quot;gatsby-resp-image-image&quot; src=&quot;/static/d9398a889ba8d3b64a173e04044dae1d/d9199/di-3.png&quot; alt=&quot;&amp;#x4F9D;&amp;#x8CF4;&amp;#x53CD;&amp;#x8F49;&amp;#x7BC4;&amp;#x4F8B;&amp;#x4E09;&quot; title=&quot;&amp;#x4F9D;&amp;#x8CF4;&amp;#x53CD;&amp;#x8F49;&amp;#x7BC4;&amp;#x4F8B;&amp;#x4E09;&quot; loading=&quot;lazy&quot; style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;&gt;
      &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
&lt;/figure&gt;
&lt;h2 id=&quot;小小總結&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E5%B0%8F%E5%B0%8F%E7%B8%BD%E7%B5%90&quot; aria-label=&quot;小小總結 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;小小總結&lt;/h2&gt;
&lt;figure&gt;
	&lt;blockquote&gt;
		&lt;p&gt;所謂的依賴反轉，就是藉由定義一個溝通的介面，讓兩端的程式碼可以互相合作，以達成不同程式目的，並讓兩端的程式碼不必為了另外一端而做內部修改。&lt;/p&gt;
    兩端都可以像插件一樣，可以抽換整個模組以達成新的目的，進而達到降低維護成本的目的。
	&lt;/blockquote&gt;
&lt;/figure&gt;
&lt;hr&gt;
&lt;h3 id=&quot;運用-dependency-inversion-有什麼缺點嗎？&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#%E9%81%8B%E7%94%A8-dependency-inversion-%E6%9C%89%E4%BB%80%E9%BA%BC%E7%BC%BA%E9%BB%9E%E5%97%8E%EF%BC%9F&quot; aria-label=&quot;運用 dependency inversion 有什麼缺點嗎？ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;運用 Dependency Inversion 有什麼缺點嗎？&lt;/h3&gt;
&lt;p&gt;假設我們今天定義出一個很棒的介面，左右兩端各有 10 支程式依賴這個介面，完成 100 個不同的任務。我們用 10+10 的時間完成了原本 100 時間才能完成的任務，聽起來非常棒。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;但，如果介面改了呢？&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;沒錯，就左右兩邊加起來 20 支程式都要改。&lt;/p&gt;
&lt;p&gt;商業世界變動快速，我們一定都遇過，業主需求改變、PM 需求改變，老闆今天心情好想加個功能…。
各種因素都有可能造成我們原本定義好的介面必須被改變，而這牽一髮動全身。如果原本每一種 case 都分開寫，還有可能不需要改動到 20 支程式。&lt;/p&gt;
&lt;p&gt;所以，如何定義好的介面，讓商業邏輯不會動到它，最有效減少程式碼維護的成本，永遠都是身為一名工程師的修煉。&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;最後是我個人大推 &lt;a href=&quot;https://bit.ly/clean-architecture-kingstone&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener noreferrer&quot;&gt;Clean Architecture&lt;/a&gt; 這本書，讓我們用更抽象化的層級思考所寫的程式，那些結構的差異，如何影響我們的開發經驗。以及如何降低維護程式碼的成本，擁有更好的生活。&lt;/p&gt;</content:encoded></item></channel></rss>