<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Zero to Expert]]></title><description><![CDATA[Learning Software Engineering from zero to expert]]></description><link>https://www.zerotoexpert.blog</link><image><url>https://substackcdn.com/image/fetch/$s_!2hjI!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcbf83b9-24f2-4bda-ace7-ea2ba9f53b1d_1024x1024.png</url><title>Zero to Expert</title><link>https://www.zerotoexpert.blog</link></image><generator>Substack</generator><lastBuildDate>Thu, 30 Apr 2026 14:30:48 GMT</lastBuildDate><atom:link href="https://www.zerotoexpert.blog/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Gwonsoo Lee]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[zerotoexpert@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[zerotoexpert@substack.com]]></itunes:email><itunes:name><![CDATA[Gwonsoo Lee]]></itunes:name></itunes:owner><itunes:author><![CDATA[Gwonsoo Lee]]></itunes:author><googleplay:owner><![CDATA[zerotoexpert@substack.com]]></googleplay:owner><googleplay:email><![CDATA[zerotoexpert@substack.com]]></googleplay:email><googleplay:author><![CDATA[Gwonsoo Lee]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[HTTP/2 Troubleshooting with Envoy]]></title><description><![CDATA[Deep dive in the outbound queue]]></description><link>https://www.zerotoexpert.blog/p/http2-troubleshooting-with-envoy</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/http2-troubleshooting-with-envoy</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Wed, 26 Mar 2025 21:52:12 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcbf83b9-24f2-4bda-ace7-ea2ba9f53b1d_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>Introduction</h1><p>While HTTP/2 offers significant improvements over HTTP/1.1&#8212;such as multiplexing, header compression, and persistent connections&#8212;it also introduces new layers of complexity. Debugging real-world issues involving HTTP/2 can be pretty challenging, especially when working with proxies like Envoy that handle low-level protocol details transparently. </p><p>We also use HTTP/2 for our services to take advantage of reusable connections. This can be easily achieved using <a href="https://github.com/istio/istio">Istio,</a>&nbsp;which is based on the&nbsp;<a href="https://github.com/envoyproxy/envoy">Envoy</a>&nbsp;and supports high-performance traffic handling. However, sometimes, it is tough to debug with the Envoy because it is too complicated and challenging to know/understand all the options it provides.</p><h1>Situation</h1><p>One day, we were told the client could not send the large file. When we tried manually, it got the following error: &#8220;upstream connect error or disconnect/reset before headers. reset reason: connection termination&#8221;. It was curious because the endpoint was okay, and the network metric seemed fine. One weird thing was that we couldn&#8217;t send the file only with the specific size limit, but we never set this limit. So, we needed to dig deeper into this situation.</p><ol><li><p>Timeout: Sometimes, TCP or request timeout can be the reason for sending a large payload. Sending large payloads takes some time, and it could exceed the timeout. We calculated the response time to check the timeout issue, but it was not over the timeout we had set.</p></li><li><p>TCP window size full: HTTP/2 utilizes one TCP connection with multiple streams. Sometimes, it is possible that the connection becomes really busy, and TCP cannot receive more packets. To check this, we dumped the TCP connection and checked the TCP window size. Unfortunately, our TCP window size was large enough to receive more packets.</p></li><li><p>HTTP/2 per connection buffer limit size: We can set the buffer limit size of each cluster connection in Envoy, but we never set the stream buffer size(the default is 1MB). If the application could not read the data faster, this might be the limitation. So, we tried to increase the <code>per_connection_buffer_limit_bytes</code> value but had no effect.</p></li><li><p>Check the Envoy debug log: We checked the Envoy debugging log to find out what happened when we sent the large file. We found many &#8220;error sending frames: Too many frames in the outbound queue.&#8221; error messages in the log. <strong>There was an </strong><code>max_outbound_frames</code><strong> option; the connection would be terminated if the max outbound frame count exceeded this limit. I mean, TCP connection, not the stream. </strong>When we changed the <code>max_outbound_frames</code> value, it worked well.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5xiI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe2bc2d0-cdb0-4222-b8a2-87e79dc264ca_3527x926.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5xiI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe2bc2d0-cdb0-4222-b8a2-87e79dc264ca_3527x926.png 424w, https://substackcdn.com/image/fetch/$s_!5xiI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe2bc2d0-cdb0-4222-b8a2-87e79dc264ca_3527x926.png 848w, https://substackcdn.com/image/fetch/$s_!5xiI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe2bc2d0-cdb0-4222-b8a2-87e79dc264ca_3527x926.png 1272w, https://substackcdn.com/image/fetch/$s_!5xiI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe2bc2d0-cdb0-4222-b8a2-87e79dc264ca_3527x926.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5xiI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe2bc2d0-cdb0-4222-b8a2-87e79dc264ca_3527x926.png" width="724" height="189.95054945054946" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fe2bc2d0-cdb0-4222-b8a2-87e79dc264ca_3527x926.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:382,&quot;width&quot;:1456,&quot;resizeWidth&quot;:724,&quot;bytes&quot;:471004,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://www.zerotoexpert.blog/i/159939704?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe2bc2d0-cdb0-4222-b8a2-87e79dc264ca_3527x926.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5xiI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe2bc2d0-cdb0-4222-b8a2-87e79dc264ca_3527x926.png 424w, https://substackcdn.com/image/fetch/$s_!5xiI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe2bc2d0-cdb0-4222-b8a2-87e79dc264ca_3527x926.png 848w, https://substackcdn.com/image/fetch/$s_!5xiI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe2bc2d0-cdb0-4222-b8a2-87e79dc264ca_3527x926.png 1272w, https://substackcdn.com/image/fetch/$s_!5xiI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe2bc2d0-cdb0-4222-b8a2-87e79dc264ca_3527x926.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><p></p><h2>Why did Envoy adopt the max_outbound_frames?</h2><p>While searching for the history, I found the following security issue in the Envoy Github.</p><ul><li><p>https://github.com/envoyproxy/envoy/security/advisories/GHSA-hm8q-x6qm-xxvw</p></li><li><p>https://github.com/envoyproxy/envoy/security/advisories/GHSA-q24r-4w7h-qv3p</p></li><li><p>https://github.com/envoyproxy/envoy/security/advisories/GHSA-5m79-fj88-wc5m</p></li><li><p>https://github.com/envoyproxy/envoy/security/advisories/GHSA-jhv4-f7mr-xx76</p></li></ul><p></p><p>The max_outbound_frames option was adopted in 2019 when there was a ping flood issue with HTTP/2. However, there was another similar issue in 2023. Even though this was not the main reason for adopting the option, we can find why it should terminate the whole connection, not the stream, here.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yCxk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe38c9f4b-8077-429e-bc8b-bb5167e287c9_2012x1401.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yCxk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe38c9f4b-8077-429e-bc8b-bb5167e287c9_2012x1401.png 424w, https://substackcdn.com/image/fetch/$s_!yCxk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe38c9f4b-8077-429e-bc8b-bb5167e287c9_2012x1401.png 848w, https://substackcdn.com/image/fetch/$s_!yCxk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe38c9f4b-8077-429e-bc8b-bb5167e287c9_2012x1401.png 1272w, https://substackcdn.com/image/fetch/$s_!yCxk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe38c9f4b-8077-429e-bc8b-bb5167e287c9_2012x1401.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yCxk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe38c9f4b-8077-429e-bc8b-bb5167e287c9_2012x1401.png" width="1456" height="1014" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e38c9f4b-8077-429e-bc8b-bb5167e287c9_2012x1401.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1014,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:319704,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.zerotoexpert.blog/i/159939704?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe38c9f4b-8077-429e-bc8b-bb5167e287c9_2012x1401.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yCxk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe38c9f4b-8077-429e-bc8b-bb5167e287c9_2012x1401.png 424w, https://substackcdn.com/image/fetch/$s_!yCxk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe38c9f4b-8077-429e-bc8b-bb5167e287c9_2012x1401.png 848w, https://substackcdn.com/image/fetch/$s_!yCxk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe38c9f4b-8077-429e-bc8b-bb5167e287c9_2012x1401.png 1272w, https://substackcdn.com/image/fetch/$s_!yCxk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe38c9f4b-8077-429e-bc8b-bb5167e287c9_2012x1401.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">https://github.com/envoyproxy/envoy/security/advisories/GHSA-jhv4-f7mr-xx76</figcaption></figure></div><p>There was a DoS Vulnerability related to the Rapid Reset in HTTP/2. Simply put, it was the DoS attack by sending many requests using stream with RST_STREAM frames. </p><p>RST_STREAM is used to close the stream logically within the TCP. Basically, most proxy has the default max concurrent streams per TCP connection, so many simultaneous requests would create many TCP connections. This can be detected quickly, and scale-out might mitigate the issue. </p><p>However, because of the RST_STREAM frame, the server closes the stream every time it gets the header. However, the server should create the resource to handle the header and route to other destinations if used in the proxy. It can cause a resource shortage because it consumes the CPU or network. To make matters worse, it is not easy to detect because it is proceeded within a single TCP connection.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nYZv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ff29ef7-e83b-4b5d-8c34-06f39cdb749e_1700x873.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nYZv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ff29ef7-e83b-4b5d-8c34-06f39cdb749e_1700x873.png 424w, https://substackcdn.com/image/fetch/$s_!nYZv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ff29ef7-e83b-4b5d-8c34-06f39cdb749e_1700x873.png 848w, https://substackcdn.com/image/fetch/$s_!nYZv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ff29ef7-e83b-4b5d-8c34-06f39cdb749e_1700x873.png 1272w, https://substackcdn.com/image/fetch/$s_!nYZv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ff29ef7-e83b-4b5d-8c34-06f39cdb749e_1700x873.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nYZv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ff29ef7-e83b-4b5d-8c34-06f39cdb749e_1700x873.png" width="1456" height="748" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0ff29ef7-e83b-4b5d-8c34-06f39cdb749e_1700x873.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:748,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;https://storage.googleapis.com/gweb-cloudblog-publish/images/2023_worlds_largest_rapid_reset_diagram.max-1700x1700.png&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="https://storage.googleapis.com/gweb-cloudblog-publish/images/2023_worlds_largest_rapid_reset_diagram.max-1700x1700.png" title="https://storage.googleapis.com/gweb-cloudblog-publish/images/2023_worlds_largest_rapid_reset_diagram.max-1700x1700.png" srcset="https://substackcdn.com/image/fetch/$s_!nYZv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ff29ef7-e83b-4b5d-8c34-06f39cdb749e_1700x873.png 424w, https://substackcdn.com/image/fetch/$s_!nYZv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ff29ef7-e83b-4b5d-8c34-06f39cdb749e_1700x873.png 848w, https://substackcdn.com/image/fetch/$s_!nYZv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ff29ef7-e83b-4b5d-8c34-06f39cdb749e_1700x873.png 1272w, https://substackcdn.com/image/fetch/$s_!nYZv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0ff29ef7-e83b-4b5d-8c34-06f39cdb749e_1700x873.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption">https://cloud.google.com/blog/products/identity-security/how-it-works-the-novel-http2-rapid-reset-ddos-attack</figcaption></figure></div><p>The Google blog said we should close the TCP connection to mitigate this issue. This will prevent the malicious user from using all the server resources. Even though trying again with a new TCP connection is possible, it would be closed every time it tries. </p><p></p><p>You can find this by checking the TCP dump file. I reproduced the traffic to test this option. I made a script to regularly send the traffic with a small payload. The server will wait 30 seconds before sending the response, which means it is unnecessary to close the stream before sending the large file. Then, I sent a massive payload with the HTTP/2 protocol. </p><ul><li><p>Server: listening port 8000</p></li><li><p>Envoy: Listening port 10000 and proxy all requests to server:8000</p></li></ul><p>Here is a sample of the TCP stream. As you can see, stream 5 sent the request, and it did not get a response. (There was no 200 OK packet.) However, when I sent the heavy request with a 100MB payload, the whole TCP connection was finished because of the envoy.  The FIN packet sender was the Envoy!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nuuG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6d395e9-7b6d-47e6-abb8-2db85eaf4ee2_2867x874.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nuuG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6d395e9-7b6d-47e6-abb8-2db85eaf4ee2_2867x874.png 424w, https://substackcdn.com/image/fetch/$s_!nuuG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6d395e9-7b6d-47e6-abb8-2db85eaf4ee2_2867x874.png 848w, https://substackcdn.com/image/fetch/$s_!nuuG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6d395e9-7b6d-47e6-abb8-2db85eaf4ee2_2867x874.png 1272w, https://substackcdn.com/image/fetch/$s_!nuuG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6d395e9-7b6d-47e6-abb8-2db85eaf4ee2_2867x874.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nuuG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6d395e9-7b6d-47e6-abb8-2db85eaf4ee2_2867x874.png" width="1456" height="444" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e6d395e9-7b6d-47e6-abb8-2db85eaf4ee2_2867x874.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:444,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:445257,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://www.zerotoexpert.blog/i/159939704?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6d395e9-7b6d-47e6-abb8-2db85eaf4ee2_2867x874.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nuuG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6d395e9-7b6d-47e6-abb8-2db85eaf4ee2_2867x874.png 424w, https://substackcdn.com/image/fetch/$s_!nuuG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6d395e9-7b6d-47e6-abb8-2db85eaf4ee2_2867x874.png 848w, https://substackcdn.com/image/fetch/$s_!nuuG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6d395e9-7b6d-47e6-abb8-2db85eaf4ee2_2867x874.png 1272w, https://substackcdn.com/image/fetch/$s_!nuuG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6d395e9-7b6d-47e6-abb8-2db85eaf4ee2_2867x874.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h1>Why was the outbound queue increased?</h1><p>The Envoy provides the&nbsp;<a href="https://www.envoyproxy.io/docs/envoy/latest/api-v3/extensions/filters/http/buffer/v3/buffer.proto#extension-envoy-filters-http-buffer">HTTP Buffer filter to limit the request size</a>. We set this filter to prevent users from sending too large files, which might affect network performance. This is also useful when the upstream cannot read the stream data.</p><p>If this filter is enabled, when the Envoy receives the frame, it holds the data inside the frame and does not send it upstream. When it gets all the payload, it passes the data upstream with a content-length header(if missing). At this moment, the nghttp2 library splits all the data into multiple frames to meet the requirements for the HTTP/2 protocol.</p><p>The HTTP/2 frame size is 16KB by default. So, nghttp2 will break the payload down to a 16KB chunk and send it as one frame. When the frame is ready, Envoy adds it to outbound_queue until the frame is well received. </p><p><strong>However, splitting frames is way faster than sending frames upstream. This caused the outbound_queue to overflow.</strong></p><p></p><h1>Takeaways</h1><ul><li><p>We should check the max_outbound_frames value when the buffer filter is enabled. Buffer filtering can be useful when you want to buffer the request inside the Envoy, but this can cause unexpected TCP termination.</p></li><li><p>We should set the maximum number of concurrent streams in a single TCP connection to mitigate the flooding issue. Otherwise, a single TCP termination will cause bulk stream resets.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[Leetcode Weekly Contest 437]]></title><description><![CDATA[Leetcode Weekly Contest 437 with solution]]></description><link>https://www.zerotoexpert.blog/p/leetcode-weekly-contest-437</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/leetcode-weekly-contest-437</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sun, 16 Feb 2025 09:05:44 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99c48acd-da9b-46b0-a422-8e176f1658bb_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3>Problem 1: <a href="https://leetcode.com/problems/find-special-substring-of-length-k/description/">Find a Special Substring of Length K</a></h3><p>In this problem, we should find the substring with a fixed length that meets the following conditions.</p><ul><li><p>The substring should use only 1 character.</p></li><li><p>The character placed right before and after the substring must not be the same as the character in the substring. It means that if there is a substring whose range is [l,r], then s[l-1] and s[r+1] must not be the character of s[l].</p></li></ul><p>This is very easy because the length of the input string is really short. You can generate all possible substrings of length K and check if it is made with only 1 character. I used sorting to check this. After that, check if the same character exists before and after the substring. </p><pre><code>class Solution {
public:
    bool hasSpecialSubstring(string s, int k) {
        for (int i = 0; i &lt; s.size()-k+1; ++i) {
            string sub = s.substr(i, k);
            sort(sub.begin(), sub.end());
            if (sub[0] == sub.back() &amp;&amp; (i-1 &lt; 0 || s[i-1] != sub[0]) &amp;&amp;  (i + k &gt;= s.size() || s[i+k] != sub[0])) return true;
        }
        return false;
    }
};</code></pre><div><hr></div><h3>Problem 2: <a href="https://leetcode.com/problems/eat-pizzas/description/">Eat Pizzas!</a></h3><p>We should find the maximum weight we can get after eating all the pizzas. No matter how we eat the pizza daily, we only get the maximum or the second maximum based on the day's index. </p><p>This problem is easy if you find the greedy solution where you can greedily choose the maximum on the odd day and the second largest on the even days. However you should ensure that this algorithm really works in this problem.</p><p>Here&#8217;s why the greedy algorithm works.</p><ul><li><p>Let&#8217;s say there are piazzas like [1,2,3,4,5,6,7,8,9,10,11,12] (sorted order).</p></li><li><p>On the first day, we can choose a maximum of 12. (We should eat the three lightest pizzas together.) Then we only have [4,5,6,7,8,9,10,11]</p></li><li><p>On the second day, we choose the second largest one, 10. Then, we should choose 11 to make 10 the second largest. So, we only have [6,7,8,9].</p></li><li><p>On the third day, we gained 9 because it was the maximum weight. </p><ul><li><p>However, if we choose [4,5,9,10] to achieve weight 9, we can achieve 11 on the third day.</p></li><li><p>It means that If there are three values [X, Y, Z] where X &lt;= Y &lt;= Z, then we can choose (X, Y) or (X, Z).</p><ul><li><p>If we choose Y on the even-numbered day, then it will be (X, Y)</p></li><li><p>Otherwise, (X, Z).</p></li></ul></li><li><p>X + Z is always larger than X + Y. Therefore, to get the maximum number, we should choose the odd-numbered day first.</p></li></ul></li></ul><p>So, we can choose the largest (total days + 1 / 2) weights first for the odd-numbered day, and then the second largest one for (total days / 2) times.</p><pre><code>class Solution {
public:
    long long maxWeight(vector&lt;int&gt;&amp; pizzas) {
        const int n = (int)pizzas.size();
        sort(pizzas.rbegin(), pizzas.rend());
        int days = n / 4;
        int idx = 0;
        long long sum = 0LL;
        for (int i = 0; i &lt; (days+1) / 2; ++i) {
            sum += pizzas[idx++];
        }
        
        for (int i = 0; i &lt; days / 2; ++i) {
            sum += pizzas[++idx];
            ++idx;
        }
        return sum;
    }
};</code></pre><div><hr></div><h3>Problem 3: <a href="https://leetcode.com/problems/select-k-disjoint-special-substrings/description/">Select K Disjoint Special Substrings</a></h3><p>In this problem, one character should be in only one substring. If we choose the substring from the index [l, r], every character between them should not exist outside the range.</p><p>Fortunately, we have a maximum of 26 characters, so we can check all substrings that start with every character.</p><ul><li><p>Get the start and end position of every character.</p></li><li><p>Sort the intervals based on the start.</p></li><li><p>Iterate the character from the one that appears at the latest. This is for the number of possible disjoint substrings after the current index.</p><ul><li><p>For example, if the last index of the substring starting with index i is j, then we can get (dp[j+1] + 1) substrings. To get dp[j+1], we should calculate it before visiting the current index. So, we should iterate from the last.</p></li></ul></li><li><p>Every character has its start and end index. However, the end index should be changed if another character has a more extensive index than the end index. Also, if there is a character that should start before the current start index, then we can skip the current character because it will be checked later.</p><ul><li><p>For example, if the substring is &#8220;BABEAE&#8221; and the current character is A, the start index is 1, and the end index is 4.</p></li><li><p>However, E is between [1,4] and appears again after the end index of A. So, we should extend the end index to 5.</p></li><li><p>In this case, the character B exists between [1,4] and B should start before index 1. So, we have to skip to get the answer with a substring that begins with A because it is impossible.</p></li></ul></li></ul><p></p><p>This algorithm takes only O(26 * N) times because, for every character, we only iterate the input string at once.</p><pre><code>class Solution {
public:
    bool maxSubstringLength(string s, int k) {
        vector&lt;pair&lt;int,int&gt;&gt; intervals(26, {-1, -1});
        const int n = (int)s.size();
        for (int i = 0; i &lt; n; ++i) {
            int j = s[i]-'a';
            intervals[j].second = i;
            if (intervals[j].first == -1) intervals[j].first = i;
        }
        vector&lt;pair&lt;int,int&gt;&gt; arr;
        for (int i = 0; i &lt; intervals.size(); ++i) {
            if (intervals[i].first != -1) arr.push_back(intervals[i]);
        }
        sort(arr.begin(), arr.end());
        vector&lt;int&gt; dp(arr.size()+1, 0);
        int ans = 0;
        for (int i = arr.size()-1; i &gt;= 0; --i) {
            dp[i] = max(dp[i], dp[i+1]);
            int l = arr[i].first, r = arr[i].second;            
            int end = r;
            bool flag = true;
            for (int j = l+1; j &lt; r; ++j) {
                int ns = intervals[s[j]-'a'].first, ne = intervals[s[j]-'a'].second;
                if (ns &lt; l) {
                    flag = false;
                    break;
                }
                r = max(r, ne);
            }
            if (flag &amp;&amp; r - l + 1 &lt; s.size()) {
                int idx = lower_bound(arr.begin(), arr.end(), make_pair(r, r)) - arr.begin();
                dp[i] = max(dp[i], dp[idx] + 1);
            }
            ans = max(ans, dp[i]);
        }
        return ans &gt;= k;
    }
};</code></pre><div><hr></div><h3>Problem 4: <a href="https://leetcode.com/problems/length-of-longest-v-shaped-diagonal-segment/description/">Length of Longest V-Shaped Diagonal Segment</a></h3><p>In this problem, we should find the most extended length that can be made with a 1,2,0,2,0 sequence. Unlike the typical DFS problem, we should move in a diagonal direction. Also, we can change the direction to one way and at most once. </p><p>The solution is basically the same as for the typical DFS problem. However, before proceeding, we should consider the following two cases.</p><ul><li><p>Choose the same direction. </p></li><li><p>Choose to take a 90-degree clockwise turn. In this case, we should not change the direction before.</p></li><li><p>The value difference between the current and the following positions should be 2 for both cases.</p></li></ul><p>So, for every position (x, y), we can keep track of the direction and the changed times. With this information, we can make all the possible moves. </p><p>However, if the grid size increases, we might visit the same position with the same condition more than once. So, we can use memoization to save the previous result and then return if we visit again. This can be possible because we have at most 500 * 500 * 4 * 2 cases. (500 - m, 500 - n, 4 - direction, 2 - the number of turns)</p><p>We don&#8217;t need to keep track of the previous visit during DFS because we cannot go back because we cannot change the direction 180 degrees. We cannot change the direction twice, so revisiting the same node within the single DFS traverse is impossible.</p><pre><code>class Solution {
public:
    int dx[4] = {1,1,-1,-1};
    int dy[4] = {1,-1,-1,1};
    int dp[501][501][4][2];
    bool pos(int x, int y, int nx, int ny, vector&lt;vector&lt;int&gt;&gt; &amp; grid) {
        return nx &gt;= 0 &amp;&amp; ny &gt;= 0 &amp;&amp; nx &lt; grid.size() &amp;&amp; ny &lt; grid[0].size() &amp;&amp; abs(grid[x][y] - grid[nx][ny]) == 2;
    }

    int dfs(vector&lt;vector&lt;int&gt;&gt; &amp; grid, int x, int y, int d, int changed) {
        if (dp[x][y][d][changed] != -1) return dp[x][y][d][changed];
        // follow the direction
        int ans = 1;
        if (pos(x, y, x + dx[d], y + dy[d], grid)) {
            ans = max(ans, dfs(grid, x + dx[d], y + dy[d], d, changed) + 1);
        }
        // change the direction
        if (changed == 0) {
            int nd = (d + 1) % 4;
            if (pos(x, y, x + dx[nd], y + dy[nd], grid)) {
                ans = max(ans, dfs(grid, x + dx[nd], y + dy[nd], nd, changed+1) + 1);
            }
        }
        return dp[x][y][d][changed] = ans;
    }
    int lenOfVDiagonal(vector&lt;vector&lt;int&gt;&gt;&amp; grid) {
        const int n = (int)grid.size();
        const int m = (int)grid[0].size();
        int ans = 0;
        memset(dp, -1, sizeof(dp));
        for (int i = 0; i &lt; n; ++i) {
            for (int j = 0; j &lt; m; ++j) {
                if (grid[i][j] == 1) {
                    ans = max(ans, 1);
                    for (int k = 0; k &lt; 4; ++k) {
                        int nx = i + dx[k], ny = j + dy[k];
                        if (nx &lt; 0 || ny &lt; 0 || nx &gt;= n || ny &gt;= m || grid[nx][ny] != 2) continue;
                        ans = max(ans, dfs(grid, nx, ny, k, 0) + 1);
                    }
                }
            }
        }
        return ans;
    }
};</code></pre><p></p>]]></content:encoded></item><item><title><![CDATA[Lowest Common Ancestor(LCA) Problems]]></title><description><![CDATA[Lowest Common Ancestor problems & solutions]]></description><link>https://www.zerotoexpert.blog/p/lowest-common-ancestorlca-problems</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/lowest-common-ancestorlca-problems</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Mon, 10 Feb 2025 17:45:00 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcbf83b9-24f2-4bda-ace7-ea2ba9f53b1d_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3>Problem1: <a href="https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/description/">Lowest Common Ancestor of a Binary Search Tree</a></h3><p>In the problem, we should find the common ancestor of p and q. Unlike in typical LCA problems, BST is used here, so we can take advantage of it. </p><ul><li><p>If the current node is larger than p and q, it cannot be the ancestor. The right ancestor will be in the left tree.</p></li><li><p>If the current node is smaller than p and q, the answer should be in the right tree.</p></li><li><p>Otherwise, the current value should be the lowest common ancestor because one might be on the left and the other on the right. (Or the current node can be one of p and q)</p></li></ul><pre><code>class Solution {
public:
    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
        while(true) {
            if(root-&gt;val &lt; p-&gt;val &amp;&amp; root-&gt;val &lt; q-&gt;val) root = root-&gt;right;
            else if (root-&gt;val &gt; p-&gt;val &amp;&amp; root-&gt;val &gt; q-&gt;val) root = root-&gt;left;
            else break;
        }
        return root;
    }
};</code></pre><div><hr></div><h3>Problem2: <a href="https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/description/">Lowest Common Ancestor of a Binary Tree</a></h3><p>Now, we should find the LCA from Binary Tree. This is not the BST, so we cannot decide which child node will contain the answer. It means that we should find the left and right child together.</p><p>The important thing is to determine which case can be the ancestor. Let&#8217;s say we already checked the left and right nodes. </p><ul><li><p>If both the left and right nodes find something, the current node should be the common ancestor. </p></li><li><p>If not, there are two cases.</p><ul><li><p>1) Find p or q, not both.</p></li><li><p>2) Find nothing.</p></li><li><p>In both cases, <strong>the current node may be either p or q</strong>. If so, we can return it. The current node will be the answer if it is the first case. In the second case, the current node will indicate to the parent that it finds p or q.</p></li></ul></li><li><p>If the current node is not p and q, then we can return the found node from the result of the left and right nodes. </p></li></ul><pre><code>class Solution {
public:
    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
        if (root == nullptr) return nullptr;

        TreeNode* left = lowestCommonAncestor(root-&gt;left, p, q);
        TreeNode* right = lowestCommonAncestor(root-&gt;right, p, q);

        if ((left != nullptr &amp;&amp; right != nullptr) || root == p || root == q) {
            return root;
        }

        return left == nullptr ? right : left;
    }
};</code></pre><div><hr></div><h3>Problem3: <a href="https://leetcode.com/problems/lowest-common-ancestor-of-deepest-leaves/description/">Lowest Common Ancestor of Deepest Leaves</a></h3><p>In this problem, we should find the LCA of deepest leaves. If there are more than 1 leaves that have the deepest depth, we should find the LCA for all of them. This is tricky, even though we search with DFS, we cannot know if it is the deepest leaves or not.</p><p>So, when we search the left and right nodes, we should get the deepest depth information as well. If the deepest depth of left tree is larger than that of right tree, then we should return LCA of left tree. It&#8217;s because the right tree must not be the answer. Of course, in this case, we are unsure that the LCA from left tree is the correct answer. There might be another LCA that has deeper depth.</p><ul><li><p>To make the logic work, we should return the empty node&#8217;s depth with -1. This will work because if left node is empty and the right node is not, right node&#8217;s depth is always larger than that of the left node.</p></li></ul><p>If the depth of left and right nodes are equal, then we should return the current node as the LCA. If it is the leaf node, then left and right node depth will be same and the value is -1. In this case, we should return the current depth to let parent know the deepest depth it has.</p><pre><code>class Solution {
public:
    pair&lt;TreeNode*, int&gt; findLCADeepestLeaves(TreeNode* root, int depth) {
        if (root == nullptr) return {nullptr,  -1};

        auto left = findLCADeepestLeaves(root-&gt;left, depth + 1);
        auto right = findLCADeepestLeaves(root-&gt;right, depth + 1);

        if (left.second == right.second) {
            return {root, left.second == -1 ? depth : left.second };
        }
        return left.second &lt; right.second ? right : left;
    }

    TreeNode* lcaDeepestLeaves(TreeNode* root) {
        return findLCADeepestLeaves(root, 0).first;
    }
};</code></pre><div><hr></div><h3>Problem4: <a href="https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-ii/">Lowest Common Ancestor of a Binary Tree II</a></h3><p>This problem is a bit harder one than problem2. It&#8217;s because p or q might not be in the tree. We should return the LCA if and only if we find both of them in the tree.</p><p>Basic logic is the same as the problem2,  but I added the boolean value that indicates returned node is the LCA. If it is false, then the node is just one of p or q, not the LCA.</p><p>If one of the left or right node found the answer, then we can return it. Unless, we should check the current node can be the answer. </p><ul><li><p>If both left node and right node finds the LCA but those are not the answer, then p and q is found from different child. So the LCA of them is the current node.</p></li><li><p>If one of them finds the LCA and the current node is either p or q, then it also means that the current node is LCA.</p></li><li><p>In those two cases, the current node is the answer, so we should return true for the second return value.</p></li></ul><p>Even though the current node is not the LCA, it can be one of p or q. If not, then the current node is useless, so return the non-empty node between left and right. (Both can be null, but it&#8217;s okay)</p><pre><code>class Solution {
public:
    pair&lt;TreeNode*, bool&gt; lowestCommonAncestorHelper(TreeNode* root, TreeNode* p, TreeNode* q) {
        if (!root) return {nullptr, false};

        auto left = lowestCommonAncestorHelper(root-&gt;left, p, q);
        auto right = lowestCommonAncestorHelper(root-&gt;right, p, q);
        if ((left.first != nullptr &amp;&amp; right.first != nullptr) || ((root == p || root == q) &amp;&amp; (left.first != nullptr || right.first != nullptr))) {
            return {root, true};
        }

        if (left.second) return left;
        if (right.second) return right;

        if (root == p || root == q) return {root, false};

        return left.first == nullptr ? right : left;
    }

    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
        auto answer = lowestCommonAncestorHelper(root, p, q);
        return answer.second ? answer.first : nullptr;
    }
};</code></pre><div><hr></div><h3>Problem5: <a href="https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iii/description/">Lowest Common Ancestor of a Binary Tree III</a></h3><p>In this problem, we don&#8217;t know the root and only p and q are provided. However, each node has the parent infromation. So we can find the parent if we keep following the parent node.</p><p>To find the LCA, we can look through all parents of p and q. </p><ul><li><p>Store all parents of p, including p itself until it reach to the root node.</p></li><li><p>Find the LCA by checking if the parent of q exists.</p></li><li><p>If nothing is found, then return nullptr.</p></li></ul><pre><code>class Solution {
public:
    Node* lowestCommonAncestor(Node* p, Node * q) {
        unordered_set&lt;Node*&gt; parents;
        while(p != nullptr) {
            parents.insert(p);
            p = p-&gt;parent;
        }
        while(q != nullptr) {
            if (parents.find(q) != parents.end()) return q;
            q = q-&gt;parent;
        }
        return nullptr;
    }
};</code></pre><p>This problem can be solved without storing the parent information. No matter where p and q is located in the tree, they have each own depth from the root node. If the depth is equal, then we can simply iterate the parent one by one until both get the same parent. </p><p>However, the problem happens when the depth is different. Let&#8217;s seem the following graph. </p><ul><li><p>If p and q moves to each parent at the same speed, then the shorter one will arrive at the root node first. In this case, p is the shorter one and it will iterate A + B times.  q also iterates A + B times. It is the C - A far from the root.</p></li><li><p>p is now starting again from original q position. Then it should iterate C times more to get to the LCA. However, before iterating C, q will arrive at the root node after C - A iteration. p also moves C - A times so it will be A far from the LCA.</p></li><li><p>if q starts from original p postion, both of them should move A times. In conclustion, both p and q moves A + B + C times to get to the LCA node.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wM-H!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc478148a-5bca-4c00-9857-26f8ab470d7b_1174x935.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wM-H!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc478148a-5bca-4c00-9857-26f8ab470d7b_1174x935.png 424w, https://substackcdn.com/image/fetch/$s_!wM-H!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc478148a-5bca-4c00-9857-26f8ab470d7b_1174x935.png 848w, https://substackcdn.com/image/fetch/$s_!wM-H!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc478148a-5bca-4c00-9857-26f8ab470d7b_1174x935.png 1272w, https://substackcdn.com/image/fetch/$s_!wM-H!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc478148a-5bca-4c00-9857-26f8ab470d7b_1174x935.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wM-H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc478148a-5bca-4c00-9857-26f8ab470d7b_1174x935.png" width="1174" height="935" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c478148a-5bca-4c00-9857-26f8ab470d7b_1174x935.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:935,&quot;width&quot;:1174,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:122226,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wM-H!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc478148a-5bca-4c00-9857-26f8ab470d7b_1174x935.png 424w, https://substackcdn.com/image/fetch/$s_!wM-H!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc478148a-5bca-4c00-9857-26f8ab470d7b_1174x935.png 848w, https://substackcdn.com/image/fetch/$s_!wM-H!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc478148a-5bca-4c00-9857-26f8ab470d7b_1174x935.png 1272w, https://substackcdn.com/image/fetch/$s_!wM-H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc478148a-5bca-4c00-9857-26f8ab470d7b_1174x935.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><pre><code>class Solution {
public:
    Node* lowestCommonAncestor(Node* p, Node * q) {
        Node* l = p;
        Node* r = q;
        while(l != r) {
            l = l-&gt;parent == nullptr ? q : l-&gt;parent;
            r = r-&gt;parent == nullptr ? p : r-&gt;parent;
        }
        return l;
    }
};</code></pre><div><hr></div><h3>Problem6: <a href="https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iv/description/">Lowest Common Ancestor of a Binary Tree IV</a></h3><p>In this problem, we should find the LCA of multiple nodes. We can find all LCA one by one, but it will take too long time if array size is big. However, if you try to find the LCA with this method, then you will get one possible optimization idea.</p><p>Let&#8217;s assume that we find the LCA of A and B. (let&#8217;s call it X)  If we want to find LCA of A,B,C, then we can find the LCA of X and C. </p><p>What if C is located in the child tree of X? In this case, we don&#8217;t need to consider C. It means that if we find a node, then we don&#8217;t need to think about the LCA of other nodes that are located in the child tree. So, we just can return the current node as the LCA.</p><p>So, the basic logic is mostly the same as the problem 2. One thing different is that, if the current node is in the list of nodes that we have to find, then we just can return the current node ans the LCA, no matter what result of left or right.</p><pre><code>class Solution {
public:
    TreeNode* lowestCommonAncestorHelper(TreeNode* root, unordered_set&lt;TreeNode*&gt; &amp; s) {
        if (root == nullptr) return nullptr;

        TreeNode* left = lowestCommonAncestorHelper(root-&gt;left, s);
        TreeNode* right = lowestCommonAncestorHelper(root-&gt;right, s);

        if ((left != nullptr &amp;&amp; right != nullptr) || s.find(root) != s.end()) {
            return root;
        }

        return left == nullptr ? right : left;
    }

    TreeNode* lowestCommonAncestor(TreeNode* root, vector&lt;TreeNode*&gt; &amp;nodes) {
        unordered_set&lt;TreeNode*&gt; s;
        for (auto &amp; node: nodes) s.insert(node);

        return lowestCommonAncestorHelper(root, s);
    }
};</code></pre>]]></content:encoded></item><item><title><![CDATA[Optimal Partition of String]]></title><description><![CDATA[Greedy Algorithm, Hash Table.]]></description><link>https://www.zerotoexpert.blog/p/optimal-partition-of-string</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/optimal-partition-of-string</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Mon, 10 Feb 2025 14:05:37 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99c48acd-da9b-46b0-a422-8e176f1658bb_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/optimal-partition-of-string/">Original Link</a></p><h1>Solution</h1><p>In this problem, we should find the minimum possible partitions that can divide the input string into multiple(or single) substring(s). The same character should not be in each substring. </p><p>We should create a substring containing as many characters as possible. Otherwise, we might need more partitions to split the duplicated characters. Thus, a greedy algorithm simply works here.</p><pre><code>class Solution {
public:
    int partitionString(string s) {
        int n = (int)s.size();
        int ans = 1;
        vector&lt;int&gt; cnt(26, 0);
        for (int i = 0; i &lt; n; ++i) {
            if (cnt[s[i]-'a'] == 1) {
                ++ans;
                fill(cnt.begin(), cnt.end(), 0);
            }
            cnt[s[i]-'a']++;
        }
        return ans;
    }
};</code></pre><p></p><h3><strong>Then, why does the greedy algorithm work here?</strong></h3><p>Let&#8217;s say that we get the answer without using a greedy algorithm. There are two partitions: A and B.</p><ul><li><p>A partition can contain more characters in the B partitions. If not, then we already solved it with a greedy algorithm.</p></li><li><p>A partition can contain some characters or all characters in the B partitions. It means that a greedy solution gets the same or fewer partitions. So, the greedy algorithm works here.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[The kth Factor of n]]></title><description><![CDATA[Math, Number Theory]]></description><link>https://www.zerotoexpert.blog/p/the-kth-factor-of-n</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/the-kth-factor-of-n</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Mon, 10 Feb 2025 12:49:42 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99c48acd-da9b-46b0-a422-8e176f1658bb_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/the-kth-factor-of-n/description/">Original Link</a></p><h1>Solution</h1><p>In this problem, we should find all factors that meet n % i == 0. Before getting all possible factors, we are unsure if there is a kth number. The easy solution is to check all possible numbers if n is divisible by that number. The input size is too small, so we can solve this problem with O(N) time complexity.</p><pre><code>class Solution {
public:
    int kthFactor(int n, int k) {
        for (int i = 1; i &lt;= n; ++i) {
            if (n % i == 0) --k;
            if (k == 0) return i;
        }
        return -1;
    }
};</code></pre><p></p><p>However, this solution won&#8217;t pass if the size of N becomes large. To make it more effective, we should consider the divisor's aspect. When a number X can divide the number N, then we know that N/X is also the divisor of N. For example, if we know that 3 is the divisor of 15, 5 is also the divisor of 15 automatically. </p><p>Then, we don&#8217;t need to check all numbers smaller than N. We only need to check until ceil(sqrt(N)). It&#8217;s because that sqrt(N) * sqrt(N) = N. If the previous sqrt(N) is larger, the later sqrt(N) should be smaller. It was already checked before we checked sqrt(N).</p><pre><code>class Solution {
public:
    int kthFactor(int n, int k) {
        vector&lt;int&gt; ans;
        for (int i = 1; i * i &lt;= n; ++i) {
            if (n % i == 0) ans.push_back(i);
            if (n % i == 0 &amp;&amp; i != n / i) ans.push_back(n/i);
        }
        sort(ans.begin(), ans.end());
        k--;
        return ans.size() &gt; k ? ans[k] : -1;
    }
};</code></pre>]]></content:encoded></item><item><title><![CDATA[Number of Possible Sets of Closing Branches]]></title><description><![CDATA[Shortest Path]]></description><link>https://www.zerotoexpert.blog/p/number-of-possible-sets-of-closing</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/number-of-possible-sets-of-closing</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sun, 09 Feb 2025 16:23:04 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99c48acd-da9b-46b0-a422-8e176f1658bb_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/number-of-possible-sets-of-closing-branches/description/">Original Link</a></p><h1>Solution</h1><p>In the problem, we should find all possible ways to close the branches. All the branches that survive must be connected to each other, and the distance between them should be no longer than the maximum distance. </p><p>The maximum input of n is 10, so there are only 1024 states to select the survived branches. Also, we should find all the shortest paths from each branch to the others. It will take N*NlogN times to detect whether the current state is valid. So, it will be O(2^N * N^2logN). This value is really low even with N = 10.</p><p></p><ul><li><p>Iterates all possible ways to select the survived branches.</p></li><li><p>Iterates all survived branches as the starting branch to find the shortest path to other branches. </p></li><li><p>Check if there is any case that one branch cannot connect to the other branch. If there is any, then this cannot be possible.</p></li></ul><pre><code>#include &lt;vector&gt;
#include &lt;unordered_map&gt;
#include &lt;queue&gt;
using namespace std;

class Solution {
public:
    int numberOfSets(int n, int maxDistance, vector&lt;vector&lt;int&gt;&gt;&amp; roads) {
        unordered_map&lt;int, vector&lt;pair&lt;int, int&gt;&gt;&gt; graph;

        // Build adjacency list representation of the graph
        for (const auto&amp; road : roads) {
            int u = road[0], v = road[1], w = road[2];
            graph[u].push_back({v, w});
            graph[v].push_back({u, w});
        }

        int validSets = 1; // At least one valid set (empty set)
        
        // Iterate over all subsets of branches (bitmasking)
        for (int mask = 1; mask &lt; (1 &lt;&lt; n); ++mask) {
            vector&lt;int&gt; openBranches;

            // Extract the branches that are open in this subset
            for (int j = 0; j &lt; n; ++j) {
                if (mask &amp; (1 &lt;&lt; j)) { // Check if branch `j` is included
                    openBranches.push_back(j);
                }
            }

            bool isValid = true;

            // Run Dijkstra's algorithm for each branch in the subset
            for (auto&amp; startNode : openBranches) {
                vector&lt;int&gt; dist(n, -1); // Distance array initialized to -1
                dist[startNode] = 0;

                priority_queue&lt;pair&lt;int, int&gt;&gt; pq;
                pq.push({0, startNode}); // {distance, node}

                while (!pq.empty()) {
                    auto [negDistance, node] = pq.top();
                    pq.pop();
                    int currDistance = -negDistance; // Convert back to positive distance

                    // If this path is not optimal, skip
                    if (dist[node] != -1 &amp;&amp; dist[node] &lt; currDistance) continue;

                    // Relax edges
                    for (auto&amp; [neighbor, weight] : graph[node]) {
                        if (mask &amp; (1 &lt;&lt; neighbor)) { // Only consider nodes in the subset
                            int newDistance = currDistance + weight;
                            if ((dist[neighbor] == -1 || dist[neighbor] &gt; newDistance) &amp;&amp; newDistance &lt;= maxDistance) {
                                dist[neighbor] = newDistance;
                                pq.push({-newDistance, neighbor}); // Push with negative distance for min-heap
                            }
                        }
                    }
                }

                // Check if all selected branches are reachable
                for (auto&amp; branch : openBranches) {
                    if (dist[branch] == -1) {
                        isValid = false;
                        break;
                    }
                }

                if (!isValid) break;
            }

            if (isValid) validSets++; // Count this subset if it's valid
        }

        return validSets;
    }
};
</code></pre><h3><strong>Time Complexity Analysis</strong></h3><ul><li><p><strong>Generating subsets:</strong> O(2^n) (Iterating over all subsets)</p></li><li><p><strong>Dijkstra's Algorithm:</strong> O(nlog&#8289;n) per subset (Priority queue operations)</p></li><li><p><strong>Checking All Subsets:</strong> O(n) in worst case</p></li></ul><p>Thus, the overall complexity is <strong>O(2^n&#8901;n^2&#8901;log n)</strong>, making this approach feasible only for small <code>n</code> (typically n&#8804;20).</p>]]></content:encoded></item><item><title><![CDATA[Leetcode Weekly Contest 436]]></title><description><![CDATA[Solutions for Weekly Contest 436]]></description><link>https://www.zerotoexpert.blog/p/weekly-contest-436</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/weekly-contest-436</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sun, 09 Feb 2025 08:31:26 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99c48acd-da9b-46b0-a422-8e176f1658bb_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3>Problem1: <a href="https://leetcode.com/problems/sort-matrix-by-diagonals/description/">Sort Matrix by Diagonals</a></h3><p>In this problem, we need to sort the diagonals. First, we should sort the numbers of bottom-left matrix in the non-increasing order. To sort the diagonals, we can start the first index of each row. And then we can move row + 1, col + 1 to get all values in the same diagonal. After sorting the values, then reassign the values to the matrix with the same logic.</p><p>For the top-right matrix, we can start the first index of each column except for the first column. First column will be calculated in the bottom-left case. The logic is the same as the bottom-left case.</p><pre><code>class Solution {
public:
    vector&lt;vector&lt;int&gt;&gt; sortMatrix(vector&lt;vector&lt;int&gt;&gt;&amp; grid) {
        int n = grid.size();

        // Sort diagonals in bottom-left (including middle diagonal) in non-increasing order
        for (int i = n - 1; i &gt;= 0; --i) {
            int row = i, col = 0;
            vector&lt;int&gt; diagonal;

            // Extract diagonal elements
            while (row &lt; n &amp;&amp; col &lt; n) {
                diagonal.push_back(grid[row][col]);
                row++, col++;
            }

            // Sort in descending order
            sort(diagonal.rbegin(), diagonal.rend());

            // Put sorted values back into the matrix
            row = i, col = 0;
            for (int val : diagonal) {
                grid[row++][col++] = val;
            }
        }

        // Sort diagonals in top-right in non-decreasing order
        for (int i = 1; i &lt; n; ++i) {
            int row = 0, col = i;
            vector&lt;int&gt; diagonal;

            // Extract diagonal elements
            while (row &lt; n &amp;&amp; col &lt; n) {
                diagonal.push_back(grid[row][col]);
                row++, col++;
            }

            // Sort in ascending order
            sort(diagonal.begin(), diagonal.end());

            // Put sorted values back into the matrix
            row = 0, col = i;
            for (int val : diagonal) {
                grid[row++][col++] = val;
            }
        }

        return grid;
    }
};
</code></pre><h3><strong>Time Complexity Analysis</strong></h3><ul><li><p><strong>Extracting diagonals</strong>: O(n)per diagonal.</p></li><li><p><strong>Sorting diagonals</strong>: O(nlog&#8289;n) per diagonal.</p></li><li><p><strong>Placing elements back</strong>: O(n) per diagonal.</p></li><li><p>There are approximately 2n&#8722;1 diagonals.</p></li></ul><p>Thus, the total complexity is <strong>O(n2log&#8289;n)</strong>.</p><div><hr></div><h3>Problem2: <a href="https://leetcode.com/problems/assign-elements-to-groups-with-constraints/description/">Assign Elements to Groups with Constraints</a></h3><p>In this problem, we should assign the divisible elements to the value in the groups. We cannot check all elements to all values because the number of groups and elements is 10^5. It should be TLE.</p><p>I remove the duplicated elements by choosing only earlier one. Also, I sorted the group values to reduce the search range after getting unique values. I can store the indexes of each value with the hashmap. When I should find the divisible values with the element, find the lower_bound from the distinct value array. This only cost O(logN). </p><p>To reduce the time complexity, I calculated the element value 1, because it will be applied to all groups by default. </p><pre><code>class Solution {
public:
    vector&lt;int&gt; assignElements(vector&lt;int&gt;&amp; groups, vector&lt;int&gt;&amp; elements) {
        unordered_map&lt;int, vector&lt;int&gt;&gt; groupToIndices;
        
        // Store indices of each group size
        for (int i = 0; i &lt; groups.size(); ++i) {
            groupToIndices[groups[i]].push_back(i);
        }

        // Extract unique group sizes and sort them
        vector&lt;int&gt; sortedGroups;
        for (auto &amp;entry : groupToIndices) {
            sortedGroups.push_back(entry.first);
        }
        sort(sortedGroups.begin(), sortedGroups.end());

        // Track the smallest index for each element in elements
        unordered_map&lt;int, int&gt; elementIndex;
        for (int i = elements.size() - 1; i &gt;= 0; --i) {
            elementIndex[elements[i]] = i; // Store the smallest index for each element
        }

        // Map to store the smallest valid element index for each group
        unordered_map&lt;int, int&gt; bestAssignment;
        
        // Iterate over each element and check its multiples in sortedGroups
        for (auto &amp;[element, index] : elementIndex) {
            int multiple = element;
            while (multiple &gt; 1) {
                auto it = lower_bound(sortedGroups.begin(), sortedGroups.end(), multiple);
                if (it == sortedGroups.end()) break; // No more valid groups

                if (*it == multiple &amp;&amp; (bestAssignment.count(multiple) == 0 || bestAssignment[multiple] &gt; index)) {
                    bestAssignment[*it] = index; // Store the smallest index
                }
                multiple += element;
            }
        }

        // Initialize answer array with -1 (default unassigned state)
        vector&lt;int&gt; result(groups.size(), -1);
        
        // Special case: If '1' is present in elements, assign its index to all groups
        if (elementIndex.count(1) &gt; 0) {
            fill(result.begin(), result.end(), elementIndex[1]);
        }

        // Assign best matching element indices to corresponding groups
        for (auto &amp;[groupSize, assignedIndex] : bestAssignment) {
            for (auto &amp;groupIndex : groupToIndices[groupSize]) {
                if (result[groupIndex] == -1 || result[groupIndex] &gt; assignedIndex) {
                    result[groupIndex] = assignedIndex;
                }
            }
        }
        
        return result;
    }
};
</code></pre><h3><strong>Time Complexity Analysis</strong></h3><ul><li><p><strong>Sorting the unique group sizes:</strong> O(Glog&#8289;G)(where G is the number of unique group sizes).</p></li><li><p><strong>Traversing </strong><code>elements</code><strong> and populating </strong><code>els</code><strong>:</strong> O(E)</p></li><li><p><strong>Checking divisibility using a sieve-like approach:</strong> O(Elog&#8289;G).</p></li><li><p><strong>Final assignment process:</strong> O(G).</p></li></ul><p>Thus, the overall complexity is approximately <strong>O(Elog&#8289;G+Glog&#8289;G)</strong>, which is efficient.</p><div><hr></div><h3>Problem3: <a href="https://leetcode.com/problems/count-substrings-divisible-by-last-digit/description/">Count Substrings Divisible By Last Digit</a></h3><p>In this problem, we should find the substring that is divisible by the last digit. The string size is too long, so that we cannot check all substrings within the limited time.</p><p>In this case, we can only find the substring by calculating the remainder.  Let&#8217;s say dp[i] means the number of substrings whose remainder is i in the current index. If we move to the next index, then every substring will become X * 10 + (next value). It means that every remainders should be recalculated by (X * 10 + next value)  % divisor.</p><ul><li><p>For example, if  we divide the substring &#8220;124&#8221; by 3, then the remainder will be 1.</p></li></ul><ul><li><p>If the substring is &#8220;1243&#8221;, which is the 124 * 10 + 3, then the remainder will be (1 * 10 + 3) % 3 == 1. It means that If calculate the next remainder with current value x, then we can find the divisible substring counts with dp[0].</p></li></ul><p>If the current value is the divisor, then we should add dp[0] to answer.</p><pre><code>class Solution {
public:
    long long countSubstrings(string s) {
        long long totalCount = 0; // Stores the total valid substrings count
        
        // Iterate over possible last digits (1 to 9)
        for (int divisor = 1; divisor &lt;= 9; ++divisor) {
            vector&lt;long long&gt; dp(divisor, 0LL); // DP array to track remainders

            // Iterate over the string to form substrings
            for (char c : s) {
                int currentDigit = c - '0'; // Convert char to int
                vector&lt;long long&gt; newDP(divisor, 0LL); // Temporary DP array

                // Update DP table for substrings ending at this digit
                for (int remainder = 0; remainder &lt; divisor; ++remainder) {
                    int newRemainder = (remainder * 10 + currentDigit) % divisor;
                    newDP[newRemainder] += dp[remainder]; // Carry forward counts
                }

                // Count single-digit substrings
                newDP[currentDigit % divisor]++;
                
                // Update DP table
                dp = newDP;

                // If the substring ending here is divisible by its last digit, count it
                if (currentDigit == divisor) {
                    totalCount += dp[0];
                }
            }
        }
        
        return totalCount;
    }
};
</code></pre><h3><strong>Time Complexity Analysis</strong></h3><ul><li><p><strong>Outer Loop:</strong> Iterate over <strong>digits 1 to 9</strong> &#8594; O(9)=O(1) (constant).</p></li><li><p><strong>Inner Loop:</strong> Traverse the string of length n &#8594; O(n).</p></li><li><p><strong>Modular DP Update:</strong> Runs in O(9) time for each character.</p></li></ul><p>Thus, the total complexity is <strong>O(n)</strong>, which is optimal for this problem.</p><div><hr></div><h3>Problem4: <a href="https://leetcode.com/problems/maximize-the-minimum-game-score/description/">Maximize the Minimum Game Score</a></h3><p>In this problem, we should find the maximum of minimum possible value after, at most, m moves. In this problem, if you can make all points to K within m moves, then you can say that all points are over K-1, K-2, etc. So, we can simply check if random X is okay for the answer. If yes, we only need to check the values above X. Otherwise, check those below X. </p><p>Then, we need to solve the problem of whether it is possible to make all values larger than or equal to X if X is given. Now the X is given, we can calculate how many times we should visit every index.</p><ul><li><p><code>cnt[i] = (X + points[i] -1) / points[i]</code></p></li></ul><p>Now, we can visit the index i greedily. No matter how far you go from i, you should visit the current index(i) at cnt[i] times. In this problem you should visit all indexes to get back to the index i and every move counts. So, we just can visit the current cnt[i] times first, then we can go to the next index.</p><ul><li><p>To visit index i, we can start from the previous index. [move i-1 to i] </p></li><li><p>And then, we should go to the next index and get back to the current as many times as needed. [move i to i+1 and move i+1 to i] * (cnt[i]-1 times). </p><ul><li><p>We already visit once from the previous index, so we just need the cnt[i] - 1 times visit more.</p></li><li><p>In this case, we should reduce the cnt[i+1] by (cnt[i]-1). </p></li></ul></li><li><p>If cnt[i] ==0 , even though we don&#8217;t need to visit more, then we need to move to i to visit the i+1 index.</p><ul><li><p>However, if the cnt[i] == 0 and the i == n-1, which means that we don&#8217;t need any more visit after i, then we can stop moving.</p></li></ul></li></ul><pre><code>class Solution {
public:
    // Helper function to check if a given minimum value can be achieved
    bool isPossible(vector&lt;int&gt;&amp; points, long long targetValue, int maxMoves) {
        int n = points.size();
        vector&lt;long long&gt; requiredUpdates(n);
        long long totalMoves = 0;

        // Calculate how many times each index needs to be updated to reach targetValue
        for (int i = 0; i &lt; n; ++i) {
            requiredUpdates[i] = (targetValue + points[i] - 1) / points[i]; // Ceiling division

            // If previous index was updated, adjust current index accordingly
            if (i &gt; 0 &amp;&amp; requiredUpdates[i - 1] &gt; 0) {
                totalMoves += 2 * requiredUpdates[i - 1] - 1;
                requiredUpdates[i] = max(0LL, requiredUpdates[i] - (requiredUpdates[i - 1] - 1));
            } 
            // Otherwise, if we are in the middle of the array, count a move
            else if (i &gt; 0 &amp;&amp; i != n - 1) {
                totalMoves++;
            }
        }

        // Handle last index separately
        if (requiredUpdates[n - 1] &gt; 0) {
            totalMoves += requiredUpdates[n - 1] * 2;
            if (requiredUpdates[n - 2] &gt; 0) {
                totalMoves--; // Reduce one move if second last index was updated
            }
        }

        return totalMoves &lt;= maxMoves; // Check if we can achieve the target value within maxMoves
    }

    // Binary search to find the maximum possible minimum value
    long long maxScore(vector&lt;int&gt;&amp; points, int m) {
        long long left = 1, right = 1e15, answer = 0;

        while (left &lt;= right) {
            long long mid = left + (right - left) / 2;

            // Check if it's possible to maintain a minimum score of 'mid'
            if (isPossible(points, mid, m)) {
                answer = mid; // Store the valid answer
                left = mid + 1; // Try for a higher minimum value
            } else {
                right = mid - 1; // Reduce the search space
            }
        }
        
        return answer; // Maximum minimum possible value
    }
};
</code></pre><h3><strong>Time Complexity Analysis</strong></h3><ul><li><p><strong>Binary Search:</strong> Runs in <strong>O(log 1e15) &#8776; O(50)</strong></p></li><li><p><strong>Greedy Checking Function (</strong><code>pos</code><strong>)</strong>: Iterates over <code>n</code> elements &#8594; <strong>O(n)</strong></p></li><li><p><strong>Total Complexity:</strong> O(nlog&#8289;1e15)&#8776; O(n&#8901;50) &#8594; <strong>O(n)</strong> in practical cases.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[Find Edges in Shortest Paths]]></title><description><![CDATA[Shortest Path, Dijkstra&#8217;s algorithm, Backtracking]]></description><link>https://www.zerotoexpert.blog/p/find-edges-in-shortest-paths</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/find-edges-in-shortest-paths</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sat, 08 Feb 2025 17:05:41 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99c48acd-da9b-46b0-a422-8e176f1658bb_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/find-edges-in-shortest-paths/description/">Original Link</a></p><h1>Solution</h1><p>In this problem, we should find the shortest path from 0 to n-1 and all edges that can be used as the shortest path. </p><p>If you track all the paths while getting the shortest path, this problem seems complicated. We are not sure the current path is the shortest path until we reach the Node n-1.</p><p>However, we know that Dijkstra&#8217;s algorithm returns the shortest path to all nodes from the starting node. It means that if we get all shortest paths from Node 0 to all nodes, then we can detect the edge from that node is used as the shortest path by comparing the <code>dist[currentNode] + cost == dist[targetNode]</code>. </p><p>For example, </p><ul><li><p>The shortest path to Node 1 costs 5. </p></li><li><p>And the shortest path to Node 2 costs 7. </p></li><li><p>Then, if the edge connecting Node 1 and Node 2 costs 2, it can be used as the shortest path to Node 2. </p><ul><li><p>If it costs more than 2, it must not be the shortest path because there is another way to get to Node 2.</p></li></ul></li></ul><p></p><p>We should iterate from the destination to determine whether the edge can be used. We wouldn&#8217;t know the following possible nodes from the start. If we find the possible nodes from the destination, we can get all possible edges to those nodes similarly.</p><pre><code>class Solution {
public:
    vector&lt;bool&gt; findAnswer(int n, vector&lt;vector&lt;int&gt;&gt;&amp; edges) {
        // Step 1: Build the graph as an adjacency list
        unordered_map&lt;int, vector&lt;pair&lt;int, int&gt;&gt;&gt; graph;
        for (int i = 0; i &lt; edges.size(); ++i) {
            int u = edges[i][0], v = edges[i][1];
            graph[u].push_back({v, i}); // Store {neighbor, edge index}
            graph[v].push_back({u, i});
        }

        // Step 2: Use Dijkstra's algorithm to find shortest distances from node 0
        vector&lt;int&gt; dist(n, 1e9);  // Initialize distances with a large value
        dist[0] = 0;
        
        // Min-heap (priority queue) for Dijkstra's algorithm
        priority_queue&lt;pair&lt;int, int&gt;&gt; pq;
        pq.push({0, 0});  // {distance, node}

        while (!pq.empty()) {
            auto current = pq.top();
            pq.pop();
            int d = -current.first;  // Convert back to positive distance
            int node = current.second;

            // Ignore outdated distances (optimization)
            if (dist[node] &lt; d) continue;

            // Explore neighbors
            for (auto &amp;neighborData : graph[node]) {
                int neighbor = neighborData.first;
                int edgeIndex = neighborData.second;
                int cost = edges[edgeIndex][2];  // Edge weight

                // Relaxation step: Update shortest distance if a better path is found
                if (dist[neighbor] &gt; d + cost) {
                    dist[neighbor] = d + cost;
                    pq.push({-dist[neighbor], neighbor});  // Push with negative for min-heap behavior
                }
            }
        }

        // Step 3: Backtrack from node n-1 to find edges used in shortest paths
        vector&lt;bool&gt; answer(edges.size(), false);
        vector&lt;bool&gt; seen(n, false);
        
        queue&lt;int&gt; q;
        q.push(n - 1);
        seen[n - 1] = true;

        while (!q.empty()) {
            int node = q.front();
            q.pop();

            // Traverse backwards to find shortest path edges
            for (auto &amp;neighborData : graph[node]) {
                int neighbor = neighborData.first;
                int edgeIndex = neighborData.second;
                int cost = edges[edgeIndex][2];

                // If the edge belongs to a shortest path
                if (dist[neighbor] + cost == dist[node]) {
                    answer[edgeIndex] = true;
                    if (!seen[neighbor]) {
                        seen[neighbor] = true;
                        q.push(neighbor);
                    }
                }
            }
        }

        return answer;
    }
};</code></pre><h3><strong>Time Complexity Analysis</strong></h3><ul><li><p><strong>Graph Construction:</strong> <code>O(m)</code>, where <code>m</code> is the number of edges.</p></li><li><p><strong>Dijkstra&#8217;s Algorithm:</strong> <code>O((n + m) log n)</code>, since each node and edge are processed at most once in a priority queue.</p></li><li><p><strong>Backtracking using BFS:</strong> <code>O(n + m)</code>, since each node and edge are visited once.</p></li></ul><p><strong>Overall Complexity:</strong> <code>O((n + m) log n)</code>, which is efficient for large graphs.</p>]]></content:encoded></item><item><title><![CDATA[Second Minimum Time to Reach Destination]]></title><description><![CDATA[Shortest Path, Dijkstra&#8217;s algorithm]]></description><link>https://www.zerotoexpert.blog/p/second-minimum-time-to-reach-destination</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/second-minimum-time-to-reach-destination</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sat, 08 Feb 2025 15:27:33 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F99c48acd-da9b-46b0-a422-8e176f1658bb_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><a href="https://leetcode.com/problems/second-minimum-time-to-reach-destination/description">Original Link</a></p><h1>Solution</h1><p>In this problem, we should find the second minimum shortest path to the destination. If the problem wants the minimum shortest path, it would be solved with Dijkstra's algorithm. However, we should do more to find the second one.</p><p>One thing we can do is to put all possible paths until we reach the destination twice at different times. Unlike Dijkstra&#8217;s algorithm, we don&#8217;t need to compare the minimum times to get to the next vertex. If we use min-heap, the answer will be returned as expected.</p><p>The solution above takes too long because it contains too many duplicates to reach each vertex. So, we reduce the duplication to make it faster. </p><p><strong>If we get to the vertex X at time Y, then we don&#8217;t need to revisit X with time Y because the answer after that will be the same</strong>. For example, if the minimum path from 1 to N is 1 &#8594; 4 &#8594; N and we visited vertex 4 at time 10. Then, we don&#8217;t need to revisit vertex 4 at time 10 from vertice other than 1 because even though the routes are different, time to N will be the same.</p><p>So, we can remove the case where we visited the vertex X with the time Y. Also, we only need to get the second minimum, meaning we don&#8217;t need to get the third minimum time to visit each vertex. </p><pre><code>class Solution {
public:
    // Adjacency list representation of the graph
    unordered_map&lt;int, vector&lt;int&gt;&gt; graph;

    int secondMinimum(int n, vector&lt;vector&lt;int&gt;&gt;&amp; edges, int time, int change) {   
        // Build the graph from the given edge list
        for (auto &amp; edge : edges) {
            graph[edge[0]].push_back(edge[1]);
            graph[edge[1]].push_back(edge[0]);
        }

        // Priority queue for Dijkstra-like traversal (min-heap)
        priority_queue&lt;pair&lt;int, int&gt;&gt; pq;
        pq.push({0, 1});  // {travel time, node}

        // Store up to two shortest arrival times at each node
        vector&lt;vector&lt;int&gt;&gt; arrivalTimes(n + 1);
        arrivalTimes[1].push_back(0);  // Start at node 1 with time 0

        while (!pq.empty()) { 
            auto current = pq.top();
            pq.pop();
            int travelTime = -current.first;  // Negating since we use max-heap simulation
            int node = current.second;

            // If we reach the destination and recorded the second arrival time, return it
            if (node == n &amp;&amp; arrivalTimes[node].size() == 2) {
                return arrivalTimes[node].back();
            }

            // Handle traffic signal: Wait if the light is red
            if ((travelTime / change) % 2 == 1) {
                travelTime = change * ((travelTime / change) + 1);  // Wait until green
            }

            // Explore all adjacent nodes
            for (auto &amp; neighbor : graph[node]) {
                int newTime = travelTime + time;

                // If the neighbor already has two recorded times, ignore
                if (arrivalTimes[neighbor].size() &gt; 1) continue;

                // Ensure we record two **distinct** times per node
                if (!arrivalTimes[neighbor].empty() &amp;&amp; arrivalTimes[neighbor].back() == newTime) continue;

                // Store new travel time and push to queue
                arrivalTimes[neighbor].push_back(newTime);
                pq.push({-newTime, neighbor});  // Use negative to simulate min-heap
            }
        }

        return -1;  // Should never be reached if a second minimum path exists
    }
};</code></pre><h3><strong>Time Complexity Analysis:</strong></h3><ul><li><p><strong>Graph Construction:</strong> <code>O(E)</code>, where <code>E</code> is the number of edges.</p></li><li><p><strong>Priority Queue Operations:</strong></p><ul><li><p>Each node can be pushed into the queue <strong>at most twice</strong> (<code>O(2N log N) ~ O(N log N)</code>).</p></li><li><p>Each edge is processed at most twice (<code>O(2E)</code>).</p></li></ul></li><li><p><strong>Overall Complexity:</strong> <code>O((N + E) log N)</code>, which is efficient for large graphs.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[Leetcode Weekly Contest 435]]></title><description><![CDATA[Solutions for the Weekly contest 435.]]></description><link>https://www.zerotoexpert.blog/p/leetcode-weekly-contest-435</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/leetcode-weekly-contest-435</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sun, 02 Feb 2025 12:54:20 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcbf83b9-24f2-4bda-ace7-ea2ba9f53b1d_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3>[Problem 1] <a href="https://leetcode.com/problems/maximum-difference-between-even-and-odd-frequency-i/description/">Maximum Difference Between Even and Odd Frequency I</a></h3><p>To get the correct answer, we should find the character that appears most at odd times and the one that appears least at even times. </p><p>So, I iterate the input string and record the frequency for all characters. Then, I calculate the maximum odd frequency and minimum even frequency. In this case, we cannot use characters that are not shown.</p><pre><code>class Solution {
public:
    int maxDifference(string s) {
        vector&lt;int&gt; cnt(26, 0);
        for (auto &amp;c:s)cnt[c-'a']++;
        int maxOdd = 0, minEven = 1e9;
        for (auto &amp; x:cnt) {
            if (x == 0) continue;
            if (x % 2 == 0) minEven = min(minEven, x);
            else maxOdd = max(maxOdd, x);
        }
        return maxOdd - minEven;
    }
};</code></pre><div><hr></div><h3>[Problem 2] <a href="https://leetcode.com/problems/maximum-manhattan-distance-after-k-changes/description/">Maximum Manhattan Distance After K Changes</a></h3><p>In this problem, we should find the maximum Manhattan distance from (0, 0). We can calculate the Manhattan distance by [X1 - X0| + [Y1 - Y0|. If we want it to be maximum, we should minimize the opposite moves, such as N-S and W-E.</p><p>So, we can simply choose a maximum of one from N/S and one from W/E. Then, we can change the direction at most K from both minimum directions. </p><ul><li><p>For example, N = 6, S = 4, E = 5, W = 2, K = 5</p><ul><li><p>Then, we can choose N and E.</p></li><li><p>We change 4 S to 4 N and 1 W to 1 E (Total K times).</p></li><li><p>Then it became N= 10, S = 0, E = 6, W = 1, so the answer is 15.</p></li></ul></li></ul><p></p><p>We should check the answer at each index. The maximum can be found in the middle of the moves.</p><pre><code>class Solution {
public:
    int maxDistance(string S, int k) {
        int n = 0, w = 0, s = 0, e = 0, ans = 0;
        for (auto &amp; c:S) {
            if (c == 'N') n++;
            else if (c == 'W') w++;
            else if (c == 'S') s++;
            else e++;

            int curr = max(n, s) + max(w, e), minus = min(n, s) + min(w, e);
            int changed = min(minus, k);
            minus -= changed;
            curr += changed;
            curr -= minus;
            ans = max(ans, curr);
        }
        return ans;
    }
};</code></pre><div><hr></div><h3>[Problem 3] <a href="https://leetcode.com/problems/minimum-increments-for-target-multiples-in-an-array/description/">Minimum Increments for Target Multiples in an Array</a></h3><p>In this problem, we should find the minimum increments to meet the condition. The critical point is that we only can increase the element. By this restriction, we can calculate the minimum value to make nums[i] to be the multiple of targets[j]. </p><p>However, we don&#8217;t know which number will be the multiple of which target. Also, one number can be the multiple of two different targets. We cannot consider all of these cases one by one.</p><p>Fortunately, we only have at most 4 targets. It means that if we calculate all the cases that nums[i] cover, it is at most 2^4 = 16. So, it is fast enough to iterate all cases for each index i of nums.</p><p>I precalculated the&nbsp;<a href="https://en.wikipedia.org/wiki/Least_common_multiple">Least Common Multiple</a>&nbsp;for each target combination to get the minimum increment faster. I record the state to find which targets are covered. If all targets are covered before iterating all nums, then return 0. If iterating all numbers finished before covering all targets, return an invalid value.</p><p>I also used memoization to skip the duplicated case.</p><pre><code>class Solution {
public:
    int n, m;
    unordered_map&lt;int, long long&gt; mp;
    int dp[50001][1&lt;&lt;4];
    long long func(vector&lt;int&gt; &amp; nums, vector&lt;int&gt; &amp; target, int i, int state) {
        if (state == (1&lt;&lt;m) - 1) {
            return 0;
        }
        if (i == n) {
            return 1e9;
        }

        if (dp[i][state] != -1) return dp[i][state];
        
        long long ans = 1e9;
        for (int x = 0; x &lt; (1 &lt;&lt; m); ++x) {
            long long l = mp[x];
            long long diff = ((nums[i] + l-1) / l) * l - nums[i];
            ans = min(ans, func(nums, target, i+1, state | x) + diff);
        }

        return dp[i][state] = ans;
    }

    int minimumIncrements(vector&lt;int&gt;&amp; nums, vector&lt;int&gt;&amp; target) {
        n = (int)nums.size();
        m = (int)target.size();
        memset(dp, -1,sizeof(dp));
        mp[0] = 1;
        for (int x = 1; x &lt; (1 &lt;&lt; m); ++x) {
            vector&lt;long long&gt; a;
            for (int j = 0; j &lt; m; ++j) {
                if (x &amp; (1 &lt;&lt; j)) {
                    a.push_back(target[j]);
                }
            }
            long long l = a[0];
            for (int i = 1; i &lt; a.size(); ++i) {
                l = l * a[i] / gcd(l, a[i]);
            }
            mp[x] = l;
        }

        return func(nums, target, 0, 0);
    }
};</code></pre><p></p><div><hr></div><h3>[Problem 4] <a href="https://leetcode.com/problems/maximum-difference-between-even-and-odd-frequency-ii/description/">Maximum Difference Between Even and Odd Frequency II</a></h3><p>We should find the maximum difference between odd frequency and even frequency. This problem is the hard version of problem 1. The reason why the first problem is easy is that the size of the string is fixed. We only need to care about the frequency of each character. </p><p>However, we can't use the same strategy in this problem because we don&#8217;t know the size. If we fix the size, we should iterate every character of the input string for each possible size larger than K. If K == 1, then it should take O((26) * N^2) times. So, this won&#8217;t work.</p><p>Fortunately, we know that there are only 5 characters that can be shown in the input string. We don&#8217;t know which one will be the answer, but the answer case will use only 2 characters: <strong>One for the odd frequency and one for the even frequency.</strong> Also, there are only 20 possible combinations. Assuming the characters for counting and getting the answer within O(N) or O(NlogN) time complexity, iterating 20 times wouldn&#8217;t be the problem.</p><p>So, I tried to consider the case when only two characters exist. Let&#8217;s ignore the size of substring K.</p><p></p><h4>How to calculate the frequency for a range query.</h4><p>To get the correct answer, we should find the exact case where an odd frequency character should appear at odd times and an even frequency character should appear at even times. But we are not sure if <code>index i</code> will meet the conditions. We should remove the character from the start if it does not meet. <strong>In short, we should calculate the count for each character within the range of [left, right].</strong></p><p>To calculate it faster, I precalculate the prefix sum, which contains the frequency data of the odd-frequency character and the even-frequency character within [0, i]. To find out the counting status of [i, j], we can simply subtract the prefixSum[i-1] from the prefixSum[j].</p><p></p><h4>How can we ensure the proper case for the answer?</h4><p>Now, we should find the right index i where [i, j] is the possible case for the answer. It means that when we iterate the input string, we should find the left index that will meet the condition. This is pretty complex.</p><p>What I thought of was the following conditions:</p><ul><li><p>We have already set the odd-frequency character and even-frequency character, and my goal is to find the case where an odd-frequency character appears at odd times, and the even-frequency character appears at even times. </p></li><li><p>If both characters appear at even times at index i, I should find the left index where an odd-frequency character appears at odd times and the even-frequency character appears at even times.</p><ul><li><p>For example, both characters appear 6 times at index i. If we found the j where j &lt; i and odd-frequency character appeared 3 times and even-frequency character appeared 2 times.</p></li><li><p>If we remove the characters [0,j] from [0, i], then [j+1, i] will meet the condition because odd-frequency appeared 3 times(6 - 3), and even-frequency appeared 4 times(6 -2).</p></li></ul></li><li><p>In short, we can record each counting status at each index i and then find the correct index for the right counting status type.</p><ul><li><p>There will be four different statuses.</p><ul><li><p>(Odd, Even) = odd-frequency appears <strong>odd</strong> times, even-frequency appears <strong>even</strong> times,</p></li><li><p>(Even, Even) = odd-frequency appears <strong>even</strong> times, even-frequency appears <strong>even</strong> times,</p></li><li><p>(Odd, Odd) = odd-frequency appears <strong>odd</strong> times, even-frequency appears <strong>odd</strong> times,</p></li><li><p>(Even, Odd) = odd-frequency appears <strong>even</strong> times, even-frequency appears <strong>odd</strong> times,</p></li></ul></li><li><p>To get the (Odd, Even) case, we can find the correct status for removal.</p><ul><li><p>(Odd, Even) - <strong>(Even, Even)</strong> = (Odd, Even)</p></li><li><p>(Even, Even) - <strong>(Odd, Even)</strong> = (Odd, Even)</p></li><li><p>(Odd, Odd) - <strong>(Even,  Odd)</strong> = (Odd, Even)</p></li><li><p>(Even, Odd) - <strong>(Odd, Odd)</strong> = (Odd, Even)</p></li></ul></li></ul></li><li><p>This can be implemented by recording the types at each index i and enqueuing them to each type queue. We can then find the index j for removal from the matching status type queue at index i.</p><ul><li><p>If (Odd, Even) is at index i, find the index from the (Even, Even) queue.</p></li></ul></li></ul><p></p><h4>How can we ensure the size of the substring?</h4><p>To ensure the size of the substring, we can use a pointer to follow the index to keep the size of the substring and enqueue the value for each type of queue. We cannot calculate the answer before we enqueue the value to the queue. This means we should ensure that the enqueued items are okay to get the answer. </p><p>So, if the i&#8212;(left index) &gt;= K meets, we can enqueue the left index item to the queue and then move the left index to the right. </p><pre><code>class Solution {
public:
    int func(string &amp; s, int k, char &amp; oddChar, char &amp; evenChar) {
        const int n = (int)s.size();
        vector&lt;vector&lt;int&gt;&gt; cnt(n, vector&lt;int&gt;(2));
        int oddCharCnt = 0, evenCharCnt = 0;
        vector&lt;int&gt; T(n);
        for (int i = 0; i &lt; n; ++i) {
            if (s[i] == oddChar) oddCharCnt++;
            else if (s[i] == evenChar) evenCharCnt++;
            cnt[i][0] = oddCharCnt, cnt[i][1] = evenCharCnt;
            if (oddCharCnt % 2 == 0 &amp;&amp; evenCharCnt % 2 == 1) T[i] = 0;
            else if (oddCharCnt % 2 == 0 &amp;&amp; evenCharCnt % 2 == 0) T[i] = 1;
            else if (oddCharCnt % 2 == 1 &amp;&amp; evenCharCnt % 2 == 0) T[i] = 2;
            else T[i] = 3;
        }
        int ans = -1e9, curr = 0, l = 0;

        auto getOppositeIndex  = [&amp;] (int t) {
            if (t == 0) return 3;
            if (t == 1) return 2;
            if (t == 2) return 1;
            return 0;
        };

        auto isPossible = [&amp;] (int i, int j) {
            int oddCharCnt = cnt[i][0] - (j == -1 ? 0 : cnt[j][0]);
            int evenCharCnt = cnt[i][1] - (j == -1 ? 0 : cnt[j][1]);
            return oddCharCnt &gt; 0 &amp;&amp; evenCharCnt &gt; 0 &amp;&amp; oddCharCnt % 2 == 1 &amp;&amp; evenCharCnt % 2 == 0 &amp;&amp; i - j &gt;= k;
        };

        vector&lt;int&gt; minimumCanRemove(4, 1e9);
        queue&lt;int&gt; q[4];
        for (int i = 0; i &lt; n; ++i) {
            int curr = cnt[i][0] - cnt[i][1];
            while(i - l &gt;= k) {
                q[T[l]].push(l);
                ++l;
            }
            int oppositeType = getOppositeIndex(T[i]);
            while(!q[oppositeType].empty() &amp;&amp; isPossible(i, q[oppositeType].front())) {
                int prevIdx = q[oppositeType].front();
                q[oppositeType].pop();
                minimumCanRemove[oppositeType] = min(minimumCanRemove[oppositeType], cnt[prevIdx][0] - cnt[prevIdx][1]);
            }
            ans = max(ans, curr - minimumCanRemove[oppositeType]);
            if (T[i] == 2 &amp;&amp; isPossible(i, -1)) ans = max(ans, curr);
        }

        return ans;
    }

    int maxDifference(string s, int k) {
        int ans = INT_MIN;
        for (char i = '0'; i &lt;= '4'; ++i) {
            for (char j = '0'; j &lt;= '4'; ++j) {
                if (i == j) continue;
                ans = max(ans, func(s, k, i, j));
            }
        }
        return ans;
    }
};</code></pre>]]></content:encoded></item><item><title><![CDATA[Monotonic Queue Questions]]></title><description><![CDATA[Let's solve the problem related to the monotonic queue patterns.]]></description><link>https://www.zerotoexpert.blog/p/monotonic-queue-questions</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/monotonic-queue-questions</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Tue, 28 Jan 2025 10:49:40 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcbf83b9-24f2-4bda-ace7-ea2ba9f53b1d_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>A monotonic queue means the queue that contains the elements is sorted in increasing or decreasing order. This is used to determine the window's minimum or maximum elements. </p><p>A monotonic queue keeps track of elements in increasing or decreasing order, so this should be used when we don&#8217;t need to insert the elements between the elements in the queue. This means we should push the current element back to the queue after dropping the smaller or larger elements from the back to keep the order. This implies that we don&#8217;t need to use the dropped elements anymore.</p><p></p><p>Let&#8217;s solve some problems to practice a monotonic queue.</p><p></p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.zerotoexpert.blog/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.zerotoexpert.blog/subscribe?"><span>Subscribe now</span></a></p><p></p><h2>Problem 1: <a href="https://leetcode.com/problems/sliding-window-maximum/description/">Sliding Window Maximum</a></h2><div><hr></div><p>In this problem, we should find the maximum elements of a fixed window. This means we should keep track of the largest element as we iterate the elements. We should find a way to find the next largest element if we drop the current largest element.</p><p>Let&#8217;s see the example. </p><p><code>nums = [1, -1, 10, 2, 11, 3, 7, 5] , k = 3</code></p><ul><li><p>The window size is 3, so we can start getting the maximum value since we iterate at least 3 elements.</p><ul><li><p>1st window is <code>[1, -1, 10]</code>. The maximum value is 10.</p></li><li><p>2nd window is <code>[-1, 10, 2]</code>. The maximum value is 10.</p></li><li><p>3rd window is <code>[10, 2, 11]</code>. The maximum value is 11.</p></li><li><p>4th window is <code>[2, 11, 3]</code>. The maximum value is 11.</p></li><li><p>5th window is <code>[11, 3, 7]</code>. The maximum value is 11.</p></li><li><p>6th window is <code>[3, 7, 5]</code>. The maximum value is 7.</p></li></ul></li><li><p>So, the answer should be <code>[10, 10, 11, 11, 11, 7]</code>.</p></li></ul><p></p><p>To solve the problem, we can use a monotonic queue for keeping the largest numbers.</p><ul><li><p>For every element, check if any elements in the queue are smaller than or equal to nums[i]. It&#8217;s because after we put nums[i] to the window, elements smaller than or equal to nums[i]  won&#8217;t be used as the maximum value. </p></li><li><p>Put nums[i] to the back of the monotonic queue. If the queue is empty, then nums[i] is the largest number in the window. If not, there is an element larger than nums[i]. </p></li><li><p>Check if the position of the first element in the queue is out of the window. If the largest number is out of the window, we should pop it from the queue. We can check this by adding the index(i), not the value(nums[i]) to the queue.</p></li></ul><pre><code>class Solution {
public:
    vector&lt;int&gt; maxSlidingWindow(vector&lt;int&gt;&amp; nums, int k) {
        vector&lt;int&gt; ans;
        const int n = (int)nums.size();
        deque&lt;int&gt; q;
        for (int i = 0; i &lt; n; ++i) {
            while(!q.empty() &amp;&amp; nums[q.back()] &lt;= nums[i]) {
                q.pop_back();
            }
            q.push_back(i);
            while(!q.empty() &amp;&amp; q.front() &lt; i-k+1) {
                q.pop_front();
            }
            if (i &gt;= k-1) {
                ans.push_back(nums[q.front()]);
            }
        }
        return ans;
    }
};</code></pre><p></p><h2>Problem2: <a href="https://leetcode.com/problems/k-empty-slots/description/">K Empty Slots</a></h2><div><hr></div><p>In this problem, you should find the minimum number of days when two bulbs are turned on and all bulbs between them are turned off. </p><p>This problem seems tricky if you keep track of the bulbs&#8217; status. We cannot track the status of every bulb between two turned-on bulbs. However, we can think of the final status of what we want to find.</p><p>What we want to find is the following situation.</p><ul><li><p>If K == 3, then <code>[On, Off, Off, Off, On].</code></p></li><li><p>If K == 0, then <code>[On, On].</code></p></li></ul><p>So, we can ensure this happens when the minimum number of days to turn on any of the K bulbs is later than the maximum number of days to turn on both the left and right bulbs. Based on the input, we can calculate the days to turn on each bulb.</p><p>For example, let&#8217;s assume that the array that represents the days to turn on the bulbs is <code>[1,3,4,5,2]</code>. It means that it takes 1 day to turn on the first bulb and 3 days to turn on the second day.</p><ul><li><p>On the first day, the bulb status is <code>[On, Off, Off, Off, Off]</code>.</p></li><li><p>On the second day, the bulb status is <code>[On, Off, Off, Off, On]</code>.</p></li><li><p>This can be proved by calculating the following condition.</p><ul><li><p> <code>min({arr[1], arr[2], arr[3]}) &gt; max(arr[0], arr[4])</code></p></li></ul></li></ul><pre><code>class Solution {
public:
    int kEmptySlots(vector&lt;int&gt;&amp; bulbs, int k) {
        const int n = (int)bulbs.size();
        vector&lt;int&gt; on(n);
        for (int i = 0; i &lt; n; ++i) {
            on[bulbs[i]-1] = i+1;
        }

        int ans = 1e9;
        deque&lt;int&gt; q;
        for (int i = 0; i &lt; n; ++i) {
            while(!q.empty() &amp;&amp; on[q.back()] &gt;= on[i]) {
                q.pop_back();
            }
            q.push_back(i);
            while(!q.empty() &amp;&amp; q.front() &lt;= i-k) {
                q.pop_front();
            }
            if (i &gt;= k &amp;&amp; i-k &gt;= 0 &amp;&amp; i+1 &lt; n){
                int maxOn = max(on[i-k],  on[i+1]);
                if (k == 0 || maxOn &lt; on[q.front()]) {
                    ans = min(ans, maxOn);
                }
            }
        }
        return ans == 1e9 ? -1 : ans;
    }
};</code></pre><p></p><h2>Problem3: <a href="https://leetcode.com/problems/minimum-number-of-coins-for-fruits-ii/">Minimum Number of Coins for Fruits II</a></h2><div><hr></div><p>We should find the minimum number of coins needed to buy all the fruits. If we buy the fruit in the index X, we can get the following (X+1) fruits for free. This might be helpful because buying expensive fruits with a small number of coins is possible. </p><p>We can use the dynamic programming technique to get the minimum number of coins at each index. </p><p>Suppose that <strong>dp[i] means the minimum number of coins needed to buy all fruits after (including) index i</strong>. Then, we make the following formula.</p><ul><li><p>dp[i] = min(dp[j] + prices[i]) for all j where i&lt;= j &lt;= min(i+i+2, n).</p><ul><li><p>dp[n] should be 0. This is needed because we can buy the fruits at index i, and all fruits after i are free. </p></li></ul></li></ul><p>This technique works when the price length (n) is small. <a href="https://leetcode.com/problems/minimum-number-of-coins-for-fruits/description/">Here&#8217;s the question</a> that you can try with dynamic programming.</p><p>However, in this problem, the maximum size of n is 10^5, so it is not fast enough to use dynamic programming. So, we should find another way. </p><p>Looking at the formula above, you will see that we don&#8217;t need to know all the dp[j] values. We need the minimum dp[j] within the valid window. For example, if the current index is 5, then we should know the minimum of dp[j] where <code>6 &lt;= j &lt;= 12(5 + 5 + 2)</code>.</p><p>So, we can use the monotonic queue to keep track of the minimum value of dp[j] and remove the elements outside the window before calculating the dp[i] value. To make this work, we should iterate from the back.</p><pre><code>class Solution {
public:
    int minimumCoins(vector&lt;int&gt;&amp; prices) {
        const int n = (int)prices.size();
        vector&lt;int&gt; dp(n+1, 0);
        deque&lt;int&gt; q;
        q.push_back(n);
        for (int i = n-1; i&gt;=0; --i) {
            while(!q.empty() &amp;&amp; q.front() &gt; i + i + 2) q.pop_front();
            dp[i] = prices[i] + dp[q.front()];
            while(!q.empty() &amp;&amp; dp[q.back()] &gt;= dp[i]) {
                q.pop_back();
            }
            q.push_back(i);
        }
        return dp[0];
    }
};</code></pre><p></p><h2>Problem4:  <a href="https://leetcode.com/problems/count-non-decreasing-subarrays-after-k-operations/description/">Count Non-Decreasing Subarrays After K Operations</a></h2><div><hr></div><p>We should find the non-decreasing subarrays after most K operations. In this case, the operation is increasing one of the elements by 1 in the subarray. This means that we should make every element bigger within the subarray.</p><p>Let&#8217;s assume that the nums = <code>[6,3,1,2]</code>.</p><ul><li><p>If the subarray is [6,3], it should be [6,6], and the number of operations is 3.</p><ul><li><p>To make 3 to 6 &#8594; 3 operations.</p></li></ul></li><li><p>If the subarray is [6,3,1], it should be [6,6,6], and the number of operations is 8.</p><ul><li><p>To make 3 to 6 &#8594; 3 operations.</p></li><li><p>To make 1 to 6 &#8594; 5 operations.</p></li></ul></li><li><p>If the subarray is [3,1,2], it should be [3,3,3], and the number of operations is 3.</p><ul><li><p>To make 1 to 3 &#8594; 2 operations.</p></li><li><p>To make 2 to 3 &#8594; 1 operations.</p></li></ul></li></ul><p>So, when we iterate the elements, we should know how many operations we need to make <code>nums[i]</code> to something. We can use the monotonic queue to store the maximum numbers within the window and add <code>maximum number - nums[i]</code> operations. If the current value is the maximum, the result will be 0.</p><p>If the current sum of operations is larger than K, all subarrays containing the current window are invalid. For example, if the nums = [A, B, C, D, E], and the subarray [A, B, C] is invalid. Then  [A, B, C, D] and  [A, B, C, D, E] are also invalid because they contain the invalid subarray. To calculate the number of invalid subarrays, we can subtract the current index from N(the size of nums).</p><p>The hard part is calculating the operations when we reduce the window size. If we find the invalid subarray, we should remove the leftmost value from the window to minimize the operations. In this case, all operation counts should be changed because some of the elements in the window are larger than the next leftmost element.</p><p>Let&#8217;s say the leftmost element index is L.</p><ul><li><p>If nums[L] &lt;= nums[L+1], then we don&#8217;t need to re-calculate the number of operations because nothing will be changed.</p></li><li><p>If nums[L] &gt; nums[L+1], then we should change the number of operations.</p></li></ul><p>For example, the invalid subarray is <code>[6,3,1,5,10]</code>, and L = 0.</p><ul><li><p>Now, nums[1] (3) &lt; num[0] (6). </p></li><li><p>Find the next element&#8217;s index whose value is larger than or equal to nums[0]. It should be 4(nums[4] = 10).</p><ul><li><p>Reduce all operations added from 0 &lt;= i &lt; 4 to make elements to 6.</p></li></ul></li><li><p>Now, reduce the window size by changing L to 1.</p></li><li><p>We should re-calculate operations to make it non-descreasing within 1 &lt;= i &lt; 4.</p><ul><li><p>Find the next element&#8217;s index whose value is larger than or equal to nums[1]. It should be 3(nums[3] = 5).</p></li><li><p>Add all operations to make elements to 3 within 1 &lt;= i &lt; 3.</p></li><li><p>Add all operations to make elements to 5 within 3 &lt;= i &lt; 4.</p></li></ul></li></ul><p>To calculate the operations faster, we can pre-calculate the prefixSum array and the right-closest index array to contain the index whose value is larger than or equal to the current value.</p><ul><li><p>To calculate the whole operations from L &lt;= i &lt;= R.</p><ul><li><p><code>nums[L] * (R - L + 1) - (PrefixSum[R] - PrefixSum[L-1])</code></p></li><li><p>This calculation is only valid if the elements within the range are non-increasing.</p></li></ul></li></ul><pre><code>class Solution {
public:
    long long countNonDecreasingSubarrays(vector&lt;int&gt;&amp; nums, int k) {
        const int n = (int)nums.size();
        vector&lt;long long&gt; pref(n+1, 0LL);
        vector&lt;int&gt; R(n, n);
        stack&lt;int&gt; st;
        for (int i = 1; i &lt;= n; ++i) {
            pref[i] += pref[i-1] + nums[i-1];
            while(!st.empty() &amp;&amp; nums[st.top()] &lt;= nums[i-1]) {
                R[st.top()] = i-1;
                st.pop();
            }
            st.push(i-1);
        }

        auto calc = [&amp;] (int l, int r) {
            long long cnt = r - l + 1;
            return nums[l] * cnt - (pref[r+1] - pref[l]);
        };

        deque&lt;int&gt; q;
        long long tot = ((long long) n * (n + 1)) / 2;
        long long invalid = 0LL;
        int l = 0, cur = 0;
        for (int i = 0; i &lt; n; ++i) {
            while(!q.empty() &amp;&amp; nums[q.back()] &lt;= nums[i]) {
                q.pop_back();
            }
            q.push_back(i);
            cur += nums[q.front()] - nums[i];
            while (cur &gt; k) {
                invalid += n-i;
                int nx = min(R[l], i + 1);
                cur -= calc(l, nx-1);
                int j = l+1;
                while(j &lt; nx) {
                    cur += calc(j, min(R[j], i + 1)-1);
                    j = min(R[j], i + 1);
                }
                l++;
            }
            while(!q.empty() &amp;&amp; q.front() &lt; l) {
                q.pop_front();
            }
        }

        return tot - invalid;
    }
};</code></pre><p></p><h2>Problem5: <a href="https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/description/">Shortest Subarray with Sum at Least K</a></h2><div><hr></div><p>In this problem, we should find the shortest subarray among subarrays where the sum of elements is larger than or equal to K. </p><p>To make it easier, we can pre-calculate the prefix sum and find the matching subarrays by calculating the <code>prefixSum[i] - prefixSum[j]</code>. But this algorithm takes too long because we should iterate the input array for each index i. The time complexity is O(N^2). </p><p>What we should do in the solution above is to find the maximum of j where the condition meets(<code>prefixSum[i] - prefixSum[j] &gt;= k)</code>. The important thing is that if we find the j, we no longer need the prefixSum[j] value. It&#8217;s because if we should use it again, then it would be from prefixSum[x] where i &lt; x, and that can&#8217;t be the answer. </p><p>Also, we don&#8217;t need to consider the case where prefixSum[x] &gt;= prefixSum[y] (x &lt; y) when we find the index j. It&#8217;s because if x is possible to use, then y is also possible, and y will be used to get the correct answer as we need the shortest subarray.</p><p>So, we can use a monotonic queue to keep track of the prefixSum values in increasing order.</p><ul><li><p>If the current prefixSum[i] is smaller than the largest value in the element, then pop the last value from the queue.</p></li><li><p>If prefixSum[i] - (smallest value from the queue) &gt;= k, then calculate the subarray size. </p><ul><li><p>Pop the smallest value from the queue and check if the condition meets with the next smallest value. </p></li><li><p>We should keep doing this until the condition is met.</p></li><li><p>This is because the smallest prefixSum doesn&#8217;t ensure the shortest subarray.</p></li></ul></li></ul><pre><code>class Solution {
public:
    int shortestSubarray(vector&lt;int&gt;&amp; nums, int k) {
        const int n = (int)nums.size();
        vector&lt;long long&gt; pref(n+1, 0LL);
        for (int i = 1; i &lt;= n; ++i) {
            pref[i] = pref[i-1] + nums[i-1];
        }
        deque&lt;int&gt; q;
        q.push_back(0);
        int ans = 1e9;
        for (int i = 1; i &lt;= n; ++i) {
            while(!q.empty() &amp;&amp; pref[q.back()] &gt;= pref[i]) {
                q.pop_back();
            }

            q.push_back(i);
            while(!q.empty() &amp;&amp; pref[i] - pref[q.front()] &gt;= k) {
                ans = min(ans, i - q.front());
                q.pop_front();
            }
        }
        return ans == 1e9 ? -1: ans;
    }
};</code></pre><p></p><h2>Problem6: <a href="https://leetcode.com/problems/constrained-subsequence-sum/description/">Constrained Subsequence Sum</a></h2><div><hr></div><p>We should find the maximum sum of subsequences that meet the condition. The condition is simple. We cannot choose two elements consecutively where the difference between two indices is larger than K. (j - I &lt;= k, where i &lt; j).</p><p>This means we should find the maximum sum from the index range <code>[i-k, i-1]</code> to get the maximum sum in the index i. So, we can use the monotonic queue to keep track of the maximum sum in each index in decreasing order. </p><ul><li><p>We can drop the element from the front if the index is smaller than i-k. </p></li><li><p>We need to consider that use the nums[i] itself without adding something from the queue. This is valid if the largest sum is negative.</p></li><li><p>If the maximum sum in the current index is larger than any element in the queue, remove that element from the queue.</p></li></ul><pre><code>class Solution {
public:
    int constrainedSubsetSum(vector&lt;int&gt;&amp; nums, int k) {
        const int n = (int)nums.size();
        deque&lt;int&gt; q;
        int ans = -1e9;
        for (int i = 0; i &lt; n; ++i) {
            while(!q.empty() &amp;&amp; q.front() &lt; i-k) {
                q.pop_front();
            }

            nums[i] += (q.empty() ? 0 : max(0, nums[q.front()]));
            ans = max(ans, nums[i]);
            while(!q.empty() &amp;&amp; nums[q.back()] &lt;= nums[i]) {
                q.pop_back();
            }
            q.push_back(i);
        }
        return ans;
    }
};</code></pre><div><hr></div><h3><strong>Useful courses</strong></h3><ul><li><p><strong><a href="https://www.designgurus.io/course/grokking-the-coding-interview?aff=nozayu">Grokking the Coding Interview: Patterns for Coding Questions</a></strong></p></li><li><p><strong><a href="https://www.designgurus.io/course/grokking-advanced-coding-patterns-for-interviews?aff=nozayu">Grokking Advanced Coding Patterns for Interviews</a></strong></p></li></ul>]]></content:encoded></item><item><title><![CDATA[SSH Key Exchange Deep Dive]]></title><description><![CDATA[How does SSH generate shared secret for encryption]]></description><link>https://www.zerotoexpert.blog/p/ssh-key-exchange-deep-dive</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/ssh-key-exchange-deep-dive</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Sun, 04 Aug 2024 13:45:32 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!wO1A!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc161e3fe-9dad-4946-8148-5ed72220ad31_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!wO1A!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc161e3fe-9dad-4946-8148-5ed72220ad31_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!wO1A!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc161e3fe-9dad-4946-8148-5ed72220ad31_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!wO1A!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc161e3fe-9dad-4946-8148-5ed72220ad31_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!wO1A!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc161e3fe-9dad-4946-8148-5ed72220ad31_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!wO1A!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc161e3fe-9dad-4946-8148-5ed72220ad31_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!wO1A!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc161e3fe-9dad-4946-8148-5ed72220ad31_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c161e3fe-9dad-4946-8148-5ed72220ad31_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:157009,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!wO1A!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc161e3fe-9dad-4946-8148-5ed72220ad31_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!wO1A!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc161e3fe-9dad-4946-8148-5ed72220ad31_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!wO1A!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc161e3fe-9dad-4946-8148-5ed72220ad31_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!wO1A!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc161e3fe-9dad-4946-8148-5ed72220ad31_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.zerotoexpert.blog/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Zero to Expert! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div><hr></div><p><strong>SSH is a Secure Shell Protocol used &#8;broadly to connect to a server.</strong> Although it is not implemented based on TLS, it is treated as secure because all packets in the TCP session are encrypted. Even though we did not set any certificate or private key for SSH, this magical communication happens automatically.</p><p>I would like to dive deep into how this magical communication can happen. By the way, I am not an expert in mathematics, so I will skip the detailed implementation or calculation about cryptography(because I can&#8217;t even understand all of them&#8230;). I don&#8217;t think you need to know all the internal formulas for software engineering. </p><p></p><h2>Preparation</h2><p>I prepared the packet capture to explain what happens inside the SSH protocol. I created the EC2 instance with an RSA PEM key and tried to connect to the server with the paramiko library. Paramiko is a pure Python implementation of the SSHv2 protocol, providing both client and server functionality. Even though I&#8217;m unsure if the implementation is the same as other libraries, I think it is enough to understand the overall process.</p><pre><code>import paramiko
from io import StringIO

def main():
    client = paramiko.SSHClient()
    ip = "&lt;ssh server ip&gt;"
    port = 22
    keypair_file_path = "test-key.pem"

    with open(keypair_file_path, "r") as f:
        keypair = f.read()
    keypair_io = StringIO(keypair)
    key = paramiko.RSAKey.from_private_key(keypair_io)
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    client.connect(hostname=ip, port=port, username="ec2-user", pkey=key)

    stdin, stdout, stderr = client.exec_command("ls -al")
    print(stdin, stdout, stderr)
    client.close()


if __name__ == '__main__':
    main()</code></pre><p>Here&#8217;s the packet capture opened with Wireshark. You can see the SSHv2 in the protocol tap. Now, let&#8217;s inspect what happens step by step.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-dzj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56db9bf0-0084-48be-8e7f-6f7f62c33f74_2531x972.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-dzj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56db9bf0-0084-48be-8e7f-6f7f62c33f74_2531x972.jpeg 424w, https://substackcdn.com/image/fetch/$s_!-dzj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56db9bf0-0084-48be-8e7f-6f7f62c33f74_2531x972.jpeg 848w, https://substackcdn.com/image/fetch/$s_!-dzj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56db9bf0-0084-48be-8e7f-6f7f62c33f74_2531x972.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!-dzj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56db9bf0-0084-48be-8e7f-6f7f62c33f74_2531x972.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-dzj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56db9bf0-0084-48be-8e7f-6f7f62c33f74_2531x972.jpeg" width="1456" height="559" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/56db9bf0-0084-48be-8e7f-6f7f62c33f74_2531x972.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:559,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2029089,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-dzj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56db9bf0-0084-48be-8e7f-6f7f62c33f74_2531x972.jpeg 424w, https://substackcdn.com/image/fetch/$s_!-dzj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56db9bf0-0084-48be-8e7f-6f7f62c33f74_2531x972.jpeg 848w, https://substackcdn.com/image/fetch/$s_!-dzj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56db9bf0-0084-48be-8e7f-6f7f62c33f74_2531x972.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!-dzj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F56db9bf0-0084-48be-8e7f-6f7f62c33f74_2531x972.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h3>1. TCP connection</h3><p>First, it is implemented over TCP. The client tries to create a TCP connection to the server. In the paramiko library, the client.connect function creates a socket if no socket is passed.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!rl60!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f4972c-9c43-4501-927b-de66d283d55a_1130x895.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!rl60!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f4972c-9c43-4501-927b-de66d283d55a_1130x895.png 424w, https://substackcdn.com/image/fetch/$s_!rl60!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f4972c-9c43-4501-927b-de66d283d55a_1130x895.png 848w, https://substackcdn.com/image/fetch/$s_!rl60!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f4972c-9c43-4501-927b-de66d283d55a_1130x895.png 1272w, https://substackcdn.com/image/fetch/$s_!rl60!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f4972c-9c43-4501-927b-de66d283d55a_1130x895.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!rl60!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f4972c-9c43-4501-927b-de66d283d55a_1130x895.png" width="1130" height="895" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c2f4972c-9c43-4501-927b-de66d283d55a_1130x895.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:895,&quot;width&quot;:1130,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:141160,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!rl60!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f4972c-9c43-4501-927b-de66d283d55a_1130x895.png 424w, https://substackcdn.com/image/fetch/$s_!rl60!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f4972c-9c43-4501-927b-de66d283d55a_1130x895.png 848w, https://substackcdn.com/image/fetch/$s_!rl60!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f4972c-9c43-4501-927b-de66d283d55a_1130x895.png 1272w, https://substackcdn.com/image/fetch/$s_!rl60!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2f4972c-9c43-4501-927b-de66d283d55a_1130x895.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2>2. Version Check</h2><p>Before starting the key exchange, the client and the server identify the SSH version. As you can see, it is now v2.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ppAB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ed3ad1b-b635-49ab-8db5-46dbf8036359_2436x161.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ppAB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ed3ad1b-b635-49ab-8db5-46dbf8036359_2436x161.png 424w, https://substackcdn.com/image/fetch/$s_!ppAB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ed3ad1b-b635-49ab-8db5-46dbf8036359_2436x161.png 848w, https://substackcdn.com/image/fetch/$s_!ppAB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ed3ad1b-b635-49ab-8db5-46dbf8036359_2436x161.png 1272w, https://substackcdn.com/image/fetch/$s_!ppAB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ed3ad1b-b635-49ab-8db5-46dbf8036359_2436x161.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ppAB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ed3ad1b-b635-49ab-8db5-46dbf8036359_2436x161.png" width="1456" height="96" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8ed3ad1b-b635-49ab-8db5-46dbf8036359_2436x161.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:96,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:95179,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ppAB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ed3ad1b-b635-49ab-8db5-46dbf8036359_2436x161.png 424w, https://substackcdn.com/image/fetch/$s_!ppAB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ed3ad1b-b635-49ab-8db5-46dbf8036359_2436x161.png 848w, https://substackcdn.com/image/fetch/$s_!ppAB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ed3ad1b-b635-49ab-8db5-46dbf8036359_2436x161.png 1272w, https://substackcdn.com/image/fetch/$s_!ppAB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ed3ad1b-b635-49ab-8db5-46dbf8036359_2436x161.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p></p><h2>3. Negotiating the key exchange algorithm</h2><p>The client sends the key exchange message through the TCP connection with supported and preferred key exchange algorithms.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SRzV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5aded303-0717-4352-a4ba-a8791c7d409e_1863x85.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SRzV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5aded303-0717-4352-a4ba-a8791c7d409e_1863x85.png 424w, https://substackcdn.com/image/fetch/$s_!SRzV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5aded303-0717-4352-a4ba-a8791c7d409e_1863x85.png 848w, https://substackcdn.com/image/fetch/$s_!SRzV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5aded303-0717-4352-a4ba-a8791c7d409e_1863x85.png 1272w, https://substackcdn.com/image/fetch/$s_!SRzV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5aded303-0717-4352-a4ba-a8791c7d409e_1863x85.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SRzV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5aded303-0717-4352-a4ba-a8791c7d409e_1863x85.png" width="1456" height="66" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5aded303-0717-4352-a4ba-a8791c7d409e_1863x85.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:66,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:35848,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SRzV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5aded303-0717-4352-a4ba-a8791c7d409e_1863x85.png 424w, https://substackcdn.com/image/fetch/$s_!SRzV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5aded303-0717-4352-a4ba-a8791c7d409e_1863x85.png 848w, https://substackcdn.com/image/fetch/$s_!SRzV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5aded303-0717-4352-a4ba-a8791c7d409e_1863x85.png 1272w, https://substackcdn.com/image/fetch/$s_!SRzV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5aded303-0717-4352-a4ba-a8791c7d409e_1863x85.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>You can find the kex(key exchange) algorithm if you check the packet inside. The client sends first, and then the server returns. If you inspect the packet in detail, you can find all the algorithms the client and server use.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kblH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689c7c6a-8bc3-4dcc-a92f-140a640b4daf_2002x619.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kblH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689c7c6a-8bc3-4dcc-a92f-140a640b4daf_2002x619.png 424w, https://substackcdn.com/image/fetch/$s_!kblH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689c7c6a-8bc3-4dcc-a92f-140a640b4daf_2002x619.png 848w, https://substackcdn.com/image/fetch/$s_!kblH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689c7c6a-8bc3-4dcc-a92f-140a640b4daf_2002x619.png 1272w, https://substackcdn.com/image/fetch/$s_!kblH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689c7c6a-8bc3-4dcc-a92f-140a640b4daf_2002x619.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kblH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689c7c6a-8bc3-4dcc-a92f-140a640b4daf_2002x619.png" width="1456" height="450" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/689c7c6a-8bc3-4dcc-a92f-140a640b4daf_2002x619.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:450,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:216192,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!kblH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689c7c6a-8bc3-4dcc-a92f-140a640b4daf_2002x619.png 424w, https://substackcdn.com/image/fetch/$s_!kblH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689c7c6a-8bc3-4dcc-a92f-140a640b4daf_2002x619.png 848w, https://substackcdn.com/image/fetch/$s_!kblH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689c7c6a-8bc3-4dcc-a92f-140a640b4daf_2002x619.png 1272w, https://substackcdn.com/image/fetch/$s_!kblH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F689c7c6a-8bc3-4dcc-a92f-140a640b4daf_2002x619.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LQfO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbce0024-919f-4ddb-9035-7267f0b1370b_2021x329.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LQfO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbce0024-919f-4ddb-9035-7267f0b1370b_2021x329.png 424w, https://substackcdn.com/image/fetch/$s_!LQfO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbce0024-919f-4ddb-9035-7267f0b1370b_2021x329.png 848w, https://substackcdn.com/image/fetch/$s_!LQfO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbce0024-919f-4ddb-9035-7267f0b1370b_2021x329.png 1272w, https://substackcdn.com/image/fetch/$s_!LQfO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbce0024-919f-4ddb-9035-7267f0b1370b_2021x329.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LQfO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbce0024-919f-4ddb-9035-7267f0b1370b_2021x329.png" width="1456" height="237" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cbce0024-919f-4ddb-9035-7267f0b1370b_2021x329.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:237,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:106374,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!LQfO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbce0024-919f-4ddb-9035-7267f0b1370b_2021x329.png 424w, https://substackcdn.com/image/fetch/$s_!LQfO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbce0024-919f-4ddb-9035-7267f0b1370b_2021x329.png 848w, https://substackcdn.com/image/fetch/$s_!LQfO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbce0024-919f-4ddb-9035-7267f0b1370b_2021x329.png 1272w, https://substackcdn.com/image/fetch/$s_!LQfO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcbce0024-919f-4ddb-9035-7267f0b1370b_2021x329.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>If the client receives the exchange algorithm list from the server, it decides which algorithm to use. It searches for the algorithms that it prefers and that are contained in the algorithm list that the server sends. The paramiko library sets the first algorithm in the list for exchanging keys.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QYxx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79264cca-eab3-4db5-9990-e852569cf0ef_1123x776.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QYxx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79264cca-eab3-4db5-9990-e852569cf0ef_1123x776.png 424w, https://substackcdn.com/image/fetch/$s_!QYxx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79264cca-eab3-4db5-9990-e852569cf0ef_1123x776.png 848w, https://substackcdn.com/image/fetch/$s_!QYxx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79264cca-eab3-4db5-9990-e852569cf0ef_1123x776.png 1272w, https://substackcdn.com/image/fetch/$s_!QYxx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79264cca-eab3-4db5-9990-e852569cf0ef_1123x776.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QYxx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79264cca-eab3-4db5-9990-e852569cf0ef_1123x776.png" width="1123" height="776" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/79264cca-eab3-4db5-9990-e852569cf0ef_1123x776.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:776,&quot;width&quot;:1123,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:154053,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!QYxx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79264cca-eab3-4db5-9990-e852569cf0ef_1123x776.png 424w, https://substackcdn.com/image/fetch/$s_!QYxx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79264cca-eab3-4db5-9990-e852569cf0ef_1123x776.png 848w, https://substackcdn.com/image/fetch/$s_!QYxx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79264cca-eab3-4db5-9990-e852569cf0ef_1123x776.png 1272w, https://substackcdn.com/image/fetch/$s_!QYxx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79264cca-eab3-4db5-9990-e852569cf0ef_1123x776.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Here are the client's preferred key exchange algorithms. If you look at the packet from the server, you will see the&nbsp;<strong>curve25519-sha256@libssh.org</strong>. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hrNf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcdf83fe-5f76-400d-b46f-8dc813068345_1197x589.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hrNf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcdf83fe-5f76-400d-b46f-8dc813068345_1197x589.png 424w, https://substackcdn.com/image/fetch/$s_!hrNf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcdf83fe-5f76-400d-b46f-8dc813068345_1197x589.png 848w, https://substackcdn.com/image/fetch/$s_!hrNf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcdf83fe-5f76-400d-b46f-8dc813068345_1197x589.png 1272w, https://substackcdn.com/image/fetch/$s_!hrNf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcdf83fe-5f76-400d-b46f-8dc813068345_1197x589.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hrNf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcdf83fe-5f76-400d-b46f-8dc813068345_1197x589.png" width="1197" height="589" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fcdf83fe-5f76-400d-b46f-8dc813068345_1197x589.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:589,&quot;width&quot;:1197,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:116511,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hrNf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcdf83fe-5f76-400d-b46f-8dc813068345_1197x589.png 424w, https://substackcdn.com/image/fetch/$s_!hrNf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcdf83fe-5f76-400d-b46f-8dc813068345_1197x589.png 848w, https://substackcdn.com/image/fetch/$s_!hrNf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcdf83fe-5f76-400d-b46f-8dc813068345_1197x589.png 1272w, https://substackcdn.com/image/fetch/$s_!hrNf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffcdf83fe-5f76-400d-b46f-8dc813068345_1197x589.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2>3. Key Exchange with Diffie-Hellman algorithm</h2><p>Now that we have decided to use the <code>curve25519-sha256@libssh.org</code> method, the client generates the private key to exchange with the DH algorithm. Diffie-Hellman is a key exchange algorithm usually used to safely exchange keys for generating the symmetric key. In my test environment, it is using the Elliptic Curve Diffie-Hellman Key Exchange algorithm, but normal DH works similarly.</p><p>The client and server generate the private key, a random number. The x25519 private key is a cryptographic key used in the X25519 key exchange protocol based on elliptic curve cryptography. The server just waits after generating its own private key. </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Uz68!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4832aa02-20c1-4d7b-b845-725788026eca_924x234.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Uz68!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4832aa02-20c1-4d7b-b845-725788026eca_924x234.png 424w, https://substackcdn.com/image/fetch/$s_!Uz68!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4832aa02-20c1-4d7b-b845-725788026eca_924x234.png 848w, https://substackcdn.com/image/fetch/$s_!Uz68!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4832aa02-20c1-4d7b-b845-725788026eca_924x234.png 1272w, https://substackcdn.com/image/fetch/$s_!Uz68!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4832aa02-20c1-4d7b-b845-725788026eca_924x234.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Uz68!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4832aa02-20c1-4d7b-b845-725788026eca_924x234.png" width="924" height="234" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4832aa02-20c1-4d7b-b845-725788026eca_924x234.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:234,&quot;width&quot;:924,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:47802,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Uz68!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4832aa02-20c1-4d7b-b845-725788026eca_924x234.png 424w, https://substackcdn.com/image/fetch/$s_!Uz68!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4832aa02-20c1-4d7b-b845-725788026eca_924x234.png 848w, https://substackcdn.com/image/fetch/$s_!Uz68!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4832aa02-20c1-4d7b-b845-725788026eca_924x234.png 1272w, https://substackcdn.com/image/fetch/$s_!Uz68!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4832aa02-20c1-4d7b-b845-725788026eca_924x234.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>On the other hand, the client sends the KEXECDH_INIT message to exchange the key with the Elliptic Curve DH method. At this time, it calculates the public key, which is a point on the elliptic curve derived from the private key. After sending a message, it waits for the <code>KEXECDH_REPLY</code> message.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZOGb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9754c4c-656e-48f7-9a52-31309b157e02_1136x442.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZOGb!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9754c4c-656e-48f7-9a52-31309b157e02_1136x442.png 424w, https://substackcdn.com/image/fetch/$s_!ZOGb!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9754c4c-656e-48f7-9a52-31309b157e02_1136x442.png 848w, https://substackcdn.com/image/fetch/$s_!ZOGb!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9754c4c-656e-48f7-9a52-31309b157e02_1136x442.png 1272w, https://substackcdn.com/image/fetch/$s_!ZOGb!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9754c4c-656e-48f7-9a52-31309b157e02_1136x442.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZOGb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9754c4c-656e-48f7-9a52-31309b157e02_1136x442.png" width="1136" height="442" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a9754c4c-656e-48f7-9a52-31309b157e02_1136x442.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:442,&quot;width&quot;:1136,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:74431,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZOGb!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9754c4c-656e-48f7-9a52-31309b157e02_1136x442.png 424w, https://substackcdn.com/image/fetch/$s_!ZOGb!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9754c4c-656e-48f7-9a52-31309b157e02_1136x442.png 848w, https://substackcdn.com/image/fetch/$s_!ZOGb!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9754c4c-656e-48f7-9a52-31309b157e02_1136x442.png 1272w, https://substackcdn.com/image/fetch/$s_!ZOGb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa9754c4c-656e-48f7-9a52-31309b157e02_1136x442.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The server, waiting for the <code>KEXECDH_INIT</code> packet, receives the packet from the client. The public key is included in the packet capture, but it is not encrypted yet.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hvro!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43612bbf-94ef-4e60-a73e-cd485f5ee92e_1857x333.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hvro!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43612bbf-94ef-4e60-a73e-cd485f5ee92e_1857x333.png 424w, https://substackcdn.com/image/fetch/$s_!hvro!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43612bbf-94ef-4e60-a73e-cd485f5ee92e_1857x333.png 848w, https://substackcdn.com/image/fetch/$s_!hvro!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43612bbf-94ef-4e60-a73e-cd485f5ee92e_1857x333.png 1272w, https://substackcdn.com/image/fetch/$s_!hvro!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43612bbf-94ef-4e60-a73e-cd485f5ee92e_1857x333.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hvro!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43612bbf-94ef-4e60-a73e-cd485f5ee92e_1857x333.png" width="1456" height="261" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/43612bbf-94ef-4e60-a73e-cd485f5ee92e_1857x333.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:261,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:97847,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hvro!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43612bbf-94ef-4e60-a73e-cd485f5ee92e_1857x333.png 424w, https://substackcdn.com/image/fetch/$s_!hvro!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43612bbf-94ef-4e60-a73e-cd485f5ee92e_1857x333.png 848w, https://substackcdn.com/image/fetch/$s_!hvro!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43612bbf-94ef-4e60-a73e-cd485f5ee92e_1857x333.png 1272w, https://substackcdn.com/image/fetch/$s_!hvro!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F43612bbf-94ef-4e60-a73e-cd485f5ee92e_1857x333.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Now, the server parses the packet to initiate the ECDH exchange. First, it retrieves the public key value from the packet. Then, it calculates the shared secret with its private key. Then, it generates its public key from the private key and sends it to the client.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iIIH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1125c34-92b3-4023-925f-acf0238ba94d_1155x764.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iIIH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1125c34-92b3-4023-925f-acf0238ba94d_1155x764.png 424w, https://substackcdn.com/image/fetch/$s_!iIIH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1125c34-92b3-4023-925f-acf0238ba94d_1155x764.png 848w, https://substackcdn.com/image/fetch/$s_!iIIH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1125c34-92b3-4023-925f-acf0238ba94d_1155x764.png 1272w, https://substackcdn.com/image/fetch/$s_!iIIH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1125c34-92b3-4023-925f-acf0238ba94d_1155x764.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iIIH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1125c34-92b3-4023-925f-acf0238ba94d_1155x764.png" width="1155" height="764" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f1125c34-92b3-4023-925f-acf0238ba94d_1155x764.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:764,&quot;width&quot;:1155,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:165694,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iIIH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1125c34-92b3-4023-925f-acf0238ba94d_1155x764.png 424w, https://substackcdn.com/image/fetch/$s_!iIIH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1125c34-92b3-4023-925f-acf0238ba94d_1155x764.png 848w, https://substackcdn.com/image/fetch/$s_!iIIH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1125c34-92b3-4023-925f-acf0238ba94d_1155x764.png 1272w, https://substackcdn.com/image/fetch/$s_!iIIH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1125c34-92b3-4023-925f-acf0238ba94d_1155x764.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Here&#8217;s the server's reply packet. It sends its ephemeral public key and its public host key.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zY6L!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c3fd4db-5b0a-41a2-810f-79804e6ffcde_1988x548.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zY6L!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c3fd4db-5b0a-41a2-810f-79804e6ffcde_1988x548.png 424w, https://substackcdn.com/image/fetch/$s_!zY6L!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c3fd4db-5b0a-41a2-810f-79804e6ffcde_1988x548.png 848w, https://substackcdn.com/image/fetch/$s_!zY6L!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c3fd4db-5b0a-41a2-810f-79804e6ffcde_1988x548.png 1272w, https://substackcdn.com/image/fetch/$s_!zY6L!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c3fd4db-5b0a-41a2-810f-79804e6ffcde_1988x548.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zY6L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c3fd4db-5b0a-41a2-810f-79804e6ffcde_1988x548.png" width="1456" height="401" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5c3fd4db-5b0a-41a2-810f-79804e6ffcde_1988x548.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:401,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:169361,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!zY6L!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c3fd4db-5b0a-41a2-810f-79804e6ffcde_1988x548.png 424w, https://substackcdn.com/image/fetch/$s_!zY6L!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c3fd4db-5b0a-41a2-810f-79804e6ffcde_1988x548.png 848w, https://substackcdn.com/image/fetch/$s_!zY6L!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c3fd4db-5b0a-41a2-810f-79804e6ffcde_1988x548.png 1272w, https://substackcdn.com/image/fetch/$s_!zY6L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5c3fd4db-5b0a-41a2-810f-79804e6ffcde_1988x548.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The client, waiting for the rely, also tries to generate the shared secret. It retrieves the public key from the packet and computes the shared secret. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!IRZZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350e3654-e4f0-4cb4-8fb4-c79f9d18f9fc_1098x402.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IRZZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350e3654-e4f0-4cb4-8fb4-c79f9d18f9fc_1098x402.png 424w, https://substackcdn.com/image/fetch/$s_!IRZZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350e3654-e4f0-4cb4-8fb4-c79f9d18f9fc_1098x402.png 848w, https://substackcdn.com/image/fetch/$s_!IRZZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350e3654-e4f0-4cb4-8fb4-c79f9d18f9fc_1098x402.png 1272w, https://substackcdn.com/image/fetch/$s_!IRZZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350e3654-e4f0-4cb4-8fb4-c79f9d18f9fc_1098x402.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IRZZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350e3654-e4f0-4cb4-8fb4-c79f9d18f9fc_1098x402.png" width="1098" height="402" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/350e3654-e4f0-4cb4-8fb4-c79f9d18f9fc_1098x402.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:402,&quot;width&quot;:1098,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:74158,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!IRZZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350e3654-e4f0-4cb4-8fb4-c79f9d18f9fc_1098x402.png 424w, https://substackcdn.com/image/fetch/$s_!IRZZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350e3654-e4f0-4cb4-8fb4-c79f9d18f9fc_1098x402.png 848w, https://substackcdn.com/image/fetch/$s_!IRZZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350e3654-e4f0-4cb4-8fb4-c79f9d18f9fc_1098x402.png 1272w, https://substackcdn.com/image/fetch/$s_!IRZZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F350e3654-e4f0-4cb4-8fb4-c79f9d18f9fc_1098x402.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Here&#8217;s where the magic happens. </p><p>Even the calculation on the client side seems different from that on the server side because the client calculates the shared secret with its private key and the server&#8217;s public key, and the server does so with its private key and the client&#8217;s public key.</p><ul><li><p>Server: Server&#8217;s private key &amp; Client&#8217;s public key.</p></li><li><p>Client: Client&#8217;s private key &amp; Server&#8217;s public key</p></li></ul><p>Behind the scenes, the curve25519 algorithm contains the curve&#8217;s base point. Generating a public key from each side is the mathematical scala-multiplication of its private key and the curve's base point. This means the public key already contains the private key as the calculation. </p><ul><li><p>Server: Server&#8217;s private key &amp; (Client&#8217;s private key &amp; curve base point)</p></li><li><p>Client: Client&#8217;s private key &amp; (Server&#8217;s private key &amp; curve base point)</p></li></ul><p>In this case, both results are the same mathematically.</p><p></p><h2>4. Retrieves the in &amp; out key and IV</h2><p>Both sides have the same shared secret, so they can encrypt and decrypt with the symmetric key, which is the shared secret. The client and server retrieve the Initialization Vector(IV) and the encryption key for outbound traffic. Those values are used when each encrypts the outbound packet.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3lNt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d321208-d2f6-467b-9314-9e8efbdebb89_1125x587.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3lNt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d321208-d2f6-467b-9314-9e8efbdebb89_1125x587.png 424w, https://substackcdn.com/image/fetch/$s_!3lNt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d321208-d2f6-467b-9314-9e8efbdebb89_1125x587.png 848w, https://substackcdn.com/image/fetch/$s_!3lNt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d321208-d2f6-467b-9314-9e8efbdebb89_1125x587.png 1272w, https://substackcdn.com/image/fetch/$s_!3lNt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d321208-d2f6-467b-9314-9e8efbdebb89_1125x587.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3lNt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d321208-d2f6-467b-9314-9e8efbdebb89_1125x587.png" width="1125" height="587" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7d321208-d2f6-467b-9314-9e8efbdebb89_1125x587.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:587,&quot;width&quot;:1125,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!3lNt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d321208-d2f6-467b-9314-9e8efbdebb89_1125x587.png 424w, https://substackcdn.com/image/fetch/$s_!3lNt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d321208-d2f6-467b-9314-9e8efbdebb89_1125x587.png 848w, https://substackcdn.com/image/fetch/$s_!3lNt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d321208-d2f6-467b-9314-9e8efbdebb89_1125x587.png 1272w, https://substackcdn.com/image/fetch/$s_!3lNt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7d321208-d2f6-467b-9314-9e8efbdebb89_1125x587.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>You should know that they are not using the same key for inbound and outbound traffic. The code above shows that the client and server compute keys with different ID values. The order is changed for the inbound traffic.</p><p><code>_active_inbound</code> method is called when it gets a <code>NEW_KEYS</code> message. As you can see, IDs used in the client for outbound are the same as those used in the server for inbound. </p><ul><li><p>Client-side</p><ul><li><p>Encryption: Uses key derived from "C" and IV from "A"</p></li><li><p>Decryption: Uses key derived from "D" and IV from "B"</p></li></ul></li><li><p> Server-side</p><ul><li><p>Encryption: Uses key derived from "D" and IV from "B"</p></li><li><p>Decryption: Uses key derived from "C" and IV from "A"</p></li></ul></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OB2b!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485f7a94-3dad-41bc-be4c-7044c258b9c1_1254x763.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OB2b!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485f7a94-3dad-41bc-be4c-7044c258b9c1_1254x763.png 424w, https://substackcdn.com/image/fetch/$s_!OB2b!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485f7a94-3dad-41bc-be4c-7044c258b9c1_1254x763.png 848w, https://substackcdn.com/image/fetch/$s_!OB2b!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485f7a94-3dad-41bc-be4c-7044c258b9c1_1254x763.png 1272w, https://substackcdn.com/image/fetch/$s_!OB2b!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485f7a94-3dad-41bc-be4c-7044c258b9c1_1254x763.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OB2b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485f7a94-3dad-41bc-be4c-7044c258b9c1_1254x763.png" width="1254" height="763" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/485f7a94-3dad-41bc-be4c-7044c258b9c1_1254x763.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:763,&quot;width&quot;:1254,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:157317,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!OB2b!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485f7a94-3dad-41bc-be4c-7044c258b9c1_1254x763.png 424w, https://substackcdn.com/image/fetch/$s_!OB2b!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485f7a94-3dad-41bc-be4c-7044c258b9c1_1254x763.png 848w, https://substackcdn.com/image/fetch/$s_!OB2b!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485f7a94-3dad-41bc-be4c-7044c258b9c1_1254x763.png 1272w, https://substackcdn.com/image/fetch/$s_!OB2b!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F485f7a94-3dad-41bc-be4c-7044c258b9c1_1254x763.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Until now, both client and server have exchanged keys and calculated the ciphers for encryption and decryption. In the current session, all packets are encrypted with precalculated ciphers. If a new session is created, all exchange processes will happen again.</p><p></p><h2>5. Encrypt and decrypt the packet</h2><p>When the client sends the packet, it checks the self.<code>__block_engine_out</code> method. It is defined as retrieving keys from a shared secret. So, before exchanging the key, the packet is not encrypted.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Mq_6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4db874-33e6-48ed-96fe-bc66d26567f8_1105x1081.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Mq_6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4db874-33e6-48ed-96fe-bc66d26567f8_1105x1081.png 424w, https://substackcdn.com/image/fetch/$s_!Mq_6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4db874-33e6-48ed-96fe-bc66d26567f8_1105x1081.png 848w, https://substackcdn.com/image/fetch/$s_!Mq_6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4db874-33e6-48ed-96fe-bc66d26567f8_1105x1081.png 1272w, https://substackcdn.com/image/fetch/$s_!Mq_6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4db874-33e6-48ed-96fe-bc66d26567f8_1105x1081.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Mq_6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4db874-33e6-48ed-96fe-bc66d26567f8_1105x1081.png" width="1105" height="1081" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9b4db874-33e6-48ed-96fe-bc66d26567f8_1105x1081.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1081,&quot;width&quot;:1105,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:199190,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Mq_6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4db874-33e6-48ed-96fe-bc66d26567f8_1105x1081.png 424w, https://substackcdn.com/image/fetch/$s_!Mq_6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4db874-33e6-48ed-96fe-bc66d26567f8_1105x1081.png 848w, https://substackcdn.com/image/fetch/$s_!Mq_6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4db874-33e6-48ed-96fe-bc66d26567f8_1105x1081.png 1272w, https://substackcdn.com/image/fetch/$s_!Mq_6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4db874-33e6-48ed-96fe-bc66d26567f8_1105x1081.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>It&#8217;s the same when it gets an inbound packet. When it gets a packet from the other side, the read_message method is called. This method uses <code>__block_engine_in</code> to decrypt the packet.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jz_0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98d7d58f-c2fa-4f9c-b5b4-0d4678e6cc02_891x319.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jz_0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98d7d58f-c2fa-4f9c-b5b4-0d4678e6cc02_891x319.png 424w, https://substackcdn.com/image/fetch/$s_!jz_0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98d7d58f-c2fa-4f9c-b5b4-0d4678e6cc02_891x319.png 848w, https://substackcdn.com/image/fetch/$s_!jz_0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98d7d58f-c2fa-4f9c-b5b4-0d4678e6cc02_891x319.png 1272w, https://substackcdn.com/image/fetch/$s_!jz_0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98d7d58f-c2fa-4f9c-b5b4-0d4678e6cc02_891x319.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jz_0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98d7d58f-c2fa-4f9c-b5b4-0d4678e6cc02_891x319.png" width="891" height="319" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/98d7d58f-c2fa-4f9c-b5b4-0d4678e6cc02_891x319.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:319,&quot;width&quot;:891,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:59089,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jz_0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98d7d58f-c2fa-4f9c-b5b4-0d4678e6cc02_891x319.png 424w, https://substackcdn.com/image/fetch/$s_!jz_0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98d7d58f-c2fa-4f9c-b5b4-0d4678e6cc02_891x319.png 848w, https://substackcdn.com/image/fetch/$s_!jz_0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98d7d58f-c2fa-4f9c-b5b4-0d4678e6cc02_891x319.png 1272w, https://substackcdn.com/image/fetch/$s_!jz_0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F98d7d58f-c2fa-4f9c-b5b4-0d4678e6cc02_891x319.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h2>Conclusion</h2><p>In conclusion, when the SSH session is created via TCP, the client and server exchange keys to calculate the shared secret with the Diffie-Hellman algorithm. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LVdu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd09ca9-cf81-4267-bfee-aef0c21ea91c_732x1122.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LVdu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd09ca9-cf81-4267-bfee-aef0c21ea91c_732x1122.png 424w, https://substackcdn.com/image/fetch/$s_!LVdu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd09ca9-cf81-4267-bfee-aef0c21ea91c_732x1122.png 848w, https://substackcdn.com/image/fetch/$s_!LVdu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd09ca9-cf81-4267-bfee-aef0c21ea91c_732x1122.png 1272w, https://substackcdn.com/image/fetch/$s_!LVdu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd09ca9-cf81-4267-bfee-aef0c21ea91c_732x1122.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LVdu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd09ca9-cf81-4267-bfee-aef0c21ea91c_732x1122.png" width="732" height="1122" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ffd09ca9-cf81-4267-bfee-aef0c21ea91c_732x1122.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1122,&quot;width&quot;:732,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:94770,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!LVdu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd09ca9-cf81-4267-bfee-aef0c21ea91c_732x1122.png 424w, https://substackcdn.com/image/fetch/$s_!LVdu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd09ca9-cf81-4267-bfee-aef0c21ea91c_732x1122.png 848w, https://substackcdn.com/image/fetch/$s_!LVdu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd09ca9-cf81-4267-bfee-aef0c21ea91c_732x1122.png 1272w, https://substackcdn.com/image/fetch/$s_!LVdu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fffd09ca9-cf81-4267-bfee-aef0c21ea91c_732x1122.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>In the Diffie-Hellman key exchange algorithm, each generates the public key by multiplying its private key and a common random number. Those public keys don&#8217;t need to be hidden from the hacker. When the client and server exchange the public key, they calculate it with their private key. Then, they get the same shared secret to generate the encryption key. After setting up the encryption and decryption ciphers, they can encrypt and decrypt both inbound and outbound packets.</p><p></p>]]></content:encoded></item><item><title><![CDATA[__new__ & __init__: Zero to Expert]]></title><description><![CDATA[Dive deeper into __new__ and __init__]]></description><link>https://www.zerotoexpert.blog/p/__new__-and-__init__-zero-to-expert</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/__new__-and-__init__-zero-to-expert</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Tue, 23 Jul 2024 07:12:04 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!lGz8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd45fbdf-1c70-461e-9865-950037ed14ec_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lGz8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd45fbdf-1c70-461e-9865-950037ed14ec_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lGz8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd45fbdf-1c70-461e-9865-950037ed14ec_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!lGz8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd45fbdf-1c70-461e-9865-950037ed14ec_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!lGz8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd45fbdf-1c70-461e-9865-950037ed14ec_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!lGz8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd45fbdf-1c70-461e-9865-950037ed14ec_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lGz8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd45fbdf-1c70-461e-9865-950037ed14ec_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fd45fbdf-1c70-461e-9865-950037ed14ec_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:136758,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!lGz8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd45fbdf-1c70-461e-9865-950037ed14ec_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!lGz8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd45fbdf-1c70-461e-9865-950037ed14ec_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!lGz8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd45fbdf-1c70-461e-9865-950037ed14ec_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!lGz8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd45fbdf-1c70-461e-9865-950037ed14ec_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.zerotoexpert.blog/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Zero to Expert! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><div><hr></div><h2>Deep Dive into Class and Instance in Python</h2><p>In Python, you can create an object from the class to represent specific data and perform several actions. The data is presented as variables, and the actions are methods.</p><p>The simple User class has two variables and two different methods. It has a name and age as data. Also, it can perform &#8220;introduce&#8221; and &#8220;hello&#8221; with its own data. </p><pre><code>class User:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def introduce(self):
        return f"My name is {self.name} and I am {self.age} years old"

    def hello(self):
        return f"Hello, I am {self.name}"</code></pre><p><strong>You should know that this is</strong><em><strong> just a template </strong></em><strong>about the User.</strong> </p><p>The actual user should be created as an object with actual data. We usually call this an <strong>instance</strong>. An instance is an object made from the class with the actual data. Its shape is literally the same as the User class, but the difference is that it has the actual data. The methods are still tied to the class and are not copied to the instance.  </p><p>Let&#8217;s create some instances from the User class. I made two instances with a different variable name and age values. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6rTC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cc829d6-dfd5-4047-80ec-6c58936fca8c_1259x884.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6rTC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cc829d6-dfd5-4047-80ec-6c58936fca8c_1259x884.png 424w, https://substackcdn.com/image/fetch/$s_!6rTC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cc829d6-dfd5-4047-80ec-6c58936fca8c_1259x884.png 848w, https://substackcdn.com/image/fetch/$s_!6rTC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cc829d6-dfd5-4047-80ec-6c58936fca8c_1259x884.png 1272w, https://substackcdn.com/image/fetch/$s_!6rTC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cc829d6-dfd5-4047-80ec-6c58936fca8c_1259x884.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6rTC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cc829d6-dfd5-4047-80ec-6c58936fca8c_1259x884.png" width="1259" height="884" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2cc829d6-dfd5-4047-80ec-6c58936fca8c_1259x884.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:884,&quot;width&quot;:1259,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:133726,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6rTC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cc829d6-dfd5-4047-80ec-6c58936fca8c_1259x884.png 424w, https://substackcdn.com/image/fetch/$s_!6rTC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cc829d6-dfd5-4047-80ec-6c58936fca8c_1259x884.png 848w, https://substackcdn.com/image/fetch/$s_!6rTC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cc829d6-dfd5-4047-80ec-6c58936fca8c_1259x884.png 1272w, https://substackcdn.com/image/fetch/$s_!6rTC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cc829d6-dfd5-4047-80ec-6c58936fca8c_1259x884.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><pre><code>daniel = User("Daniel", 35)
emily = User("Emily", 20)

daniel.introduce()
emily.introduce()

# Result
--------------------------------
'My name is Daniel and I am 35 years old'
'My name is Emily and I am 20 years old'</code></pre><p>Now, let&#8217;s check how the <code>introduce</code> function works internally. If you print the function without calling it, you can see which function is bound to it. As you can see from the result below, it is tied to the method <code>User.introduce</code>, and the object is 0x103be9eb0, which is the id of the Daniel object.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QGRq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F077b7140-ed5c-4d8d-b954-10b59876c6a8_1164x184.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QGRq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F077b7140-ed5c-4d8d-b954-10b59876c6a8_1164x184.png 424w, https://substackcdn.com/image/fetch/$s_!QGRq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F077b7140-ed5c-4d8d-b954-10b59876c6a8_1164x184.png 848w, https://substackcdn.com/image/fetch/$s_!QGRq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F077b7140-ed5c-4d8d-b954-10b59876c6a8_1164x184.png 1272w, https://substackcdn.com/image/fetch/$s_!QGRq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F077b7140-ed5c-4d8d-b954-10b59876c6a8_1164x184.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QGRq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F077b7140-ed5c-4d8d-b954-10b59876c6a8_1164x184.png" width="1164" height="184" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/077b7140-ed5c-4d8d-b954-10b59876c6a8_1164x184.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:184,&quot;width&quot;:1164,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:38022,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!QGRq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F077b7140-ed5c-4d8d-b954-10b59876c6a8_1164x184.png 424w, https://substackcdn.com/image/fetch/$s_!QGRq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F077b7140-ed5c-4d8d-b954-10b59876c6a8_1164x184.png 848w, https://substackcdn.com/image/fetch/$s_!QGRq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F077b7140-ed5c-4d8d-b954-10b59876c6a8_1164x184.png 1272w, https://substackcdn.com/image/fetch/$s_!QGRq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F077b7140-ed5c-4d8d-b954-10b59876c6a8_1164x184.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>This means that I can call the function like this.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fYU4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6b125cf-541a-42ea-9e9c-1eec4af523af_700x139.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fYU4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6b125cf-541a-42ea-9e9c-1eec4af523af_700x139.png 424w, https://substackcdn.com/image/fetch/$s_!fYU4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6b125cf-541a-42ea-9e9c-1eec4af523af_700x139.png 848w, https://substackcdn.com/image/fetch/$s_!fYU4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6b125cf-541a-42ea-9e9c-1eec4af523af_700x139.png 1272w, https://substackcdn.com/image/fetch/$s_!fYU4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6b125cf-541a-42ea-9e9c-1eec4af523af_700x139.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fYU4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6b125cf-541a-42ea-9e9c-1eec4af523af_700x139.png" width="700" height="139" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f6b125cf-541a-42ea-9e9c-1eec4af523af_700x139.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:139,&quot;width&quot;:700,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:17890,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fYU4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6b125cf-541a-42ea-9e9c-1eec4af523af_700x139.png 424w, https://substackcdn.com/image/fetch/$s_!fYU4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6b125cf-541a-42ea-9e9c-1eec4af523af_700x139.png 848w, https://substackcdn.com/image/fetch/$s_!fYU4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6b125cf-541a-42ea-9e9c-1eec4af523af_700x139.png 1272w, https://substackcdn.com/image/fetch/$s_!fYU4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff6b125cf-541a-42ea-9e9c-1eec4af523af_700x139.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>See? The same result came out. </p><p><em>What would happen if I changed the method in the class after creating the instance?</em></p><p>Let&#8217;s change the <code>introduce</code> method to return a different string. As you might guess, the instance method has been changed as well. This is simply because the instance method is actually bound to the class. A class function is called with the instance as a function parameter. </p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!m8A0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd60444b4-bdc0-4c95-9c08-7912cc9470e9_935x234.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!m8A0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd60444b4-bdc0-4c95-9c08-7912cc9470e9_935x234.png 424w, https://substackcdn.com/image/fetch/$s_!m8A0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd60444b4-bdc0-4c95-9c08-7912cc9470e9_935x234.png 848w, https://substackcdn.com/image/fetch/$s_!m8A0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd60444b4-bdc0-4c95-9c08-7912cc9470e9_935x234.png 1272w, https://substackcdn.com/image/fetch/$s_!m8A0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd60444b4-bdc0-4c95-9c08-7912cc9470e9_935x234.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!m8A0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd60444b4-bdc0-4c95-9c08-7912cc9470e9_935x234.png" width="935" height="234" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d60444b4-bdc0-4c95-9c08-7912cc9470e9_935x234.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:234,&quot;width&quot;:935,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:45357,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!m8A0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd60444b4-bdc0-4c95-9c08-7912cc9470e9_935x234.png 424w, https://substackcdn.com/image/fetch/$s_!m8A0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd60444b4-bdc0-4c95-9c08-7912cc9470e9_935x234.png 848w, https://substackcdn.com/image/fetch/$s_!m8A0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd60444b4-bdc0-4c95-9c08-7912cc9470e9_935x234.png 1272w, https://substackcdn.com/image/fetch/$s_!m8A0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd60444b4-bdc0-4c95-9c08-7912cc9470e9_935x234.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>This is why we add <code>self</code> to the instance method. Internally, calling the instance method is the same as calling a class function with an instance as a parameter.</p><pre><code>daniel.introduce() == User.introduce(daniel)</code></pre><h3></h3><h3>What is the __new__ method?</h3><p>The object is made based on the class definition when you create the instance. Some might have learned that the __init__ method is used to create an instance, but it&#8217;s wrong. It is just the initialization method that is called after the instance is created. The actual method to create an instance is the __new__ method.</p><p>Let&#8217;s create the instance using the __new__ method. </p><pre><code>class User:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def introduce(self):
        return f"My name is {self.name} and I am {self.age} years old"

    def hello(self):
        return f"Hello!!"

mark = User.__new__(User)
print(mark.__dict__)
print(type(mark))
print(isinstance(mark, User))
print(mark.hello())


# Result
--------------------------------
{}
&lt;class '__main__.User'&gt;
True
Hello!!</code></pre><p>The instance named mark was created successfully but has no data inside the __dict__ variable. However, the hello function is available because it is an instance of the User class. If you want to give it a name and age, you should call the __init__ method. This is how Python creates the instance and initializes the data of that instance.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Vc8L!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F149238b7-78df-43d2-a02f-3b5671a12978_720x213.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Vc8L!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F149238b7-78df-43d2-a02f-3b5671a12978_720x213.png 424w, https://substackcdn.com/image/fetch/$s_!Vc8L!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F149238b7-78df-43d2-a02f-3b5671a12978_720x213.png 848w, https://substackcdn.com/image/fetch/$s_!Vc8L!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F149238b7-78df-43d2-a02f-3b5671a12978_720x213.png 1272w, https://substackcdn.com/image/fetch/$s_!Vc8L!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F149238b7-78df-43d2-a02f-3b5671a12978_720x213.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Vc8L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F149238b7-78df-43d2-a02f-3b5671a12978_720x213.png" width="720" height="213" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/149238b7-78df-43d2-a02f-3b5671a12978_720x213.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:213,&quot;width&quot;:720,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:25226,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Vc8L!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F149238b7-78df-43d2-a02f-3b5671a12978_720x213.png 424w, https://substackcdn.com/image/fetch/$s_!Vc8L!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F149238b7-78df-43d2-a02f-3b5671a12978_720x213.png 848w, https://substackcdn.com/image/fetch/$s_!Vc8L!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F149238b7-78df-43d2-a02f-3b5671a12978_720x213.png 1272w, https://substackcdn.com/image/fetch/$s_!Vc8L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F149238b7-78df-43d2-a02f-3b5671a12978_720x213.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h3></h3><h3>How does __new__ and __init__ works internally</h3><p>When you create a class, it actually inherits the <strong>object</strong> type. Object type is the base class that CPython manages. So, when you make a new type by making the class, it inherits an object and calls it an object.__new__ method.</p><p>First, when you create the class, it actually calls the type() function internally. The type function is used to create a custom type like a class. If the type is well created, you create an instance with that type, which is the class here.</p><p>In CPython, type_call is the function called when you create an instance with a class type like User().  In this function, <strong>type&#8594;tp_new</strong> is called. After that,&nbsp;<strong>type&#8594;tp_init</strong>&nbsp;is called, and the object is passed as a parameter.</p><pre><code>static PyObject *
type_call(PyObject *self, PyObject *args, PyObject *kwds)
{
    PyTypeObject *type = (PyTypeObject *)self;
    PyObject *obj;

    //(... skipped ...) 

    obj = type-&gt;tp_new(type, args, kwds);
    obj = _Py_CheckFunctionResult(tstate, (PyObject*)type, obj, NULL);
    if (obj == NULL)
        return NULL;

    //(... skipped ...) 

    type = Py_TYPE(obj);
    if (type-&gt;tp_init != NULL) {
        int res = type-&gt;tp_init(obj, args, kwds);
        
        //(... skipped ...) 
    }
    return obj;
}</code></pre><p>You can ensure that the tp_init is called after creating the object with the tp_new function. Now, we need to find out the actual code of tp_new for the object type.</p><p>Here&#8217;s the CPython code that defines the object type. The tp_new function is mapped with the <strong>object_new</strong> function.</p><pre><code>PyTypeObject PyBaseObject_Type = {
    PyVarObject_HEAD_INIT(&amp;PyType_Type, 0)
    "object",                                   /* tp_name */
    sizeof(PyObject),                           /* tp_basicsize */
    // ( ... skip ... )
    object_init,                                /* tp_init */
    object_new,                                 /* tp_new */
};</code></pre><p>Let&#8217;s examine the <strong>object_new</strong> function to discover what happens inside the __new__ method.  </p><pre><code>static PyObject *
object_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
    // (...skipped...)

    PyObject *obj = type-&gt;tp_alloc(type, 0);
    if (obj == NULL) {
        return NULL;
    }
    return obj;
}</code></pre><p><strong>&#8220;It just allocates the object's memory.&#8221;</strong></p><p>Now, you can assume that no matter what type your class type inherits, you should make it call the object.__new__ method to allocate the memory for the class. If you do not call the object.__new__ method, then it does not call __init__ method because type_call checks the return object type. </p><p>You can test this by customizing the __new__ method for the base type. Here&#8217;s an example. I made two classes and inherited A from B. When super().__new__(cls) line is executed, it calls the __new__ method in class A. But the __new__ method of class A returns the string type. So, the __init__ method is not called.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!vgwU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabf2ef1f-5012-43b9-b703-e7a2c56ec4ac_939x720.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vgwU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabf2ef1f-5012-43b9-b703-e7a2c56ec4ac_939x720.png 424w, https://substackcdn.com/image/fetch/$s_!vgwU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabf2ef1f-5012-43b9-b703-e7a2c56ec4ac_939x720.png 848w, https://substackcdn.com/image/fetch/$s_!vgwU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabf2ef1f-5012-43b9-b703-e7a2c56ec4ac_939x720.png 1272w, https://substackcdn.com/image/fetch/$s_!vgwU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabf2ef1f-5012-43b9-b703-e7a2c56ec4ac_939x720.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vgwU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabf2ef1f-5012-43b9-b703-e7a2c56ec4ac_939x720.png" width="939" height="720" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/abf2ef1f-5012-43b9-b703-e7a2c56ec4ac_939x720.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:720,&quot;width&quot;:939,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:84067,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!vgwU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabf2ef1f-5012-43b9-b703-e7a2c56ec4ac_939x720.png 424w, https://substackcdn.com/image/fetch/$s_!vgwU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabf2ef1f-5012-43b9-b703-e7a2c56ec4ac_939x720.png 848w, https://substackcdn.com/image/fetch/$s_!vgwU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabf2ef1f-5012-43b9-b703-e7a2c56ec4ac_939x720.png 1272w, https://substackcdn.com/image/fetch/$s_!vgwU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fabf2ef1f-5012-43b9-b703-e7a2c56ec4ac_939x720.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h3>Summary</h3><p>Here&#8217;s the overall process for creating the class and the instance. Remember that the __init__ method is just for initializing the instance. The __new__ method creates the instance itself in memory.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!BLjP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ae584e-6362-4f88-80c2-b87831f6d520_1189x2091.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!BLjP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ae584e-6362-4f88-80c2-b87831f6d520_1189x2091.png 424w, https://substackcdn.com/image/fetch/$s_!BLjP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ae584e-6362-4f88-80c2-b87831f6d520_1189x2091.png 848w, https://substackcdn.com/image/fetch/$s_!BLjP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ae584e-6362-4f88-80c2-b87831f6d520_1189x2091.png 1272w, https://substackcdn.com/image/fetch/$s_!BLjP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ae584e-6362-4f88-80c2-b87831f6d520_1189x2091.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!BLjP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ae584e-6362-4f88-80c2-b87831f6d520_1189x2091.png" width="1189" height="2091" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/52ae584e-6362-4f88-80c2-b87831f6d520_1189x2091.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2091,&quot;width&quot;:1189,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:187896,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!BLjP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ae584e-6362-4f88-80c2-b87831f6d520_1189x2091.png 424w, https://substackcdn.com/image/fetch/$s_!BLjP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ae584e-6362-4f88-80c2-b87831f6d520_1189x2091.png 848w, https://substackcdn.com/image/fetch/$s_!BLjP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ae584e-6362-4f88-80c2-b87831f6d520_1189x2091.png 1272w, https://substackcdn.com/image/fetch/$s_!BLjP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F52ae584e-6362-4f88-80c2-b87831f6d520_1189x2091.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p>]]></content:encoded></item><item><title><![CDATA[Algorithm Challenges #2]]></title><description><![CDATA[Leetcode problems]]></description><link>https://www.zerotoexpert.blog/p/algorithm-challenges-2</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/algorithm-challenges-2</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Mon, 22 Jul 2024 18:14:37 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!SgTa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae11481b-76da-434e-b5bc-424bf0e43819_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SgTa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae11481b-76da-434e-b5bc-424bf0e43819_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SgTa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae11481b-76da-434e-b5bc-424bf0e43819_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!SgTa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae11481b-76da-434e-b5bc-424bf0e43819_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!SgTa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae11481b-76da-434e-b5bc-424bf0e43819_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!SgTa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae11481b-76da-434e-b5bc-424bf0e43819_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SgTa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae11481b-76da-434e-b5bc-424bf0e43819_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ae11481b-76da-434e-b5bc-424bf0e43819_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:138063,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SgTa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae11481b-76da-434e-b5bc-424bf0e43819_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!SgTa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae11481b-76da-434e-b5bc-424bf0e43819_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!SgTa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae11481b-76da-434e-b5bc-424bf0e43819_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!SgTa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fae11481b-76da-434e-b5bc-424bf0e43819_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h3>1. Build a Matrix With Conditions</h3><p>link: https://leetcode.com/problems/build-a-matrix-with-conditions/description</p><div><hr></div><p>This problem states that we must find a matrix that meets the row and column conditions. Each condition contains the order of numbers that should appear from top to bottom and from left to right. For example, if one of the row conditions is [2, 3], 2 should appear upper than 3. If one of the column conditions is [2, 3], 2 should appear on the left of 3.</p><p>Even though it is a k-by-k matrix, let&#8217;s consider it one dimension. We can solve the problem only with the row conditions first.</p><p>No matter how many conditions are provided, we only have k numbers. Matrix also has k rows. This means we can ensure that each number is placed in each row. So, we don&#8217;t need to consider the case of two numbers located in the same row.</p><p>We need to solve the order in which the numbers are placed. This problem has now been changed to a graph problem. A similar situation is finding the order of classes I should take when the prerequisites of each class are provided. To solve this problem, we can use the <strong>topology sort algorithm</strong>&nbsp;to get orders from graphs.</p><p>One thing we need to check here is the case that has the cycle. 1 &#8594; 2 &#8594; 3 &#8594; 1 is one case with the cycle because 3 should be placed above 1, but 1 should be above 3, too. This cannot happen! If this case is found, we should return an empty list as the answer.</p><p>So, we can use a color mechanism to check if the current number is in progress or completed. Let&#8217;s assume that color 0 means ready state. If we start finding orders of nodes with connected edges, then let&#8217;s change the color to 1. If all connected edges are well ordered, add the current node to the array and change the color to 2. </p><p>While processing each number, we can check the current color to see if the number is in progress. If the color of the number is 1, we face the cycle! In this case, we can return None to detect the cycle case.</p><p>Now, we can get the order of k numbers that meet the row conditions. With the same logic, we also need to get the order of k numbers that meet the column conditions. After that, we can just place the number i in the position of row order[i] and column order[i].</p><p>Here&#8217;s the code.</p><ul><li><p>Time complexity is O(K+E), where E is the number of edges in the graph. But it excludes the initialization of the matrix for the answer. </p></li><li><p>Space complexity is O(K+E), where E is the number of edges in the graph.</p></li></ul><pre><code>&nbsp;class Solution:
    def buildMatrix(self, k: int, rowConditions: List[List[int]], colConditions: List[List[int]]) -&gt; List[List[int]]:
        def topsort(g, node, colors, ret):
            if colors[node] == 1:
                return False
            if colors[node] == 2:
                return True
            colors[node] = 1
            for ne in g[node]:
                if not topsort(g, ne, colors, ret):
                    return False
            colors[node] = 2
            ret.append(node)
            return True
            
        def make_graph(arr, k):
            g = defaultdict(list)
            s = set(list(range(1,k+1)))
            for p, q in arr:
                g[p].append(q)
            ret = []
            colors = [0 for _ in range(k+1)]
            for e in s:
                if not topsort(g, e, colors, ret):
                    return None
            ret.reverse()
            return { v: i for i, v in enumerate(ret) }
        row = make_graph(rowConditions, k)
        col = make_graph(colConditions, k)
        
        if not row or not col:
            return []
            
        ans = [[0 for _ in range(k) ] for _ in range(k)]
        for i in range(1, k+1):
            ans[row[i]][col[i]] = i

        return ans
        </code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sqE2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e31e01-f196-4ad4-bbe5-21068eaaf9f3_1460x874.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sqE2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e31e01-f196-4ad4-bbe5-21068eaaf9f3_1460x874.png 424w, https://substackcdn.com/image/fetch/$s_!sqE2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e31e01-f196-4ad4-bbe5-21068eaaf9f3_1460x874.png 848w, https://substackcdn.com/image/fetch/$s_!sqE2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e31e01-f196-4ad4-bbe5-21068eaaf9f3_1460x874.png 1272w, https://substackcdn.com/image/fetch/$s_!sqE2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e31e01-f196-4ad4-bbe5-21068eaaf9f3_1460x874.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sqE2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e31e01-f196-4ad4-bbe5-21068eaaf9f3_1460x874.png" width="1456" height="872" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c5e31e01-f196-4ad4-bbe5-21068eaaf9f3_1460x874.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:872,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:105442,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sqE2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e31e01-f196-4ad4-bbe5-21068eaaf9f3_1460x874.png 424w, https://substackcdn.com/image/fetch/$s_!sqE2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e31e01-f196-4ad4-bbe5-21068eaaf9f3_1460x874.png 848w, https://substackcdn.com/image/fetch/$s_!sqE2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e31e01-f196-4ad4-bbe5-21068eaaf9f3_1460x874.png 1272w, https://substackcdn.com/image/fetch/$s_!sqE2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5e31e01-f196-4ad4-bbe5-21068eaaf9f3_1460x874.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><h3>2. Find a Valid Matrix Given Row and Column Sums</h3><p>Link: https://leetcode.com/problems/find-valid-matrix-given-row-and-column-sums/description</p><div><hr></div><p>The problem states that we should fill the matrix that meets the row and column conditions. Row and column conditions contain the sum of each row and column. </p><p>Here&#8217;s an example. Let&#8217;s say the sum of the first column is 5, and the sum of the second row is 8. Then, you can fill in the number like this to meet those two conditions.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!WtdX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb992e36f-b3b6-4594-b2f1-99659e8e1772_1251x1368.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!WtdX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb992e36f-b3b6-4594-b2f1-99659e8e1772_1251x1368.png 424w, https://substackcdn.com/image/fetch/$s_!WtdX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb992e36f-b3b6-4594-b2f1-99659e8e1772_1251x1368.png 848w, https://substackcdn.com/image/fetch/$s_!WtdX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb992e36f-b3b6-4594-b2f1-99659e8e1772_1251x1368.png 1272w, https://substackcdn.com/image/fetch/$s_!WtdX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb992e36f-b3b6-4594-b2f1-99659e8e1772_1251x1368.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!WtdX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb992e36f-b3b6-4594-b2f1-99659e8e1772_1251x1368.png" width="1251" height="1368" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b992e36f-b3b6-4594-b2f1-99659e8e1772_1251x1368.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1368,&quot;width&quot;:1251,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:356214,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!WtdX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb992e36f-b3b6-4594-b2f1-99659e8e1772_1251x1368.png 424w, https://substackcdn.com/image/fetch/$s_!WtdX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb992e36f-b3b6-4594-b2f1-99659e8e1772_1251x1368.png 848w, https://substackcdn.com/image/fetch/$s_!WtdX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb992e36f-b3b6-4594-b2f1-99659e8e1772_1251x1368.png 1272w, https://substackcdn.com/image/fetch/$s_!WtdX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb992e36f-b3b6-4594-b2f1-99659e8e1772_1251x1368.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>If you think about this problem for a while, you will easily find that you can fill the number greedily. It&#8217;s because the overall sum is always the same and there is no other constraints to distribute the number except for the sum.</p><p>This means we can iterate the rows and distribute the number row[i] greedily to columns. For example, if row[0] is 10, we can fill the column[0] to 10 if possible. If column[0] is smaller than 10, we can fill the rest of the number to column[1].</p><p></p><p>Here&#8217;s the simple code.</p><ul><li><p>Time complexity is O(N*M), where N is the number of rows, and M is the number of columns.</p></li><li><p>Space complexity is O(N*M) because of the list for the answer.</p></li></ul><pre><code>class Solution:
    def restoreMatrix(self, rowSum: List[int], colSum: List[int]) -&gt; List[List[int]]:
        n = len(rowSum)
        m = len(colSum)
        ans = [[0 for _ in range(m)] for _ in range(n)]

        curr_idx = 0
        for i in range(n):
            value = rowSum[i]
            while curr_idx &lt; m and value &gt; 0:
                can = min(colSum[curr_idx], value)
                colSum[curr_idx] -= can
                value -= can
                ans[i][curr_idx] = can
                if colSum[curr_idx] == 0:
                    curr_idx += 1
        return ans</code></pre><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RU94!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3467c48a-ce3d-4604-9218-22bea032c300_1475x913.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RU94!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3467c48a-ce3d-4604-9218-22bea032c300_1475x913.png 424w, https://substackcdn.com/image/fetch/$s_!RU94!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3467c48a-ce3d-4604-9218-22bea032c300_1475x913.png 848w, https://substackcdn.com/image/fetch/$s_!RU94!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3467c48a-ce3d-4604-9218-22bea032c300_1475x913.png 1272w, https://substackcdn.com/image/fetch/$s_!RU94!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3467c48a-ce3d-4604-9218-22bea032c300_1475x913.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RU94!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3467c48a-ce3d-4604-9218-22bea032c300_1475x913.png" width="1456" height="901" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3467c48a-ce3d-4604-9218-22bea032c300_1475x913.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:901,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:106187,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!RU94!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3467c48a-ce3d-4604-9218-22bea032c300_1475x913.png 424w, https://substackcdn.com/image/fetch/$s_!RU94!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3467c48a-ce3d-4604-9218-22bea032c300_1475x913.png 848w, https://substackcdn.com/image/fetch/$s_!RU94!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3467c48a-ce3d-4604-9218-22bea032c300_1475x913.png 1272w, https://substackcdn.com/image/fetch/$s_!RU94!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3467c48a-ce3d-4604-9218-22bea032c300_1475x913.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p>]]></content:encoded></item><item><title><![CDATA[Performance Insights]]></title><description><![CDATA[&#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#47784;&#45768;&#53552;&#47553;&#51012; &#50948;&#54620; &#54140;&#54252;&#47676;&#49828; &#51064;&#49324;&#51060;&#53944;&#50640; &#45824;&#54644; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/performance-insights</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/performance-insights</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Mon, 22 Jul 2024 05:17:19 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!jYLr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F326724aa-a140-460e-8e06-299888f15dc3_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jYLr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F326724aa-a140-460e-8e06-299888f15dc3_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jYLr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F326724aa-a140-460e-8e06-299888f15dc3_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!jYLr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F326724aa-a140-460e-8e06-299888f15dc3_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!jYLr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F326724aa-a140-460e-8e06-299888f15dc3_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!jYLr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F326724aa-a140-460e-8e06-299888f15dc3_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jYLr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F326724aa-a140-460e-8e06-299888f15dc3_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/326724aa-a140-460e-8e06-299888f15dc3_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:390807,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jYLr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F326724aa-a140-460e-8e06-299888f15dc3_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!jYLr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F326724aa-a140-460e-8e06-299888f15dc3_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!jYLr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F326724aa-a140-460e-8e06-299888f15dc3_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!jYLr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F326724aa-a140-460e-8e06-299888f15dc3_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Amazon RDS Performance Insights&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49457;&#45733;&#51012; &#47784;&#45768;&#53552;&#47553;&#54616;&#44256; &#52572;&#51201;&#54868;&#54616;&#45716; &#45936; &#46020;&#50880;&#51012; &#51452;&#45716; &#44053;&#47141;&#54620; &#46020;&#44396;&#51060;&#45796;. &#51060; &#49436;&#48708;&#49828;&#45716; &#48373;&#51105;&#54620; &#49457;&#45733; &#47928;&#51228;&#47484; &#49884;&#44033;&#51201;&#51004;&#47196; &#49789;&#44172; &#51060;&#54644;&#54624; &#49688; &#51080;&#46020;&#47197; &#45936;&#51060;&#53552;&#47484; &#49884;&#44033;&#54868;&#54616;&#44256;, &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#51064;&#49828;&#53556;&#49828;&#51032; &#54876;&#46041;&#51012; &#49892;&#49884;&#44036;&#51004;&#47196; &#48516;&#49437;&#54616;&#50668; &#48337;&#47785; &#54788;&#49345;&#51012; &#49885;&#48324;&#54616;&#44256; &#54644;&#44208;&#54624; &#49688; &#51080;&#46020;&#47197; &#46037;&#45716;&#45796;.</p><p>Performance Insights&#45716; RDS &#51064;&#49828;&#53556;&#49828;&#51032; &#49457;&#45733; &#45936;&#51060;&#53552;&#47484; &#49688;&#51665;&#54616;&#50668; CPU &#49324;&#50857;&#47049;, &#47700;&#47784;&#47532; &#49324;&#50857;&#47049;, &#46356;&#49828;&#53356; I/O, &#53244;&#47532; &#49457;&#45733; &#46321;&#51012; &#47784;&#45768;&#53552;&#47553;&#54620;&#45796;. &#51060;&#47084;&#54620; &#45936;&#51060;&#53552;&#47484; &#53685;&#54644; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#51064;&#49828;&#53556;&#49828;&#51032; &#49457;&#45733; &#49345;&#53468;&#47484; &#49892;&#49884;&#44036;&#51004;&#47196; &#54028;&#50501;&#54624; &#49688; &#51080;&#51004;&#47728;, &#49457;&#45733; &#47928;&#51228;&#51032; &#50896;&#51064;&#51012; &#48736;&#47476;&#44172; &#49885;&#48324;&#54624; &#49688; &#51080;&#45796;.</p><p><strong>Performance Insights&#51032; &#51452;&#50836; &#44592;&#45733; &#51473; &#54616;&#45208;&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#48512;&#54616; &#48516;&#49437;</strong>&#51060;&#45796;. &#51060; &#46020;&#44396;&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#51064;&#49828;&#53556;&#49828;&#51032; &#54876;&#46041;&#51012; &#45796;&#50577;&#54620; &#44288;&#51216;&#50640;&#49436; &#48516;&#49437;&#54624; &#49688; &#51080;&#46020;&#47197; &#51648;&#50896;&#54616;&#47728;, SQL &#53244;&#47532;, &#45824;&#44592; &#51060;&#48292;&#53944;, &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#45236;&#48512; &#54876;&#46041; &#46321;&#51012; &#49884;&#44033;&#51201;&#51004;&#47196; &#48372;&#50668;&#51456;&#45796;. &#51060;&#47484; &#53685;&#54644; &#49324;&#50857;&#51088;&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49457;&#45733;&#50640; &#50689;&#54693;&#51012; &#48120;&#52824;&#45716; &#51452;&#50836; &#50836;&#49548;&#47484; &#49789;&#44172; &#49885;&#48324;&#54616;&#44256;, &#49457;&#45733; &#52572;&#51201;&#54868;&#47484; &#50948;&#54620; &#44396;&#52404;&#51201;&#51064; &#51312;&#52824;&#47484; &#52712;&#54624; &#49688; &#51080;&#45796;.</p><p>Performance Insights&#47484; &#49324;&#50857;&#54616;&#44592; &#50948;&#54644;&#49436;&#45716; AWS Management Console, AWS CLI, &#46608;&#45716; AWS SDK&#47484; &#53685;&#54644; RDS &#51064;&#49828;&#53556;&#49828;&#50640;&#49436; &#51060; &#44592;&#45733;&#51012; &#54876;&#49457;&#54868;&#54644;&#50556; &#54620;&#45796;. &#54876;&#49457;&#54868;&#46108; &#54980;&#50640;&#45716; Performance Insights &#45824;&#49884;&#48372;&#46300;&#50640;&#49436; &#49457;&#45733; &#45936;&#51060;&#53552;&#47484; &#49892;&#49884;&#44036;&#51004;&#47196; &#54869;&#51064;&#54624; &#49688; &#51080;&#51004;&#47728;, &#51648;&#45212; &#49884;&#44036; &#46041;&#50504;&#51032; &#49457;&#45733; &#48320;&#54868;&#47484; &#49884;&#44033;&#51201;&#51004;&#47196; &#48516;&#49437;&#54624; &#49688; &#51080;&#45796;. &#45824;&#49884;&#48372;&#46300;&#50640;&#49436;&#45716; &#51452;&#50836; &#49457;&#45733; &#51648;&#54364;&#50752; &#54632;&#44760;, SQL &#53244;&#47532;&#51032; &#49892;&#54665; &#49884;&#44036;, &#45824;&#44592; &#51060;&#48292;&#53944;&#51032; &#48712;&#46020;, &#47532;&#49548;&#49828; &#49324;&#50857;&#47049; &#46321;&#51012; &#49345;&#49464;&#55176; &#48380; &#49688; &#51080;&#45796;.</p><p>&#49457;&#45733; &#47928;&#51228;&#47484; &#51652;&#45800;&#54624; &#46412;&#45716; &#45796;&#51020;&#44284; &#44057;&#51008; &#51452;&#50836; &#51648;&#54364;&#50752; &#47700;&#53944;&#47533;&#51012; &#54876;&#50857;&#54624; &#49688; &#51080;&#45796;:</p><ol><li><p><strong>DB Load</strong>: &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#48512;&#54616;&#45716; &#51064;&#49828;&#53556;&#49828;&#51032; &#51204;&#52404; &#49457;&#45733; &#49345;&#53468;&#47484; &#45208;&#53440;&#45236;&#45716; &#51648;&#54364;&#47196;, CPU &#49324;&#50857;&#47049;, &#45824;&#44592; &#49884;&#44036;, &#49828;&#53664;&#47532;&#51648; I/O &#46321;&#51012; &#54252;&#54632;&#54620;&#45796;. DB Load &#44536;&#47000;&#54532;&#47484; &#53685;&#54644; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#48512;&#54616;&#51032; &#48320;&#54868; &#52628;&#51060;&#47484; &#49884;&#44033;&#51201;&#51004;&#47196; &#54869;&#51064;&#54624; &#49688; &#51080;&#45796;.</p></li><li><p><strong>Top SQL Queries</strong>: &#44032;&#51109; &#47566;&#51008; &#47532;&#49548;&#49828;&#47484; &#49548;&#48708;&#54616;&#45716; SQL &#53244;&#47532;&#47484; &#49885;&#48324;&#54624; &#49688; &#51080;&#45796;. &#51060; &#44592;&#45733;&#51008; &#49892;&#54665; &#49884;&#44036;&#51060; &#44596; &#53244;&#47532;, &#51088;&#51452; &#49892;&#54665;&#46104;&#45716; &#53244;&#47532;, &#45824;&#44592; &#49884;&#44036;&#51060; &#44596; &#53244;&#47532; &#46321;&#51012; &#48372;&#50668;&#51452;&#50612; &#53244;&#47532; &#52572;&#51201;&#54868;&#51032; &#50864;&#49440;&#49692;&#50948;&#47484; &#51221;&#54616;&#45716; &#45936; &#46020;&#50880;&#51012; &#51456;&#45796;.</p></li><li><p><strong>Wait Events</strong>: &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#44032; &#51089;&#50629;&#51012; &#52376;&#47532;&#54616;&#45716; &#46041;&#50504; &#48156;&#49373;&#54616;&#45716; &#45824;&#44592; &#51060;&#48292;&#53944;&#47484; &#47784;&#45768;&#53552;&#47553;&#54616;&#50668; &#48337;&#47785; &#54788;&#49345;&#51012; &#49885;&#48324;&#54624; &#49688; &#51080;&#45796;. &#45824;&#44592; &#51060;&#48292;&#53944; &#48516;&#49437;&#51012; &#53685;&#54644; &#53945;&#51221; &#47532;&#49548;&#49828;(&#50696;: CPU, I/O, &#46973;)&#50640;&#49436;&#51032; &#48337;&#47785;&#51012; &#54028;&#50501;&#54616;&#44256;, &#51060;&#50640; &#45824;&#54620; &#52572;&#51201;&#54868; &#51312;&#52824;&#47484; &#52712;&#54624; &#49688; &#51080;&#45796;.</p></li><li><p><strong>Resource Utilization</strong>: CPU, &#47700;&#47784;&#47532;, &#46356;&#49828;&#53356; I/O &#46321;&#51032; &#47532;&#49548;&#49828; &#49324;&#50857;&#47049;&#51012; &#47784;&#45768;&#53552;&#47553;&#54624; &#49688; &#51080;&#45796;. &#47532;&#49548;&#49828; &#49324;&#50857;&#47049; &#44536;&#47000;&#54532;&#47484; &#53685;&#54644; &#51064;&#49828;&#53556;&#49828;&#51032; &#54788;&#51116; &#49345;&#53468;&#50752; &#44284;&#44144; &#49345;&#53468;&#47484; &#48708;&#44368;&#54616;&#50668; &#49457;&#45733; &#47928;&#51228;&#51032; &#50896;&#51064;&#51012; &#48516;&#49437;&#54624; &#49688; &#51080;&#45796;.</p></li></ol><p>Performance Insights&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49457;&#45733; &#52572;&#51201;&#54868;&#49104;&#47564; &#50500;&#45768;&#46972;, &#48708;&#50857; &#51208;&#44048;&#50640;&#46020; &#46020;&#50880;&#51012; &#51456;&#45796;. &#50696;&#47484; &#46308;&#50612;, CPU &#49324;&#50857;&#47456;&#51060; &#45230;&#51008; &#44221;&#50864;&#50640;&#45716; &#51064;&#49828;&#53556;&#49828; &#53356;&#44592;&#47484; &#51460;&#50668; &#48708;&#50857;&#51012; &#51208;&#44048;&#54624; &#49688; &#51080;&#51004;&#47728;, &#48152;&#45824;&#47196; CPU &#49324;&#50857;&#47456;&#51060; &#45458;&#51012; &#44221;&#50864;&#50640;&#45716; &#51064;&#49828;&#53556;&#49828; &#53356;&#44592;&#47484; &#51613;&#44032;&#49884;&#53020; &#49457;&#45733;&#51012; &#54693;&#49345;&#49884;&#53420; &#49688; &#51080;&#45796;. &#46608;&#54620;, &#47532;&#49548;&#49828; &#49324;&#50857;&#47049;&#51012; &#47784;&#45768;&#53552;&#47553;&#54616;&#50668; &#48520;&#54596;&#50836;&#54620; &#47532;&#49548;&#49828; &#49324;&#50857;&#51012; &#51460;&#51060;&#44256;, &#54952;&#50984;&#51201;&#51064; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#50868;&#50689;&#51012; &#44032;&#45733;&#54616;&#44172; &#54620;&#45796;.</p><p>Performance Insights&#45716; Amazon Aurora, MySQL, MariaDB, PostgreSQL, Oracle, SQL Server &#46321;&#51032; &#45796;&#50577;&#54620; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#50644;&#51652;&#51012; &#51648;&#50896;&#54620;&#45796;. &#51060;&#47484; &#53685;&#54644; &#50668;&#47084; &#51333;&#47448;&#51032; RDS &#51064;&#49828;&#53556;&#49828;&#50640;&#49436; &#49457;&#45733; &#47784;&#45768;&#53552;&#47553;&#44284; &#52572;&#51201;&#54868;&#47484; &#51068;&#44288;&#46104;&#44172; &#49688;&#54665;&#54624; &#49688; &#51080;&#45796;. &#46608;&#54620;, Performance Insights&#45716; 7&#51068;&#44036;&#51032; &#44592;&#48376; &#45936;&#51060;&#53552;&#47484; &#47924;&#47308;&#47196; &#51228;&#44277;&#54616;&#47728;, &#52628;&#44032; &#50836;&#44552;&#51004;&#47196; &#52572;&#45824; 24&#44060;&#50900;&#44620;&#51648; &#45936;&#51060;&#53552;&#47484; &#48372;&#44288;&#54624; &#49688; &#51080;&#45796;. &#51060;&#47484; &#53685;&#54644; &#51109;&#44592;&#51201;&#51064; &#49457;&#45733; &#52628;&#51060;&#47484; &#48516;&#49437;&#54616;&#44256;, &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49457;&#45733;&#51012; &#51648;&#49549;&#51201;&#51004;&#47196; &#52572;&#51201;&#54868;&#54624; &#49688; &#51080;&#45796;.</p>]]></content:encoded></item><item><title><![CDATA[Amazon Aurora 파라미터 그룹]]></title><description><![CDATA[Amazon Aurora &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#50640; &#45824;&#54644; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/amazon-aurora-5cd</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/amazon-aurora-5cd</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Mon, 22 Jul 2024 05:15:20 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!TClI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F284454d6-cfc5-4bda-8d44-f3a6752d9a9b_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TClI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F284454d6-cfc5-4bda-8d44-f3a6752d9a9b_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TClI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F284454d6-cfc5-4bda-8d44-f3a6752d9a9b_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!TClI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F284454d6-cfc5-4bda-8d44-f3a6752d9a9b_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!TClI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F284454d6-cfc5-4bda-8d44-f3a6752d9a9b_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!TClI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F284454d6-cfc5-4bda-8d44-f3a6752d9a9b_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TClI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F284454d6-cfc5-4bda-8d44-f3a6752d9a9b_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/284454d6-cfc5-4bda-8d44-f3a6752d9a9b_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:384731,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TClI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F284454d6-cfc5-4bda-8d44-f3a6752d9a9b_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!TClI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F284454d6-cfc5-4bda-8d44-f3a6752d9a9b_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!TClI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F284454d6-cfc5-4bda-8d44-f3a6752d9a9b_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!TClI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F284454d6-cfc5-4bda-8d44-f3a6752d9a9b_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Amazon Aurora&#51032; <strong>&#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51008; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#51064;&#49828;&#53556;&#49828;&#51032; &#46041;&#51089; &#48169;&#49885;&#51012; &#51228;&#50612;&#54616;&#45716; &#49444;&#51221; &#51665;&#54633;</strong>&#51060;&#45796;. &#51060; &#49444;&#51221;&#51012; &#53685;&#54644; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49457;&#45733;, &#48372;&#50504;, &#47196;&#44536; &#48143; &#44592;&#53440; &#45796;&#50577;&#54620; &#44592;&#45733;&#51012; &#49464;&#48128;&#54616;&#44172; &#51312;&#51221;&#54624; &#49688; &#51080;&#45796;. Aurora&#45716; &#44592;&#48376; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51012; &#51228;&#44277;&#54616;&#47728;, &#49324;&#50857;&#51088;&#45716; &#51060;&#47484; &#48373;&#49324;&#54616;&#50668; &#49324;&#50857;&#51088; &#51221;&#51032; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51012; &#49373;&#49457;&#54616;&#44256; &#54596;&#50836;&#50640; &#47582;&#44172; &#49444;&#51221;&#51012; &#48320;&#44221;&#54624; &#49688; &#51080;&#45796;.</p><p>&#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51012; &#49444;&#51221;&#54616;&#45716; &#52395; &#48264;&#51704; &#45800;&#44228;&#45716; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51012; &#49373;&#49457;&#54616;&#45716; &#44163;&#51060;&#45796;. AWS Management Console, AWS CLI, &#46608;&#45716; AWS SDK&#47484; &#53685;&#54644; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51012; &#49373;&#49457;&#54624; &#49688; &#51080;&#45796;. &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51012; &#49373;&#49457;&#54624; &#46412;&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#50644;&#51652; &#50976;&#54805;&#44284; &#48260;&#51204;&#51012; &#51648;&#51221;&#54644;&#50556; &#54616;&#47728;, &#51060;&#45716; &#54644;&#45817; &#50644;&#51652;&#44284; &#48260;&#51204;&#50640; &#47582;&#45716; &#49444;&#51221;&#51060; &#51201;&#50857;&#46104;&#46020;&#47197; &#54616;&#44592; &#50948;&#54632;&#51060;&#45796;. &#50696;&#47484; &#46308;&#50612;, Aurora MySQL&#44284; Aurora PostgreSQL&#51008; &#44033;&#44033; &#45796;&#47480; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51012; &#49324;&#50857;&#54616;&#47728;, &#50644;&#51652; &#48260;&#51204;&#50640; &#46384;&#46972; &#49324;&#50857;&#54624; &#49688; &#51080;&#45716; &#54028;&#46972;&#48120;&#53552;&#44032; &#45796;&#47484; &#49688; &#51080;&#45796;.</p><p>&#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51060; &#49373;&#49457;&#46104;&#47732;, &#49324;&#50857;&#51088;&#45716; &#54644;&#45817; &#44536;&#47353;&#51032; &#54028;&#46972;&#48120;&#53552; &#44050;&#51012; &#49688;&#51221;&#54624; &#49688; &#51080;&#45796;. AWS Management Console&#50640;&#49436; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51012; &#49440;&#53469;&#54616;&#44256;, &#44033; &#54028;&#46972;&#48120;&#53552;&#51032; &#54788;&#51116; &#44050;&#51012; &#54869;&#51064;&#54620; &#54980; &#54596;&#50836;&#54620; &#44050;&#51012; &#48320;&#44221;&#54624; &#49688; &#51080;&#45796;. </p><p></p><h3>&#51452;&#50836; &#54028;&#46972;&#48120;&#53552;</h3><ul><li><p><strong>innodb_buffer_pool_size</strong><br>innodb_buffer_pool_size&#45716; InnoDB &#49828;&#53664;&#47532;&#51648; &#50644;&#51652;&#51032; &#48260;&#54140; &#54400; &#53356;&#44592;&#47484; &#49444;&#51221;&#54616;&#45716; &#54028;&#46972;&#48120;&#53552;&#47196;, &#45936;&#51060;&#53552;&#50752; &#51064;&#45937;&#49828;&#47484; &#47700;&#47784;&#47532;&#50640; &#52880;&#49905;&#54616;&#50668; &#46356;&#49828;&#53356; I/O&#47484; &#51460;&#51060;&#44256; &#49457;&#45733;&#51012; &#54693;&#49345;&#49884;&#53416;&#45796;. &#47700;&#47784;&#47532; &#50857;&#47049;&#51060; &#53360; &#49436;&#48260;&#50640;&#49436;&#45716; &#51060; &#44050;&#51012; &#53356;&#44172; &#49444;&#51221;&#54616;&#50668; &#45908; &#47566;&#51008; &#45936;&#51060;&#53552;&#47484; &#47700;&#47784;&#47532;&#50640; &#50976;&#51648;&#54632;&#51004;&#47196;&#50024; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49457;&#45733;&#51012; &#44537;&#45824;&#54868;&#54624; &#49688; &#51080;&#45796;.</p></li><li><p><strong>max_connections</strong><br>max_connections&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#50640; &#46041;&#49884;&#50640; &#50672;&#44208;&#54624; &#49688; &#51080;&#45716; &#52572;&#45824; &#50672;&#44208; &#49688;&#47484; &#49444;&#51221;&#54616;&#45716; &#54028;&#46972;&#48120;&#53552;&#47196;, &#50528;&#54540;&#47532;&#52992;&#51060;&#49496;&#51032; &#50836;&#44396;&#50640; &#46384;&#46972; &#51060; &#44050;&#51012; &#51312;&#51221;&#54624; &#49688; &#51080;&#45796;. &#50937; &#50528;&#54540;&#47532;&#52992;&#51060;&#49496;&#44284; &#44057;&#51060; &#47566;&#51008; &#49324;&#50857;&#51088;&#44032; &#46041;&#49884;&#50640; &#51217;&#49549;&#54616;&#45716; &#54872;&#44221;&#50640;&#49436;&#45716; &#51060; &#44050;&#51012; &#45458;&#50668; &#45908; &#47566;&#51008; &#50672;&#44208;&#51012; &#54728;&#50857;&#54616;&#46020;&#47197; &#49444;&#51221;&#54644;&#50556; &#54620;&#45796;.</p></li><li><p><strong>query_cache_size</strong><br>query_cache_size&#45716; MySQL&#50640;&#49436; &#53244;&#47532; &#52880;&#49884;&#51032; &#53356;&#44592;&#47484; &#49444;&#51221;&#54616;&#45716; &#54028;&#46972;&#48120;&#53552;&#47196;, &#51088;&#51452; &#49892;&#54665;&#46104;&#45716; SELECT &#53244;&#47532;&#51032; &#44208;&#44284;&#47484; &#52880;&#49905;&#54616;&#50668; &#53244;&#47532; &#49457;&#45733;&#51012; &#54693;&#49345;&#49884;&#53416;&#45796;. &#44536;&#47084;&#45208; Aurora MySQL 5.7 &#51060;&#49345; &#48260;&#51204;&#50640;&#49436;&#45716; &#53244;&#47532; &#52880;&#49884;&#44032; &#51228;&#44144;&#46104;&#50632;&#51004;&#48064;&#47196;, &#44536; &#51060;&#54616; &#48260;&#51204;&#51012; &#49324;&#50857;&#54616;&#45716; &#44221;&#50864;&#50640;&#47564; &#51060; &#54028;&#46972;&#48120;&#53552;&#47484; &#51312;&#51221;&#54624; &#49688; &#51080;&#45796;.</p></li><li><p><strong>innodb_log_file_size</strong><br>innodb_log_file_size&#45716; InnoDB &#47196;&#44536; &#54028;&#51068;&#51032; &#53356;&#44592;&#47484; &#49444;&#51221;&#54616;&#45716; &#54028;&#46972;&#48120;&#53552;&#47196;, &#47196;&#44536; &#54028;&#51068;&#51060; &#53356;&#47732; &#53356;&#47000;&#49884; &#48373;&#44396; &#49884; &#49884;&#44036;&#51060; &#45800;&#52629;&#46104;&#44256;, &#53944;&#47004;&#51117;&#49496; &#52376;&#47532; &#49457;&#45733;&#51060; &#54693;&#49345;&#46108;&#45796;. &#44536;&#47084;&#45208; &#45320;&#47924; &#53356;&#44172; &#49444;&#51221;&#54616;&#47732; &#46356;&#49828;&#53356; &#49324;&#50857;&#47049;&#51060; &#51613;&#44032;&#54624; &#49688; &#51080;&#51004;&#48064;&#47196; &#51201;&#51208;&#54620; &#53356;&#44592;&#47196; &#51312;&#51221;&#54644;&#50556; &#54620;&#45796;.</p></li><li><p><strong>innodb_flush_log_at_trx_commit</strong><br>innodb_flush_log_at_trx_commit&#51008; &#53944;&#47004;&#51117;&#49496;&#51060; &#52964;&#48139;&#46112; &#46412; &#47196;&#44536;&#47484; &#46356;&#49828;&#53356;&#50640; &#44592;&#47197;&#54616;&#45716; &#48169;&#49885;&#51012; &#51228;&#50612;&#54616;&#45716; &#54028;&#46972;&#48120;&#53552;&#47196;, &#44050;&#50640; &#46384;&#46972; &#45936;&#51060;&#53552; &#50504;&#51221;&#49457;&#44284; &#49457;&#45733; &#44036;&#51032; &#44512;&#54805;&#51012; &#47582;&#52636; &#49688; &#51080;&#45796;. &#44592;&#48376;&#44050;&#51064; 1&#51008; &#44033; &#53944;&#47004;&#51117;&#49496;&#47560;&#45796; &#47196;&#44536;&#47484; &#46356;&#49828;&#53356;&#50640; &#44592;&#47197;&#54616;&#50668; &#45458;&#51008; &#45936;&#51060;&#53552; &#50504;&#51221;&#49457;&#51012; &#48372;&#51109;&#54616;&#51648;&#47564;, &#49457;&#45733;&#51060; &#51200;&#54616;&#46112; &#49688; &#51080;&#45796;. &#44050;&#51060; 2 &#46608;&#45716; 0&#51004;&#47196; &#49444;&#51221;&#54616;&#47732; &#49457;&#45733;&#51060; &#54693;&#49345;&#46104;&#51648;&#47564;, &#45936;&#51060;&#53552; &#49552;&#49892; &#50948;&#54744;&#51060; &#52964;&#51652;&#45796;.</p></li><li><p><strong>innodb_io_capacity</strong><br>innodb_io_capacity&#45716; InnoDB&#51032; &#48177;&#44536;&#46972;&#50868;&#46300; &#51089;&#50629;(&#50696;: &#48260;&#54140; &#54400;&#51032; &#54168;&#51060;&#51648; &#54540;&#47084;&#49884;, &#47196;&#44536; &#54028;&#51068; &#44592;&#47197; &#46321;)&#51012; &#50948;&#54620; I/O &#50857;&#47049;&#51012; &#49444;&#51221;&#54616;&#45716; &#54028;&#46972;&#48120;&#53552;&#47196;, &#46356;&#49828;&#53356; I/O &#49457;&#45733;&#50640; &#47582;&#52656; &#51201;&#51208;&#55176; &#49444;&#51221;&#54644;&#50556; &#54620;&#45796;. SSD&#50752; &#44057;&#51008; &#44256;&#49457;&#45733; &#46356;&#49828;&#53356;&#47484; &#49324;&#50857;&#54616;&#45716; &#44221;&#50864; &#51060; &#44050;&#51012; &#45458;&#50668; &#48177;&#44536;&#46972;&#50868;&#46300; &#51089;&#50629;&#51012; &#45908; &#48736;&#47476;&#44172; &#49688;&#54665;&#54624; &#49688; &#51080;&#45796;.</p></li><li><p><strong>innodb_thread_concurrency</strong><br>innodb_thread_concurrency&#45716; InnoDB&#50640;&#49436; &#46041;&#49884;&#50640; &#49892;&#54665;&#54624; &#49688; &#51080;&#45716; &#49828;&#47112;&#46300; &#49688;&#47484; &#51228;&#54620;&#54616;&#45716; &#54028;&#46972;&#48120;&#53552;&#47196;, &#49828;&#47112;&#46300; &#44221;&#54633;&#51012; &#51460;&#51060;&#44256; &#49457;&#45733;&#51012; &#54693;&#49345;&#49884;&#53420; &#49688; &#51080;&#45796;. &#51068;&#48152;&#51201;&#51004;&#47196; CPU &#53076;&#50612; &#49688;&#50640; &#47582;&#52656; &#51060; &#44050;&#51012; &#51312;&#51221;&#54616;&#47732; &#49457;&#45733;&#51012; &#52572;&#51201;&#54868;&#54624; &#49688; &#51080;&#45796;.</p></li><li><p><strong>autocommit</strong><br>autocommit&#51008; &#44033; SQL &#47928;&#51060; &#51088;&#46041;&#51004;&#47196; &#52964;&#48139;&#46112;&#51648; &#50668;&#48512;&#47484; &#44208;&#51221;&#54616;&#45716; &#54028;&#46972;&#48120;&#53552;&#47196;, &#50528;&#54540;&#47532;&#52992;&#51060;&#49496;&#51032; &#53944;&#47004;&#51117;&#49496; &#44288;&#47532; &#51204;&#47029;&#50640; &#46384;&#46972; &#51060; &#44050;&#51012; &#49444;&#51221;&#54624; &#49688; &#51080;&#45796;. &#51088;&#46041; &#52964;&#48139;&#51012; &#48708;&#54876;&#49457;&#54868;&#54616;&#47732; &#53944;&#47004;&#51117;&#49496; &#45800;&#50948;&#47196; &#52964;&#48139;&#54624; &#49688; &#51080;&#50612; &#45936;&#51060;&#53552; &#51068;&#44288;&#49457;&#51012; &#50976;&#51648;&#54624; &#49688; &#51080;&#45796;.</p></li><li><p><strong>log_bin_trust_function_creators</strong><br>log_bin_trust_function_creators&#45716; &#49324;&#50857;&#51088; &#51221;&#51032; &#54632;&#49688;(UDF)&#50752; &#51200;&#51109; &#54532;&#47196;&#49884;&#51200;&#47484; &#49373;&#49457;&#54624; &#46412; &#54596;&#50836;&#47196; &#54616;&#45716; &#53945;&#44428;&#51012; &#49444;&#51221;&#54616;&#45716; &#54028;&#46972;&#48120;&#53552;&#47196;, &#53944;&#47532;&#44144; &#48143; &#51060;&#48292;&#53944;&#47484; &#49324;&#50857;&#54616;&#45716; &#50528;&#54540;&#47532;&#52992;&#51060;&#49496;&#50640;&#49436; &#50976;&#50857;&#54616;&#45796;. &#51060; &#44050;&#51012; 1&#47196; &#49444;&#51221;&#54616;&#47732; UDF &#48143; &#51200;&#51109; &#54532;&#47196;&#49884;&#51200;&#47484; &#45908; &#49789;&#44172; &#49373;&#49457;&#54624; &#49688; &#51080;&#45796;.</p></li><li><p><strong>slow_query_log</strong><br>slow_query_log&#45716; &#45712;&#47536; &#53244;&#47532;&#47484; &#47196;&#44536;&#50640; &#44592;&#47197;&#54616;&#45716; &#44592;&#45733;&#51012; &#54876;&#49457;&#54868;&#54616;&#45716; &#54028;&#46972;&#48120;&#53552;&#47196;, &#49457;&#45733; &#47928;&#51228;&#47484; &#51652;&#45800;&#54616;&#44256; &#52572;&#51201;&#54868;&#54624; &#46412; &#50976;&#50857;&#54616;&#45796;. &#45712;&#47536; &#53244;&#47532; &#47196;&#44536;&#47484; &#53685;&#54644; &#49457;&#45733;&#51060; &#51200;&#54616;&#46104;&#45716; &#53244;&#47532;&#47484; &#49885;&#48324;&#54616;&#44256;, &#51064;&#45937;&#49828; &#52572;&#51201;&#54868;&#45208; &#53244;&#47532; &#44396;&#51312; &#44060;&#49440; &#46321;&#51032; &#51312;&#52824;&#47484; &#52712;&#54624; &#49688; &#51080;&#45796;.</p></li></ul><p></p><h3>Cluster Parameter Group vs Instance Parameter Group</h3><p><strong>&#53364;&#47084;&#49828;&#53552; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51008; Aurora &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#53364;&#47084;&#49828;&#53552; &#51204;&#52404;&#50640; &#51201;&#50857;&#46104;&#45716; &#49444;&#51221;&#51012; &#54252;&#54632;</strong>&#54616;&#44256; &#51080;&#45796;. &#54616;&#45208;&#51032; &#53364;&#47084;&#49828;&#53552;&#50640;&#45716; &#45796;&#49688;&#51032; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#51064;&#49828;&#53556;&#49828;&#44032; &#51080;&#51012; &#49688; &#51080;&#51004;&#47728;, &#53364;&#47084;&#49828;&#53552; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51008; &#51060; &#47784;&#46304; &#51064;&#49828;&#53556;&#49828;&#50640; &#44277;&#53685;&#51201;&#51004;&#47196; &#51201;&#50857;&#46104;&#45716; &#54028;&#46972;&#48120;&#53552;&#47484; &#51221;&#51032;&#54620;&#45796;. &#50696;&#47484; &#46308;&#50612;, &#53364;&#47084;&#49828;&#53552; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51012; &#53685;&#54644; &#53364;&#47084;&#49828;&#53552; &#51204;&#52404;&#51032; &#47196;&#44536; &#54028;&#51068; &#53356;&#44592;&#45208; &#48373;&#51228; &#49444;&#51221;&#51012; &#44288;&#47532;&#54624; &#49688; &#51080;&#45796;. &#51060;&#47084;&#54620; &#49444;&#51221;&#51008; &#53364;&#47084;&#49828;&#53552; &#45236; &#47784;&#46304; &#51064;&#49828;&#53556;&#49828;&#50640; &#46041;&#51068;&#54616;&#44172; &#51201;&#50857;&#46104;&#44592; &#46412;&#47928;&#50640;, &#53364;&#47084;&#49828;&#53552; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51012; &#50732;&#48148;&#47476;&#44172; &#49444;&#51221;&#54616;&#45716; &#44163;&#51008; &#47588;&#50864; &#51473;&#50836;&#54616;&#45796;.</p><p><strong>&#51064;&#49828;&#53556;&#49828; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51008; &#44060;&#48324; DB &#51064;&#49828;&#53556;&#49828;&#50640; &#51201;&#50857;&#46104;&#45716; &#49444;&#51221;&#51012; &#51221;&#51032;</strong>&#54620;&#45796;. &#44033; &#51064;&#49828;&#53556;&#49828;&#45716; &#46021;&#47549;&#51201;&#51004;&#47196; &#44396;&#49457;&#46112; &#49688; &#51080;&#51004;&#47728;, &#53945;&#51221; &#51064;&#49828;&#53556;&#49828;&#50640; &#45824;&#54644; &#48324;&#46020;&#51032; &#49444;&#51221;&#51012; &#51201;&#50857;&#54616;&#44256;&#51088; &#54624; &#46412; &#51064;&#49828;&#53556;&#49828; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51012; &#49324;&#50857;&#54620;&#45796;. &#50696;&#47484; &#46308;&#50612;, &#53945;&#51221; &#51064;&#49828;&#53556;&#49828;&#51032; &#47700;&#47784;&#47532; &#54624;&#45817;&#47049;&#51060;&#45208; &#52880;&#49884; &#53356;&#44592;&#47484; &#51312;&#51221;&#54616;&#44256;&#51088; &#54624; &#46412; &#51064;&#49828;&#53556;&#49828; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51012; &#49324;&#50857;&#54616;&#47732; &#46108;&#45796;. &#51060;&#45716; &#53364;&#47084;&#49828;&#53552; &#45236;&#51032; &#51064;&#49828;&#53556;&#49828;&#44032; &#49436;&#47196; &#45796;&#47480; &#51089;&#50629; &#48512;&#54616;&#47484; &#52376;&#47532;&#54616;&#44144;&#45208;, &#45796;&#47480; &#49457;&#45733; &#50836;&#44396; &#49324;&#54637;&#51012; &#44032;&#51656; &#46412; &#50976;&#50857;&#54616;&#45796;.</p><p>&#51060; &#46160; &#44032;&#51648; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51032; &#52264;&#51060;&#47484; &#51060;&#54644;&#54616;&#45716; &#44163;&#51008; &#47588;&#50864; &#51473;&#50836;&#54616;&#45796;. &#53364;&#47084;&#49828;&#53552; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51008; &#53364;&#47084;&#49828;&#53552; &#51204;&#52404;&#51032; &#51068;&#44288;&#49457;&#51012; &#50976;&#51648;&#54616;&#44256;, &#44277;&#53685;&#51201;&#51064; &#49444;&#51221;&#51012; &#49789;&#44172; &#44288;&#47532;&#54624; &#49688; &#51080;&#46020;&#47197; &#46020;&#50752;&#51456;&#45796;. &#53364;&#47084;&#49828;&#53552; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51012; &#48320;&#44221;&#54616;&#47732; &#53364;&#47084;&#49828;&#53552; &#45236; &#47784;&#46304; &#51064;&#49828;&#53556;&#49828;&#50640; &#51593;&#49884; &#50689;&#54693;&#51012; &#48120;&#52824;&#44592; &#46412;&#47928;&#50640;, &#51060;&#47084;&#54620; &#48320;&#44221; &#49324;&#54637;&#51008; &#49888;&#51473;&#54616;&#44172; &#44288;&#47532;&#46104;&#50612;&#50556; &#54620;&#45796;. &#48152;&#47732;&#50640;, &#51064;&#49828;&#53556;&#49828; &#54028;&#46972;&#48120;&#53552; &#44536;&#47353;&#51008; &#44060;&#48324; &#51064;&#49828;&#53556;&#49828;&#51032; &#53945;&#49688;&#54620; &#50836;&#44396; &#49324;&#54637;&#51012; &#52649;&#51313;&#49884;&#53412;&#44592; &#50948;&#54644; &#49324;&#50857;&#46108;&#45796;. &#51060;&#45716; &#53945;&#55176; &#45824;&#44508;&#47784; &#53364;&#47084;&#49828;&#53552;&#50640;&#49436; &#53945;&#51221; &#51064;&#49828;&#53556;&#49828;&#50640; &#45824;&#54644; &#52572;&#51201;&#54868;&#46108; &#49444;&#51221;&#51012; &#51201;&#50857;&#54624; &#46412; &#47588;&#50864; &#50976;&#50857;&#54616;&#45796;.</p>]]></content:encoded></item><item><title><![CDATA[Amazon Aurora]]></title><description><![CDATA[Amazon Aurora &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#50640; &#45824;&#54644; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/amazon-aurora</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/amazon-aurora</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Mon, 22 Jul 2024 05:08:53 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!0Kas!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bd81d04-b1fb-4765-969f-cb1aedfcde42_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!0Kas!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bd81d04-b1fb-4765-969f-cb1aedfcde42_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!0Kas!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bd81d04-b1fb-4765-969f-cb1aedfcde42_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!0Kas!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bd81d04-b1fb-4765-969f-cb1aedfcde42_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!0Kas!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bd81d04-b1fb-4765-969f-cb1aedfcde42_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!0Kas!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bd81d04-b1fb-4765-969f-cb1aedfcde42_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!0Kas!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bd81d04-b1fb-4765-969f-cb1aedfcde42_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4bd81d04-b1fb-4765-969f-cb1aedfcde42_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:391758,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!0Kas!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bd81d04-b1fb-4765-969f-cb1aedfcde42_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!0Kas!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bd81d04-b1fb-4765-969f-cb1aedfcde42_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!0Kas!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bd81d04-b1fb-4765-969f-cb1aedfcde42_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!0Kas!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bd81d04-b1fb-4765-969f-cb1aedfcde42_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Amazon Aurora&#45716; AWS&#50640;&#49436; &#51228;&#44277;&#54616;&#45716; &#44256;&#49457;&#45733; &#44288;&#44228;&#54805; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49436;&#48708;&#49828;&#47196;, MySQL&#44284; PostgreSQL&#51012; &#44592;&#48152;&#51004;&#47196; &#49444;&#44228;&#46104;&#50632;&#45796;. Aurora&#45716; &#44592;&#51316;&#51032; MySQL &#48143; PostgreSQL &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#50752; &#54840;&#54872;&#46104;&#47732;&#49436;&#46020;, &#49457;&#45733;&#44284; &#44032;&#50857;&#49457; &#47732;&#50640;&#49436; &#54925;&#44592;&#51201;&#51064; &#54693;&#49345;&#51012; &#51228;&#44277;&#54620;&#45796;. Amazon Aurora&#45716; &#53364;&#46972;&#50864;&#46300; &#45348;&#51060;&#54000;&#48652; &#49444;&#44228;&#47196;, &#44256;&#44032;&#50857;&#49457;, &#54869;&#51109;&#49457;, &#45936;&#51060;&#53552; &#48372;&#50504;, &#51088;&#46041; &#48177;&#50629; &#46321; &#45796;&#50577;&#54620; &#44592;&#45733;&#51012; &#54252;&#54632;&#54616;&#44256; &#51080;&#50612; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#50868;&#50689;&#51032; &#48373;&#51105;&#49457;&#51012; &#53356;&#44172; &#51460;&#50668;&#51456;&#45796;.</p><p>Amazon Aurora&#51032; &#51452;&#50836; &#51109;&#51216; &#51473; &#54616;&#45208;&#45716; <strong>&#46832;&#50612;&#45212; &#49457;&#45733;</strong>&#51060;&#45796;. Aurora&#45716; &#54364;&#51456; MySQL&#48372;&#45796; &#52572;&#45824; 5&#48176;, &#54364;&#51456; PostgreSQL&#48372;&#45796; &#52572;&#45824; 3&#48176; &#45908; &#48736;&#47480; &#49457;&#45733;&#51012; &#51228;&#44277;&#54620;&#45796;. &#51060;&#47084;&#54620; &#49457;&#45733; &#54693;&#49345;&#51008; Aurora&#51032; &#46021;&#51088;&#51201;&#51064; &#50500;&#53412;&#53581;&#52376; &#45909;&#48516;&#51060;&#45796;. Aurora&#45716; &#49828;&#53664;&#47532;&#51648;&#50752; &#52980;&#54504;&#54021;&#51012; &#48516;&#47532;&#54616;&#50668; &#44033; &#45432;&#46300;&#44032; &#46021;&#47549;&#51201;&#51004;&#47196; &#54869;&#51109;&#46112; &#49688; &#51080;&#46020;&#47197; &#49444;&#44228;&#46104;&#50632;&#45796;. &#51060;&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#51069;&#44592; &#48143; &#50416;&#44592; &#51089;&#50629;&#51012; &#48516;&#49328;&#49884;&#53020; &#49457;&#45733; &#48337;&#47785;&#51012; &#52572;&#49548;&#54868;&#54616;&#44256;, &#44256;&#49457;&#45733;&#51012; &#50976;&#51648;&#54624; &#49688; &#51080;&#44172; &#54620;&#45796;.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Wpjj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F983dae96-8d88-40e8-bd40-72f9e4e2cf6a_1535x1739.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Wpjj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F983dae96-8d88-40e8-bd40-72f9e4e2cf6a_1535x1739.png 424w, https://substackcdn.com/image/fetch/$s_!Wpjj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F983dae96-8d88-40e8-bd40-72f9e4e2cf6a_1535x1739.png 848w, https://substackcdn.com/image/fetch/$s_!Wpjj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F983dae96-8d88-40e8-bd40-72f9e4e2cf6a_1535x1739.png 1272w, https://substackcdn.com/image/fetch/$s_!Wpjj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F983dae96-8d88-40e8-bd40-72f9e4e2cf6a_1535x1739.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Wpjj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F983dae96-8d88-40e8-bd40-72f9e4e2cf6a_1535x1739.png" width="1456" height="1650" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/983dae96-8d88-40e8-bd40-72f9e4e2cf6a_1535x1739.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1650,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:600685,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Wpjj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F983dae96-8d88-40e8-bd40-72f9e4e2cf6a_1535x1739.png 424w, https://substackcdn.com/image/fetch/$s_!Wpjj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F983dae96-8d88-40e8-bd40-72f9e4e2cf6a_1535x1739.png 848w, https://substackcdn.com/image/fetch/$s_!Wpjj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F983dae96-8d88-40e8-bd40-72f9e4e2cf6a_1535x1739.png 1272w, https://substackcdn.com/image/fetch/$s_!Wpjj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F983dae96-8d88-40e8-bd40-72f9e4e2cf6a_1535x1739.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Aurora&#45716; &#44256;&#44032;&#50857;&#49457;&#51012; &#48372;&#51109;&#54616;&#44592; &#50948;&#54644; &#50668;&#47084; &#44032;&#50857; &#50689;&#50669;(AZ)&#50640; &#44152;&#52432; &#45936;&#51060;&#53552;&#47484; &#51088;&#46041;&#51004;&#47196; &#48373;&#51228;&#54620;&#45796;. &#44592;&#48376;&#51201;&#51004;&#47196; 6&#44060;&#51032; &#48373;&#51228;&#48376;&#51060; 3&#44060;&#51032; AZ&#50640; &#44152;&#52432; &#51200;&#51109;&#46104;&#47728;, &#51060;&#45716; &#45936;&#51060;&#53552; &#49552;&#49892;&#51012; &#48169;&#51648;&#54616;&#44256; &#51109;&#50528; &#48156;&#49373; &#49884;&#50640;&#46020; &#45936;&#51060;&#53552;&#51032; &#47924;&#44208;&#49457;&#51012; &#50976;&#51648;&#54624; &#49688; &#51080;&#44172; &#54620;&#45796;. Aurora&#45716; &#51109;&#50528; &#48373;&#44396; &#49884;&#44036;&#51012; &#47751; &#52488; &#51060;&#45236;&#47196; &#51460;&#51060;&#45716; &#51088;&#46041; &#51109;&#50528; &#51312;&#52824;(failover) &#44592;&#45733;&#51012; &#51228;&#44277;&#54616;&#50668;, &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#44032;&#50857;&#49457;&#51012; &#44537;&#45824;&#54868;&#54620;&#45796;. &#51060;&#45716; &#48708;&#51592;&#45768;&#49828; &#50672;&#49549;&#49457;&#51012; &#50976;&#51648;&#54616;&#45716; &#45936; &#47588;&#50864; &#51473;&#50836;&#54620; &#50669;&#54624;&#51012; &#54620;&#45796;.</p><p>&#46608;&#54620;, Aurora&#45716; <strong>&#51088;&#46041; &#48177;&#50629;&#44284; &#53945;&#51221; &#49884;&#51216; &#48373;&#44396;(Point-In-Time Recovery, PITR)&#47484; &#51648;&#50896;</strong>&#54620;&#45796;. &#51088;&#46041; &#48177;&#50629;&#51008; Aurora &#49828;&#53664;&#47532;&#51648; &#44228;&#52789;&#50640;&#49436; &#51648;&#49549;&#51201;&#51004;&#47196; &#49688;&#54665;&#46104;&#47728;, &#49324;&#50857;&#51088;&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#47484; &#53945;&#51221; &#49884;&#51216;&#51004;&#47196; &#48373;&#44396;&#54624; &#49688; &#51080;&#45796;. &#51060;&#47084;&#54620; &#44592;&#45733;&#51008; &#45936;&#51060;&#53552; &#49552;&#49892;&#50640; &#45824;&#54620; &#44145;&#51221;&#51012; &#45916;&#50612;&#51452;&#44256;, &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#50504;&#51221;&#49457;&#51012; &#45458;&#50668;&#51456;&#45796;. &#48177;&#50629;&#51008; Amazon S3&#50640; &#50504;&#51204;&#54616;&#44172; &#51200;&#51109;&#46104;&#47728;, S3&#51032; &#45458;&#51008; &#45236;&#44396;&#49457;&#44284; &#44032;&#50857;&#49457;&#51012; &#48148;&#53461;&#51004;&#47196; &#45936;&#51060;&#53552;&#44032; &#50504;&#51204;&#54616;&#44172; &#48372;&#54840;&#46108;&#45796;.</p><p>Aurora&#45716; &#46608;&#54620; &#51069;&#44592; &#49457;&#45733;&#51012; &#54693;&#49345;&#49884;&#53412;&#44592; &#50948;&#54644; &#51069;&#44592; &#48373;&#51228;&#48376;(Read Replica)&#51012; &#51648;&#50896;&#54620;&#45796;. &#52572;&#45824; 15&#44060;&#51032; &#51069;&#44592; &#48373;&#51228;&#48376;&#51012; &#49373;&#49457;&#54624; &#49688; &#51080;&#51004;&#47728;, &#51060;&#45716; &#51069;&#44592; &#50836;&#52397;&#51012; &#48516;&#49328;&#49884;&#53020; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#51069;&#44592; &#49457;&#45733;&#51012; &#44537;&#45824;&#54868;&#54624; &#49688; &#51080;&#45796;. &#51069;&#44592; &#48373;&#51228;&#48376;&#51008; &#51452; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#50752;&#51032; &#51648;&#50672; &#49884;&#44036;&#51060; &#47588;&#50864; &#51687;&#50500;, &#49892;&#49884;&#44036;&#50640; &#44032;&#44620;&#50868; &#45936;&#51060;&#53552; &#51217;&#44540;&#51060; &#44032;&#45733;&#54616;&#45796;. &#51060;&#45716; &#45824;&#44508;&#47784; &#50528;&#54540;&#47532;&#52992;&#51060;&#49496;&#50640;&#49436; &#51069;&#44592; &#51089;&#50629;&#51060; &#51665;&#51473;&#46112; &#46412; &#47588;&#50864; &#50976;&#50857;&#54616;&#45796;.</p>]]></content:encoded></item><item><title><![CDATA[Amazon RDS 자동 백업]]></title><description><![CDATA[RDS &#51088;&#46041; &#48177;&#50629;&#50640; &#45824;&#54644; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/amazon-rds-85e</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/amazon-rds-85e</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Mon, 22 Jul 2024 04:55:23 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!TZgJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa80f4da5-b393-4c9d-8777-193d099646f7_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TZgJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa80f4da5-b393-4c9d-8777-193d099646f7_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TZgJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa80f4da5-b393-4c9d-8777-193d099646f7_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!TZgJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa80f4da5-b393-4c9d-8777-193d099646f7_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!TZgJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa80f4da5-b393-4c9d-8777-193d099646f7_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!TZgJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa80f4da5-b393-4c9d-8777-193d099646f7_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TZgJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa80f4da5-b393-4c9d-8777-193d099646f7_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a80f4da5-b393-4c9d-8777-193d099646f7_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:385967,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TZgJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa80f4da5-b393-4c9d-8777-193d099646f7_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!TZgJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa80f4da5-b393-4c9d-8777-193d099646f7_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!TZgJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa80f4da5-b393-4c9d-8777-193d099646f7_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!TZgJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa80f4da5-b393-4c9d-8777-193d099646f7_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#51088;&#46041; &#48177;&#50629;&#51008; &#49324;&#50857;&#51088;&#44032; &#51648;&#51221;&#54620; &#48372;&#44288; &#44592;&#44036; &#46041;&#50504; &#47588;&#51068; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#51064;&#49828;&#53556;&#49828;&#47484; &#48177;&#50629;&#54616;&#50668; &#45936;&#51060;&#53552; &#49552;&#49892;&#50640; &#45824;&#48708;&#54624; &#49688; &#51080;&#44172; &#54644;&#51456;&#45796;. &#51060; &#44592;&#45733;&#51008; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#44288;&#47532;&#51088;&#44032; &#49688;&#46041;&#51004;&#47196; &#48177;&#50629;&#51012; &#49688;&#54665;&#54644;&#50556; &#54616;&#45716; &#48512;&#45812;&#51012; &#45916;&#50612;&#51452;&#44256;, &#45936;&#51060;&#53552; &#48373;&#44396; &#49884;&#51216;(RPO, Recovery Point Objective)&#51012; &#52572;&#49548;&#54868;&#54616;&#45716; &#45936; &#46020;&#50880;&#51012; &#51456;&#45796;.</p><p>RDS &#51088;&#46041; &#48177;&#50629; &#44592;&#45733;&#51008; <strong>&#48177;&#50629; &#48372;&#44288; &#44592;&#44036;&#51012; &#49444;&#51221;&#54632;&#51004;&#47196;&#50024; &#54876;&#49457;&#54868;</strong>&#46108;&#45796;. &#44592;&#48376;&#51201;&#51004;&#47196; RDS&#45716; 1&#51068;&#50640;&#49436; &#52572;&#45824; 35&#51068;&#44620;&#51648;&#51032; &#48372;&#44288; &#44592;&#44036;&#51012; &#49444;&#51221;&#54624; &#49688; &#51080;&#51004;&#47728;, &#51060; &#44592;&#44036; &#46041;&#50504; &#51088;&#46041;&#51004;&#47196; &#48177;&#50629;&#51060; &#49688;&#54665;&#46108;&#45796;. &#48177;&#50629;&#51008; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#51064;&#49828;&#53556;&#49828;&#51032; &#51088;&#46041;&#54868;&#46108; &#49828;&#45253;&#49399; &#54805;&#53468;&#47196; &#51200;&#51109;&#46104;&#47728;, &#51060;&#47084;&#54620; &#49828;&#45253;&#49399;&#51008; &#49324;&#50857;&#51088;&#44032; &#54596;&#50836;&#54624; &#46412; &#50616;&#51228;&#46304;&#51648; &#48373;&#44396;&#54624; &#49688; &#51080;&#45796;. &#51088;&#46041; &#48177;&#50629; &#49828;&#45253;&#49399;&#51008; Amazon S3&#50640; &#51200;&#51109;&#46104;&#47728;, S3&#51032; &#45458;&#51008; &#45236;&#44396;&#49457;&#44284; &#44032;&#50857;&#49457;&#51012; &#48148;&#53461;&#51004;&#47196; &#50504;&#51204;&#54616;&#44172; &#48372;&#44288;&#46108;&#45796;.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!u4gM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e18284-2eac-4d2d-9d6a-42abf30ae5e8_798x277.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!u4gM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e18284-2eac-4d2d-9d6a-42abf30ae5e8_798x277.png 424w, https://substackcdn.com/image/fetch/$s_!u4gM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e18284-2eac-4d2d-9d6a-42abf30ae5e8_798x277.png 848w, https://substackcdn.com/image/fetch/$s_!u4gM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e18284-2eac-4d2d-9d6a-42abf30ae5e8_798x277.png 1272w, https://substackcdn.com/image/fetch/$s_!u4gM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e18284-2eac-4d2d-9d6a-42abf30ae5e8_798x277.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!u4gM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e18284-2eac-4d2d-9d6a-42abf30ae5e8_798x277.png" width="798" height="277" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/12e18284-2eac-4d2d-9d6a-42abf30ae5e8_798x277.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:277,&quot;width&quot;:798,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:31122,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!u4gM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e18284-2eac-4d2d-9d6a-42abf30ae5e8_798x277.png 424w, https://substackcdn.com/image/fetch/$s_!u4gM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e18284-2eac-4d2d-9d6a-42abf30ae5e8_798x277.png 848w, https://substackcdn.com/image/fetch/$s_!u4gM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e18284-2eac-4d2d-9d6a-42abf30ae5e8_798x277.png 1272w, https://substackcdn.com/image/fetch/$s_!u4gM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12e18284-2eac-4d2d-9d6a-42abf30ae5e8_798x277.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>RDS &#51088;&#46041; &#48177;&#50629;&#51008; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#51064;&#49828;&#53556;&#49828;&#51032; &#49457;&#45733;&#50640; &#50689;&#54693;&#51012; &#52572;&#49548;&#54868;&#54616;&#46020;&#47197; &#49444;&#44228;&#46104;&#50632;&#45796;. &#48177;&#50629; &#51089;&#50629;&#51008; &#48177;&#44536;&#46972;&#50868;&#46300;&#50640;&#49436; &#49688;&#54665;&#46104;&#47728;, &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#51069;&#44592; &#48143; &#50416;&#44592; &#51089;&#50629;&#50640; &#48120;&#52824;&#45716; &#50689;&#54693;&#51012; &#52572;&#49548;&#54868;&#54616;&#44592; &#50948;&#54644; &#52572;&#51201;&#54868;&#46104;&#50612; &#51080;&#45796;. &#51060;&#47196; &#51064;&#54644; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#44032; &#50868;&#50689; &#51473;&#51068; &#46412;&#46020; &#48177;&#50629; &#51089;&#50629;&#51060; &#50896;&#54876;&#54616;&#44172; &#51652;&#54665;&#46112; &#49688; &#51080;&#45796;.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nnke!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06189ccb-b359-454f-b590-5810c4ca511b_1265x1095.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nnke!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06189ccb-b359-454f-b590-5810c4ca511b_1265x1095.png 424w, https://substackcdn.com/image/fetch/$s_!nnke!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06189ccb-b359-454f-b590-5810c4ca511b_1265x1095.png 848w, https://substackcdn.com/image/fetch/$s_!nnke!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06189ccb-b359-454f-b590-5810c4ca511b_1265x1095.png 1272w, https://substackcdn.com/image/fetch/$s_!nnke!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06189ccb-b359-454f-b590-5810c4ca511b_1265x1095.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nnke!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06189ccb-b359-454f-b590-5810c4ca511b_1265x1095.png" width="1265" height="1095" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/06189ccb-b359-454f-b590-5810c4ca511b_1265x1095.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1095,&quot;width&quot;:1265,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:68745,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nnke!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06189ccb-b359-454f-b590-5810c4ca511b_1265x1095.png 424w, https://substackcdn.com/image/fetch/$s_!nnke!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06189ccb-b359-454f-b590-5810c4ca511b_1265x1095.png 848w, https://substackcdn.com/image/fetch/$s_!nnke!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06189ccb-b359-454f-b590-5810c4ca511b_1265x1095.png 1272w, https://substackcdn.com/image/fetch/$s_!nnke!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06189ccb-b359-454f-b590-5810c4ca511b_1265x1095.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#46608;&#54620;, RDS&#45716; &#53945;&#51221; &#49884;&#51216; &#48373;&#44396;(Point-In-Time Recovery, PITR)&#47484; &#51648;&#50896;&#54620;&#45796;. &#51060; &#44592;&#45733;&#51008; &#49324;&#50857;&#51088;&#44032; &#53945;&#51221; &#49884;&#51216;&#51004;&#47196; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#47484; &#48373;&#44396;&#54624; &#49688; &#51080;&#46020;&#47197; &#54644;&#51456;&#45796;. &#50696;&#47484; &#46308;&#50612;, &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#50640; &#49892;&#49688;&#47196; &#51096;&#47803;&#46108; &#45936;&#51060;&#53552;&#47484; &#51077;&#47141;&#54664;&#44144;&#45208;, &#51473;&#50836; &#45936;&#51060;&#53552;&#47484; &#49325;&#51228;&#54620; &#44221;&#50864;, PITR &#44592;&#45733;&#51012; &#53685;&#54644; &#47928;&#51228; &#48156;&#49373; &#51060;&#51204;&#51032; &#49884;&#51216;&#51004;&#47196; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#47484; &#48373;&#50896;&#54624; &#49688; &#51080;&#45796;. &#51060;&#45716; &#45936;&#51060;&#53552; &#49552;&#49892;&#51012; &#52572;&#49548;&#54868;&#54616;&#44256;, &#48708;&#51592;&#45768;&#49828; &#50672;&#49549;&#49457;&#51012; &#50976;&#51648;&#54616;&#45716; &#45936; &#47588;&#50864; &#50976;&#50857;&#54616;&#45796;.</p><p>&#51088;&#46041; &#48177;&#50629; &#50808;&#50640;&#46020; RDS&#45716; &#49688;&#46041; &#49828;&#45253;&#49399; &#44592;&#45733;&#51012; &#51228;&#44277;&#54620;&#45796;. &#49324;&#50857;&#51088;&#45716; &#54596;&#50836;&#50640; &#46384;&#46972; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#49828;&#45253;&#49399;&#51012; &#49688;&#46041;&#51004;&#47196; &#49373;&#49457;&#54616;&#50668; &#51200;&#51109;&#54624; &#49688; &#51080;&#45796;. &#51060;&#47084;&#54620; &#49688;&#46041; &#49828;&#45253;&#49399;&#51008; &#51088;&#46041; &#48177;&#50629; &#49828;&#45253;&#49399;&#44284; &#47560;&#52268;&#44032;&#51648;&#47196; Amazon S3&#50640; &#51200;&#51109;&#46104;&#47728;, &#49324;&#50857;&#51088;&#44032; &#50896;&#54616;&#45716; &#49884;&#51216;&#50640; &#48373;&#44396;&#54624; &#49688; &#51080;&#45796;. &#49688;&#46041; &#49828;&#45253;&#49399;&#51008; &#53945;&#51221; &#51060;&#48292;&#53944;&#45208; &#50629;&#45936;&#51060;&#53944; &#51204;&#50640; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49345;&#53468;&#47484; &#51200;&#51109;&#54616;&#45716; &#45936; &#50976;&#50857;&#54616;&#47728;, &#51060;&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#48320;&#44221;&#51004;&#47196; &#51064;&#54620; &#50948;&#54744;&#51012; &#44288;&#47532;&#54616;&#45716; &#45936; &#46020;&#50880;&#51012; &#51456;&#45796;.</p><p>RDS&#51032; &#48177;&#50629; &#48373;&#44396; &#44284;&#51221;&#51008; &#47588;&#50864; &#44036;&#45800;&#54616;&#44256; &#51649;&#44288;&#51201;&#51060;&#45796;. &#49324;&#50857;&#51088;&#45716; AWS Management Console, AWS CLI, &#46608;&#45716; RDS API&#47484; &#53685;&#54644; &#48373;&#44396; &#51089;&#50629;&#51012; &#49688;&#54665;&#54624; &#49688; &#51080;&#45796;. &#48373;&#44396; &#51089;&#50629;&#51008; &#49352;&#47196;&#50868; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#51064;&#49828;&#53556;&#49828;&#47196; &#49688;&#54665;&#46104;&#47728;, &#44592;&#51316; &#51064;&#49828;&#53556;&#49828;&#47484; &#44536;&#45824;&#47196; &#50976;&#51648;&#54616;&#47732;&#49436; &#48373;&#44396;&#46108; &#51064;&#49828;&#53556;&#49828;&#47484; &#53580;&#49828;&#53944;&#54624; &#49688; &#51080;&#45796;. &#51060;&#45716; &#48373;&#44396; &#51089;&#50629; &#51473;&#50640; &#44592;&#51316; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#50868;&#50689;&#50640; &#50689;&#54693;&#51012; &#51452;&#51648; &#50506;&#46020;&#47197; &#54616;&#47728;, &#48373;&#44396;&#46108; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#50976;&#54952;&#49457;&#51012; &#44160;&#51613;&#54624; &#49688; &#51080;&#45716; &#50976;&#50672;&#49457;&#51012; &#51228;&#44277;&#54620;&#45796;.</p><p>RDS&#45716; &#46608;&#54620; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#50516;&#54840;&#54868;&#47484; &#51648;&#50896;&#54616;&#50668; &#48177;&#50629; &#45936;&#51060;&#53552;&#51032; &#48372;&#50504;&#51012; &#44053;&#54868;&#54620;&#45796;. RDS &#50516;&#54840;&#54868;&#45716; &#51200;&#51109;&#46108; &#45936;&#51060;&#53552;&#50752; &#51088;&#46041; &#48177;&#50629;, &#49828;&#45253;&#49399;, &#48373;&#51228;&#48376; &#46321;&#51012; &#47784;&#46160; &#50516;&#54840;&#54868;&#54616;&#47728;, AWS Key Management Service(KMS)&#47484; &#53685;&#54644; &#44288;&#47532;&#46108;&#45796;. &#51060;&#47484; &#53685;&#54644; &#45936;&#51060;&#53552;&#51032; &#44592;&#48128;&#49457;&#51012; &#50976;&#51648;&#54616;&#44256;, &#44508;&#51228; &#51456;&#49688; &#50836;&#44396;&#49324;&#54637;&#51012; &#52649;&#51313;&#54624; &#49688; &#51080;&#45796;.</p>]]></content:encoded></item><item><title><![CDATA[Amazon RDS란]]></title><description><![CDATA[Amazon RDS&#50640; &#45824;&#54644; &#50508;&#50500;&#48372;&#51088;]]></description><link>https://www.zerotoexpert.blog/p/amazon-rds</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/amazon-rds</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Mon, 22 Jul 2024 04:46:07 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!GYcP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa125afa6-f461-42ed-81d9-f0ebbc07caaf_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!GYcP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa125afa6-f461-42ed-81d9-f0ebbc07caaf_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!GYcP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa125afa6-f461-42ed-81d9-f0ebbc07caaf_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!GYcP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa125afa6-f461-42ed-81d9-f0ebbc07caaf_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!GYcP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa125afa6-f461-42ed-81d9-f0ebbc07caaf_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!GYcP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa125afa6-f461-42ed-81d9-f0ebbc07caaf_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!GYcP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa125afa6-f461-42ed-81d9-f0ebbc07caaf_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a125afa6-f461-42ed-81d9-f0ebbc07caaf_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:389818,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!GYcP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa125afa6-f461-42ed-81d9-f0ebbc07caaf_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!GYcP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa125afa6-f461-42ed-81d9-f0ebbc07caaf_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!GYcP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa125afa6-f461-42ed-81d9-f0ebbc07caaf_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!GYcP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa125afa6-f461-42ed-81d9-f0ebbc07caaf_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>AWS RDS&#45716; <strong>Amazon Web Services&#51032; &#44288;&#44228;&#54805; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49436;&#48708;&#49828;</strong>&#47196;, &#49324;&#50857;&#51088;&#44032; &#53364;&#46972;&#50864;&#46300; &#54872;&#44221;&#50640;&#49436; &#44288;&#44228;&#54805; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#47484; &#49789;&#44172; &#49444;&#51221;&#54616;&#44256; &#50868;&#50689;&#54624; &#49688; &#51080;&#44172; &#54644;&#51456;&#45796;. RDS&#45716; MySQL, PostgreSQL, MariaDB, Oracle, Microsoft SQL Server &#46321;&#51032; &#45796;&#50577;&#54620; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#50644;&#51652;&#51012; &#51648;&#50896;&#54616;&#47728;, &#49324;&#50857;&#51088;&#45716; &#44033; &#50644;&#51652;&#51032; &#53945;&#51669;&#44284; &#50836;&#44396;&#49324;&#54637;&#50640; &#47582;&#52656; &#49440;&#53469;&#54624; &#49688; &#51080;&#45796;. RDS&#45716; &#44288;&#47532;&#54805; &#49436;&#48708;&#49828;&#47196;, &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#54056;&#52824;, &#48177;&#50629;, &#48373;&#44396;, &#54869;&#51109; &#46321;&#51012; &#51088;&#46041;&#51004;&#47196; &#52376;&#47532;&#54644;&#51452;&#50612; &#49324;&#50857;&#51088;&#51032; &#44288;&#47532; &#48512;&#45812;&#51012; &#53356;&#44172; &#51460;&#50668;&#51456;&#45796;.</p><p></p><h3>RDS&#51032; &#51452;&#50836; &#44592;&#45733;</h3><p>RDS&#51032; &#51452;&#50836; &#44592;&#45733; &#51473; &#54616;&#45208;&#45716; <strong>&#51088;&#46041; &#48177;&#50629; &#44592;&#45733;</strong>&#51060;&#45796;. &#49324;&#50857;&#51088;&#45716; &#48177;&#50629; &#48372;&#44288; &#44592;&#44036;&#51012; &#49444;&#51221;&#54624; &#49688; &#51080;&#51004;&#47728;, RDS&#45716; &#49444;&#51221;&#46108; &#44592;&#44036; &#46041;&#50504; &#51088;&#46041;&#51004;&#47196; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#47484; &#48177;&#50629;&#54616;&#44256; &#48372;&#44288;&#54620;&#45796;. &#51060;&#47084;&#54620; &#51088;&#46041; &#48177;&#50629;&#51008; &#49324;&#50857;&#51088;&#44032; &#51649;&#51217; &#48177;&#50629;&#51012; &#49688;&#54665;&#54616;&#45716; &#44163;&#48372;&#45796; &#45908;&#50865; &#54200;&#47532;&#54616;&#44256; &#50504;&#51204;&#54616;&#45796;. &#46608;&#54620;, &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#51064;&#49828;&#53556;&#49828;&#44032; &#51109;&#50528;&#47484; &#51068;&#51004;&#53420; &#44221;&#50864;, RDS&#45716; &#51088;&#46041;&#51004;&#47196; &#45796;&#47480; &#44032;&#50857; &#50689;&#50669;&#51004;&#47196; &#51109;&#50528; &#51312;&#52824;&#47484; &#49688;&#54665;&#54616;&#50668; &#44256;&#44032;&#50857;&#49457;&#51012; &#48372;&#51109;&#54620;&#45796;. &#51060;&#45716; &#49324;&#50857;&#51088;&#44032; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#50868;&#50689; &#51473;&#45800; &#50630;&#51060; &#50504;&#51221;&#51201;&#51004;&#47196; &#49436;&#48708;&#49828;&#47484; &#51228;&#44277;&#54624; &#49688; &#51080;&#44172; &#54644;&#51456;&#45796;.</p><p>&#46608;&#54620;, RDS&#45716; <strong>&#49828;&#53664;&#47532;&#51648;&#51032; &#54869;&#51109;&#49457;&#51012; &#51228;&#44277;</strong>&#54620;&#45796;. &#52488;&#44592; &#49444;&#51221; &#49884;&#50640; &#54624;&#45817;&#54620; &#49828;&#53664;&#47532;&#51648; &#50857;&#47049;&#51060; &#48512;&#51313;&#54624; &#44221;&#50864;, &#49324;&#50857;&#51088;&#45716; &#44036;&#45800;&#54620; &#49444;&#51221; &#48320;&#44221;&#47564;&#51004;&#47196; &#49828;&#53664;&#47532;&#51648;&#47484; &#54869;&#51109;&#54624; &#49688; &#51080;&#45796;. &#51060;&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#49457;&#51109;&#50640; &#46384;&#46972; &#50976;&#50672;&#54616;&#44172; &#45824;&#51025;&#54624; &#49688; &#51080;&#46020;&#47197; &#54644;&#51456;&#45796;. </p><p>RDS&#45716; &#46608;&#54620; &#51069;&#44592; &#49457;&#45733;&#51012; &#54693;&#49345;&#49884;&#53412;&#44592; &#50948;&#54644; <strong>&#51069;&#44592; &#48373;&#51228;&#48376;(Read Replica)&#51012; &#51648;&#50896;</strong>&#54620;&#45796;. &#51069;&#44592; &#48373;&#51228;&#48376;&#51012; &#49324;&#50857;&#54616;&#47732;, &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#51069;&#44592; &#50836;&#52397;&#51012; &#48373;&#51228;&#48376;&#51004;&#47196; &#48516;&#49328;&#49884;&#53020; &#51452; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#48512;&#54616;&#47484; &#51460;&#51068; &#49688; &#51080;&#45796;. &#51060;&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#49457;&#45733; &#54693;&#49345;&#44284; &#50504;&#51221;&#49457;&#50640; &#53356;&#44172; &#44592;&#50668;&#54620;&#45796;.</p><p>RDS&#45716; &#48372;&#50504; &#52769;&#47732;&#50640;&#49436;&#46020; &#44053;&#47141;&#54620; &#44592;&#45733;&#51012; &#51228;&#44277;&#54620;&#45796;. &#49324;&#50857;&#51088;&#45716; VPC(&#44032;&#49345; &#49324;&#49444; &#53364;&#46972;&#50864;&#46300;)&#47484; &#53685;&#54644; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#47484; &#44201;&#47532;&#46108; &#45348;&#53944;&#50892;&#53356; &#54872;&#44221;&#50640;&#49436; &#50868;&#50689;&#54624; &#49688; &#51080;&#51004;&#47728;, IAM(Identity and Access Management)&#51012; &#53685;&#54644; &#49324;&#50857;&#51088; &#44428;&#54620;&#51012; &#49464;&#48128;&#54616;&#44172; &#44288;&#47532;&#54624; &#49688; &#51080;&#45796;. &#46608;&#54620;, RDS&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#50516;&#54840;&#54868; &#44592;&#45733;&#51012; &#51228;&#44277;&#54616;&#50668; &#51200;&#51109;&#46108; &#45936;&#51060;&#53552;&#47484; &#48372;&#54840;&#54624; &#49688; &#51080;&#45796;. &#51060; &#50516;&#54840;&#54868; &#44592;&#45733;&#51008; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#51064;&#49828;&#53556;&#49828;&#51032; &#49828;&#45253;&#49399;&#44284; &#48177;&#50629;&#50640;&#46020; &#51201;&#50857;&#46104;&#50612; &#45936;&#51060;&#53552; &#48372;&#50504;&#49457;&#51012; &#45908;&#50865; &#45458;&#51064;&#45796;.</p><p>RDS&#45716; &#47784;&#45768;&#53552;&#47553; &#44592;&#45733;&#46020; &#51228;&#44277;&#54620;&#45796;. Amazon CloudWatch&#50752; &#53685;&#54633;&#46104;&#50612; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#49457;&#45733; &#51648;&#54364;&#47484; &#49892;&#49884;&#44036;&#51004;&#47196; &#47784;&#45768;&#53552;&#47553;&#54624; &#49688; &#51080;&#45796;. &#49324;&#50857;&#51088;&#45716; CPU &#49324;&#50857;&#47456;, &#47700;&#47784;&#47532; &#49324;&#50857;&#47456;, &#46356;&#49828;&#53356; I/O &#46321;&#51032; &#51648;&#54364;&#47484; &#53685;&#54644; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#49345;&#53468;&#47484; &#54028;&#50501;&#54616;&#44256;, &#54596;&#50836;&#50640; &#46384;&#46972; &#51312;&#52824;&#47484; &#52712;&#54624; &#49688; &#51080;&#45796;. &#46608;&#54620;, RDS&#45716; &#44221;&#44256; &#44592;&#45733;&#51012; &#53685;&#54644; &#53945;&#51221; &#51648;&#54364;&#44032; &#51076;&#44228;&#44050;&#51012; &#52488;&#44284;&#54624; &#44221;&#50864; &#50508;&#47548;&#51012; &#48155;&#51012; &#49688; &#51080;&#46020;&#47197; &#49444;&#51221;&#54624; &#49688; &#51080;&#45796;. &#51060;&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#47928;&#51228;&#47484; &#49324;&#51204;&#50640; &#44048;&#51648;&#54616;&#44256; &#45824;&#51025;&#54624; &#49688; &#51080;&#44172; &#54644;&#51456;&#45796;.</p><p></p><h3>RDS &#48708;&#50857; &#48143; &#49324;&#50857; &#49324;&#47168;</h3><p>RDS&#51032; &#48708;&#50857; &#44396;&#51312;&#45716; &#49324;&#50857;&#51088;&#44032; &#49440;&#53469;&#54620; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#50644;&#51652;, &#51064;&#49828;&#53556;&#49828; &#50976;&#54805;, &#49828;&#53664;&#47532;&#51648; &#50857;&#47049; &#46321;&#50640; &#46384;&#46972; &#45796;&#47476;&#45796;. &#49324;&#50857;&#51088;&#45716; &#54596;&#50836;&#50640; &#46384;&#46972; &#45796;&#50577;&#54620; &#51064;&#49828;&#53556;&#49828; &#50976;&#54805;&#51012; &#49440;&#53469;&#54624; &#49688; &#51080;&#51004;&#47728;, &#48708;&#50857; &#51208;&#44048;&#51012; &#50948;&#54644; &#50696;&#50557; &#51064;&#49828;&#53556;&#49828;&#47484; &#49324;&#50857;&#54624; &#49688;&#46020; &#51080;&#45796;. &#46608;&#54620;, RDS&#45716; &#49324;&#50857;&#47049; &#44592;&#48152; &#44284;&#44552; &#48169;&#49885;&#51012; &#52292;&#53469;&#54616;&#50668; &#49324;&#50857;&#51088;&#44032; &#49892;&#51228;&#47196; &#49324;&#50857;&#54620; &#47532;&#49548;&#49828;&#50640; &#45824;&#54644;&#49436;&#47564; &#48708;&#50857;&#51012; &#51648;&#48520;&#54616;&#46020;&#47197; &#54620;&#45796;. &#51060;&#45716; &#48520;&#54596;&#50836;&#54620; &#48708;&#50857;&#51012; &#51208;&#44048;&#54616;&#44256; &#54952;&#50984;&#51201;&#51004;&#47196; &#50696;&#49328;&#51012; &#44288;&#47532;&#54624; &#49688; &#51080;&#44172; &#54644;&#51456;&#45796;.</p><p>RDS&#51032; &#49324;&#50857; &#49324;&#47168;&#45716; &#47588;&#50864; &#45796;&#50577;&#54616;&#45796;. &#50937; &#50528;&#54540;&#47532;&#52992;&#51060;&#49496;&#51032; &#48177;&#50644;&#46300; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#47196;&#49436;, &#48709;&#45936;&#51060;&#53552; &#48516;&#49437;&#51012; &#50948;&#54620; &#45936;&#51060;&#53552; &#50920;&#50612;&#54616;&#50864;&#49828;&#47196;&#49436;, &#44536;&#47532;&#44256; &#45796;&#50577;&#54620; &#48708;&#51592;&#45768;&#49828; &#50528;&#54540;&#47532;&#52992;&#51060;&#49496;&#51032; &#45936;&#51060;&#53552; &#51200;&#51109;&#49548;&#47196;&#49436; RDS&#47484; &#54876;&#50857;&#54624; &#49688; &#51080;&#45796;. &#53945;&#55176;, &#54869;&#51109;&#49457;&#44284; &#44256;&#44032;&#50857;&#49457;&#51012; &#50836;&#44396;&#54616;&#45716; &#50528;&#54540;&#47532;&#52992;&#51060;&#49496;&#50640;&#49436; RDS&#51032; &#51109;&#51216;&#51060; &#45908;&#50865; &#46160;&#46300;&#47084;&#51652;&#45796;. &#51060;&#45716; RDS&#44032; &#45800;&#49692;&#55176; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#47484; &#54840;&#49828;&#54021;&#54616;&#45716; &#44163;&#51012; &#45336;&#50612;, &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#51032; &#50868;&#50689;&#44284; &#44288;&#47532;&#50640; &#54596;&#50836;&#54620; &#45796;&#50577;&#54620; &#44592;&#45733;&#51012; &#51228;&#44277;&#54616;&#44592; &#46412;&#47928;&#51060;&#45796;.</p><div><hr></div><p>&#44208;&#47200;&#51201;&#51004;&#47196;, AWS RDS&#45716; &#53364;&#46972;&#50864;&#46300; &#54872;&#44221;&#50640;&#49436; &#44288;&#44228;&#54805; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828;&#47484; &#54952;&#50984;&#51201;&#51004;&#47196; &#50868;&#50689;&#54624; &#49688; &#51080;&#46020;&#47197; &#46037;&#45716; &#44053;&#47141;&#54620; &#46020;&#44396;&#51060;&#45796;. &#51088;&#46041;&#54868;&#46108; &#44288;&#47532; &#44592;&#45733;, &#45458;&#51008; &#44032;&#50857;&#49457;, &#54869;&#51109;&#49457;, &#48372;&#50504; &#44592;&#45733; &#46321;&#51012; &#53685;&#54644; &#49324;&#50857;&#51088;&#45716; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#44288;&#47532;&#51032; &#48373;&#51105;&#49457;&#51012; &#51460;&#51060;&#44256;, &#48708;&#51592;&#45768;&#49828;&#50640; &#51665;&#51473;&#54624; &#49688; &#51080;&#45796;. RDS&#45716; &#45796;&#50577;&#54620; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#50644;&#51652;&#51012; &#51648;&#50896;&#54616;&#50668; &#49324;&#50857;&#51088;&#51032; &#50836;&#44396;&#49324;&#54637;&#50640; &#47582;&#44172; &#49440;&#53469;&#54624; &#49688; &#51080;&#51004;&#47728;, &#48708;&#50857; &#54952;&#50984;&#51201;&#51064; &#50868;&#50689;&#51012; &#44032;&#45733;&#54616;&#44172; &#54620;&#45796;. &#51060;&#47084;&#54620; &#51216;&#50640;&#49436; RDS&#45716; &#53364;&#46972;&#50864;&#46300; &#44592;&#48152; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49556;&#47336;&#49496;&#51004;&#47196;&#49436; &#47588;&#50864; &#50976;&#50857;&#54616;&#45796;.</p>]]></content:encoded></item><item><title><![CDATA[샤딩(Sharding)]]></title><description><![CDATA[&#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49380;&#46377;&#50640; &#45824;&#54644;&#49436; &#50508;&#50500;&#48372;&#51088;.]]></description><link>https://www.zerotoexpert.blog/p/sharding</link><guid isPermaLink="false">https://www.zerotoexpert.blog/p/sharding</guid><dc:creator><![CDATA[Gwonsoo Lee]]></dc:creator><pubDate>Mon, 22 Jul 2024 04:11:03 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Rcp8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccc09743-dd1a-4054-8561-ba82236dbbd9_800x600.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Rcp8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccc09743-dd1a-4054-8561-ba82236dbbd9_800x600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Rcp8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccc09743-dd1a-4054-8561-ba82236dbbd9_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!Rcp8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccc09743-dd1a-4054-8561-ba82236dbbd9_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!Rcp8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccc09743-dd1a-4054-8561-ba82236dbbd9_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!Rcp8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccc09743-dd1a-4054-8561-ba82236dbbd9_800x600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Rcp8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccc09743-dd1a-4054-8561-ba82236dbbd9_800x600.png" width="800" height="600" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ccc09743-dd1a-4054-8561-ba82236dbbd9_800x600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:600,&quot;width&quot;:800,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:388950,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Rcp8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccc09743-dd1a-4054-8561-ba82236dbbd9_800x600.png 424w, https://substackcdn.com/image/fetch/$s_!Rcp8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccc09743-dd1a-4054-8561-ba82236dbbd9_800x600.png 848w, https://substackcdn.com/image/fetch/$s_!Rcp8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccc09743-dd1a-4054-8561-ba82236dbbd9_800x600.png 1272w, https://substackcdn.com/image/fetch/$s_!Rcp8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fccc09743-dd1a-4054-8561-ba82236dbbd9_800x600.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>&#45936;&#51060;&#53552;&#48288;&#51060;&#49828; <strong>&#49380;&#46377;&#51008; &#45824;&#44508;&#47784; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49884;&#49828;&#53596;&#50640;&#49436; &#45936;&#51060;&#53552;&#51032; &#49457;&#45733;&#44284; &#54869;&#51109;&#49457;&#51012; &#54693;&#49345;&#49884;&#53412;&#44592; &#50948;&#54620; &#51473;&#50836;&#54620; &#44592;&#49696;</strong>&#51060;&#45796;. &#51060; &#44060;&#45392;&#51008; &#45936;&#51060;&#53552;&#47484; &#51089;&#51008; &#45800;&#50948;&#47196; &#48516;&#54624;&#54616;&#50668; &#50668;&#47084; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49436;&#48260;&#50640; &#48516;&#49328; &#51200;&#51109;&#54616;&#45716; &#44163;&#51012; &#51032;&#48120;&#54620;&#45796;. &#49380;&#46377;&#51012; &#53685;&#54644; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49884;&#49828;&#53596;&#51008; &#49688;&#54217;&#51201;&#51004;&#47196; &#54869;&#51109; &#44032;&#45733;&#54644;&#51648;&#47728;, &#51060;&#45716; &#54620; &#49436;&#48260;&#51032; &#51088;&#50896;&#51060; &#48512;&#51313;&#54644;&#51656; &#46412; &#52628;&#44032; &#49436;&#48260;&#47484; &#52628;&#44032;&#54616;&#50668; &#52376;&#47532; &#50857;&#47049;&#51012; &#45720;&#47540; &#49688; &#51080;&#51020;&#51012; &#51032;&#48120;&#54620;&#45796;.</p><p></p><h3>&#49380;&#46377; &#48169;&#49885;</h3><p>&#49380;&#46377;&#51008; &#53356;&#44172; &#46160; &#44032;&#51648; &#48169;&#49885;&#51004;&#47196; &#45208;&#45580; &#49688; &#51080;&#45796;. </p><p>&#52395; &#48264;&#51704;&#45716; <strong>&#49688;&#54217; &#49380;&#46377;</strong>&#51060;&#45796;. &#49688;&#54217; &#49380;&#46377;&#50640;&#49436;&#45716; &#44033; &#53580;&#51060;&#48660;&#51032; &#47196;&#50864;&#47484; &#50668;&#47084; &#49436;&#48260;&#50640; &#45208;&#45572;&#50612; &#51200;&#51109;&#54620;&#45796;. &#50696;&#47484; &#46308;&#50612;, &#49324;&#50857;&#51088; &#53580;&#51060;&#48660;&#51060; &#51080;&#45796;&#44256; &#44032;&#51221;&#54616;&#47732;, &#49324;&#50857;&#51088; ID&#47484; &#44592;&#51456;&#51004;&#47196; &#53945;&#51221; &#48276;&#50948;&#51032; &#49324;&#50857;&#51088; &#45936;&#51060;&#53552;&#47484; &#44033;&#44592; &#45796;&#47480; &#49436;&#48260;&#50640; &#48516;&#49328; &#51200;&#51109;&#54624; &#49688; &#51080;&#45796;. &#51060;&#47111;&#44172; &#54616;&#47732; &#53945;&#51221; &#49436;&#48260;&#50640; &#45824;&#54620; &#48512;&#45812;&#51060; &#51460;&#50612;&#46308;&#44256;, &#44033; &#49436;&#48260;&#45716; &#51088;&#49888;&#50640;&#44172; &#54624;&#45817;&#46108; &#45936;&#51060;&#53552;&#47564; &#52376;&#47532;&#54616;&#47732; &#46104;&#48064;&#47196; &#51204;&#52404; &#49884;&#49828;&#53596;&#51032; &#49457;&#45733;&#51060; &#54693;&#49345;&#46108;&#45796;.</p><p>&#46160; &#48264;&#51704; &#48169;&#49885;&#51008; <strong>&#49688;&#51649; &#49380;&#46377;</strong>&#51060;&#45796;. &#49688;&#51649; &#49380;&#46377;&#50640;&#49436;&#45716; &#53580;&#51060;&#48660;&#51012; &#52972;&#47100; &#45800;&#50948;&#47196; &#45208;&#45572;&#50612; &#51200;&#51109;&#54620;&#45796;. &#50696;&#47484; &#46308;&#50612;, &#49324;&#50857;&#51088; &#53580;&#51060;&#48660;&#51032; &#44221;&#50864;, &#49324;&#50857;&#51088;&#51032; &#44592;&#48376; &#51221;&#48372;(&#51060;&#47492;, &#51060;&#47700;&#51068; &#46321;)&#45716; &#54620; &#49436;&#48260;&#50640; &#51200;&#51109;&#54616;&#44256;, &#49324;&#50857;&#51088;&#51032; &#54876;&#46041; &#44592;&#47197;(&#47196;&#44536;&#51064; &#44592;&#47197;, &#51452;&#47928; &#45236;&#50669; &#46321;)&#51008; &#45796;&#47480; &#49436;&#48260;&#50640; &#51200;&#51109;&#54624; &#49688; &#51080;&#45796;. &#51060;&#47111;&#44172; &#54616;&#47732; &#53945;&#51221; &#53244;&#47532;&#45208; &#51089;&#50629;&#51060; &#53945;&#51221; &#49436;&#48260;&#50640; &#51665;&#51473;&#46104;&#51648; &#50506;&#44256; &#48516;&#49328;&#46104;&#50612; &#52376;&#47532;&#54624; &#49688; &#51080;&#44172; &#46104;&#50612; &#49457;&#45733;&#51060; &#54693;&#49345;&#46108;&#45796;.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LbHx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06509e02-1410-4f25-9d82-e049619c4652_1946x1831.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LbHx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06509e02-1410-4f25-9d82-e049619c4652_1946x1831.png 424w, https://substackcdn.com/image/fetch/$s_!LbHx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06509e02-1410-4f25-9d82-e049619c4652_1946x1831.png 848w, https://substackcdn.com/image/fetch/$s_!LbHx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06509e02-1410-4f25-9d82-e049619c4652_1946x1831.png 1272w, https://substackcdn.com/image/fetch/$s_!LbHx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06509e02-1410-4f25-9d82-e049619c4652_1946x1831.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LbHx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06509e02-1410-4f25-9d82-e049619c4652_1946x1831.png" width="1456" height="1370" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/06509e02-1410-4f25-9d82-e049619c4652_1946x1831.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1370,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:176921,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!LbHx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06509e02-1410-4f25-9d82-e049619c4652_1946x1831.png 424w, https://substackcdn.com/image/fetch/$s_!LbHx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06509e02-1410-4f25-9d82-e049619c4652_1946x1831.png 848w, https://substackcdn.com/image/fetch/$s_!LbHx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06509e02-1410-4f25-9d82-e049619c4652_1946x1831.png 1272w, https://substackcdn.com/image/fetch/$s_!LbHx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06509e02-1410-4f25-9d82-e049619c4652_1946x1831.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p></p><p>&#49380;&#46377;&#51012; &#44396;&#54788;&#54624; &#46412;&#45716; <strong>&#49380;&#46377; &#53412;&#51032; &#49440;&#53469;&#51060; &#47588;&#50864; &#51473;&#50836;</strong>&#54616;&#45796;. &#49380;&#46377; &#53412;&#45716; &#45936;&#51060;&#53552;&#47484; &#48516;&#54624;&#54616;&#45716; &#44592;&#51456;&#51060; &#46104;&#45716; &#44050;&#51004;&#47196;, &#51096;&#47803;&#46108; &#49380;&#46377; &#53412;&#47484; &#49440;&#53469;&#54616;&#47732; &#45936;&#51060;&#53552;&#44032; &#44256;&#47476;&#44172; &#48516;&#49328;&#46104;&#51648; &#50506;&#44256; &#53945;&#51221; &#49436;&#48260;&#50640; &#45936;&#51060;&#53552;&#44032; &#51665;&#51473;&#46112; &#49688; &#51080;&#45796;. &#51060;&#45716; &#53945;&#51221; &#49436;&#48260;&#51032; &#48512;&#54616;&#47484; &#51613;&#44032;&#49884;&#53412;&#44256; &#51204;&#52404; &#49884;&#49828;&#53596;&#51032; &#49457;&#45733; &#51200;&#54616;&#47484; &#52488;&#47000;&#54624; &#49688; &#51080;&#45796;. &#46384;&#46972;&#49436; &#49380;&#46377; &#53412;&#45716; &#45936;&#51060;&#53552;&#51032; &#44256;&#47480; &#48516;&#54252;&#47484; &#48372;&#51109;&#54624; &#49688; &#51080;&#46020;&#47197; &#49888;&#51473;&#54616;&#44172; &#49440;&#53469;&#54644;&#50556; &#54620;&#45796;.</p><p></p><h3>&#49380;&#46377;&#51032; &#51109;&#51216;</h3><p><strong>&#49380;&#46377;&#51032; &#51109;&#51216;&#51008; &#47924;&#50631;&#48372;&#45796;&#46020; &#49884;&#49828;&#53596;&#51032; &#54869;&#51109;&#49457;&#44284; &#49457;&#45733;&#51012; &#54693;&#49345;&#49884;&#53420; &#49688; &#51080;&#45796;&#45716; &#51216;</strong>&#51060;&#45796;. &#45800;&#51068; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49436;&#48260;&#51032; &#52376;&#47532; &#50857;&#47049;&#51060; &#54620;&#44228;&#50640; &#46020;&#45804;&#54616;&#47732;, &#52628;&#44032; &#49436;&#48260;&#47484; &#53685;&#54644; &#50857;&#47049;&#51012; &#54869;&#51109;&#54624; &#49688; &#51080;&#45796;. &#46608;&#54620;, &#50668;&#47084; &#49436;&#48260;&#50640; &#45936;&#51060;&#53552;&#47484; &#48516;&#49328; &#51200;&#51109;&#54632;&#51004;&#47196;&#50024; &#53244;&#47532; &#52376;&#47532; &#49549;&#46020;&#44032; &#48744;&#46972;&#51648;&#44256;, &#45936;&#51060;&#53552; &#51069;&#44592; &#48143; &#50416;&#44592; &#51089;&#50629;&#51060; &#48337;&#47148;&#47196; &#49688;&#54665;&#46112; &#49688; &#51080;&#45796;.</p><p>&#54616;&#51648;&#47564; &#49380;&#46377;&#50640;&#45716; &#47751; &#44032;&#51648; &#45800;&#51216;&#46020; &#51316;&#51116;&#54620;&#45796;. &#52395;&#51704;, <strong>&#49884;&#49828;&#53596;&#51032; &#48373;&#51105;&#46020;&#44032; &#51613;&#44032;</strong>&#54620;&#45796;. &#50668;&#47084; &#49436;&#48260;&#50640; &#45936;&#51060;&#53552;&#47484; &#48516;&#49328; &#51200;&#51109;&#54616;&#44592; &#46412;&#47928;&#50640; &#45936;&#51060;&#53552; &#51068;&#44288;&#49457;&#51012; &#50976;&#51648;&#54616;&#45716; &#44163;&#51060; &#50612;&#47140;&#50892;&#51652;&#45796;. &#50696;&#47484; &#46308;&#50612;, &#50668;&#47084; &#49436;&#48260;&#50640; &#44152;&#52828; &#53944;&#47004;&#51117;&#49496;&#51012; &#44288;&#47532;&#54616;&#45716; &#44163;&#51008; &#47588;&#50864; &#48373;&#51105;&#54624; &#49688; &#51080;&#51004;&#47728;, &#51060;&#45716; &#44060;&#48156; &#48143; &#50976;&#51648; &#48372;&#49688; &#48708;&#50857;&#51012; &#51613;&#44032;&#49884;&#53416;&#45796;. &#46168;&#51704;, &#49380;&#46377; &#53412;&#51032; &#48320;&#44221;&#51060; &#50612;&#47157;&#45796;. &#54620;&#48264; &#49380;&#46377; &#53412;&#47484; &#49440;&#53469;&#54616;&#44256; &#45936;&#51060;&#53552;&#47484; &#48516;&#49328; &#51200;&#51109;&#54616;&#47732;, &#49380;&#46377; &#53412;&#47484; &#48320;&#44221;&#54616;&#44592; &#50948;&#54644;&#49436;&#45716; &#51204;&#52404; &#45936;&#51060;&#53552;&#47484; &#45796;&#49884; &#48516;&#49328; &#51200;&#51109;&#54644;&#50556; &#54616;&#45716; &#48264;&#44144;&#47196;&#50880;&#51060; &#51080;&#45796;.</p><p>&#49380;&#46377;&#51032; &#46608; &#45796;&#47480; &#44256;&#47140; &#49324;&#54637;&#51008; &#45936;&#51060;&#53552; &#51060;&#46041;&#51060;&#45796;. &#49436;&#48260; &#44036;&#51032; &#45936;&#51060;&#53552; &#51060;&#46041;&#51008; &#45348;&#53944;&#50892;&#53356; &#48708;&#50857;&#51012; &#48156;&#49373;&#49884;&#53412;&#44256;, &#45936;&#51060;&#53552; &#51060;&#46041; &#51473;&#50640;&#45716; &#49436;&#48708;&#49828; &#44032;&#50857;&#49457;&#51060; &#46504;&#50612;&#51656; &#49688; &#51080;&#45796;. &#46384;&#46972;&#49436; &#49380;&#46377;&#51012; &#44228;&#54925;&#54624; &#46412;&#45716; &#51060;&#47084;&#54620; &#45348;&#53944;&#50892;&#53356; &#48708;&#50857;&#44284; &#44032;&#50857;&#49457; &#47928;&#51228;&#47484; &#52649;&#48516;&#55176; &#44256;&#47140;&#54644;&#50556; &#54620;&#45796;.</p><p>&#51333;&#54633;&#51201;&#51004;&#47196;, &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49380;&#46377;&#51008; &#45824;&#44508;&#47784; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49884;&#49828;&#53596;&#51032; &#49457;&#45733;&#44284; &#54869;&#51109;&#49457;&#51012; &#45458;&#51060;&#45716; &#45936; &#47588;&#50864; &#50976;&#50857;&#54620; &#44592;&#49696;&#51060;&#45796;. &#49380;&#46377;&#51012; &#53685;&#54644; &#45936;&#51060;&#53552; &#52376;&#47532; &#45733;&#47141;&#51012; &#54693;&#49345;&#49884;&#53412;&#44256;, &#49884;&#49828;&#53596;&#51032; &#50857;&#47049;&#51012; &#50976;&#50672;&#54616;&#44172; &#54869;&#51109;&#54624; &#49688; &#51080;&#45796;. </p><p>&#44536;&#47084;&#45208; &#49380;&#46377;&#51012; &#44396;&#54788;&#54624; &#46412;&#45716; &#49380;&#46377; &#53412;&#51032; &#49440;&#53469;, &#45936;&#51060;&#53552; &#51068;&#44288;&#49457; &#50976;&#51648;, &#45936;&#51060;&#53552; &#51060;&#46041; &#46321;&#51032; &#50668;&#47084; &#44032;&#51648; &#44256;&#47140; &#49324;&#54637;&#51012; &#49888;&#51473;&#54616;&#44172; &#54032;&#45800;&#54644;&#50556; &#54620;&#45796;. &#51060;&#47084;&#54620; &#51216;&#51012; &#52649;&#48516;&#55176; &#44256;&#47140;&#54616;&#50668; &#49380;&#46377;&#51012; &#50732;&#48148;&#47476;&#44172; &#44396;&#54788;&#54616;&#47732;, &#45824;&#44508;&#47784; &#45936;&#51060;&#53552;&#48288;&#51060;&#49828; &#49884;&#49828;&#53596;&#50640;&#49436; &#54952;&#50984;&#51201;&#51060;&#44256; &#50504;&#51221;&#51201;&#51064; &#45936;&#51060;&#53552; &#52376;&#47532;&#44032; &#44032;&#45733;&#54644;&#51652;&#45796;.</p>]]></content:encoded></item></channel></rss>