<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Juan M. Alonso]]></title><description><![CDATA[Software Engineer. Always be closing.]]></description><link>https://www.j1nma.com</link><generator>GatsbyJS</generator><lastBuildDate>Sat, 27 Apr 2024 15:47:39 GMT</lastBuildDate><item><title><![CDATA[115 días para desarmar la bomba]]></title><description><![CDATA[Curiosidades y hechos de la crisis 2001-2002 en la voz del ex-ministro Jorge Remes Lenicov]]></description><link>https://www.j1nma.com/115-dias-para-desarmar-la-bomba/</link><guid isPermaLink="false">https://www.j1nma.com/115-dias-para-desarmar-la-bomba/</guid><pubDate>Thu, 28 Dec 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;En un poco más de 200 páginas, Jorge Remes Lenicov, Ministro de Economía durante la Presidencia de Duhalde en la crisis post 2001, explica la hecatombe argentina de aquel entonces, cuenta los entretelones políticos detrás de su plan y define una serie de medidas para que no caigamos nuevamente en la perdición.&lt;/p&gt;
&lt;p&gt;En este blog, intento rescatar lo más interesante de la Parte I para entender las cuestiones difíciles de comprender, al menos para los que éramos muy chicos, de esta etapa que marcó una época.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Algunas citas a continuación están incluídas textuales del libro, otras fueron parafraseadas, y algunas otras digeridas por mí.&lt;/em&gt;&lt;/p&gt;
&lt;!-- TOC depthto:2 --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#c3-el-que-desposit%C3%B3-d%C3%B3lares-recibir%C3%A1-d%C3%B3lares-la-estrategia-econ%C3%B3mica-&quot;&gt;C3: &quot;El que despositó dólares, recibirá dólares&quot;: la estrategia económica 💵&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c4-se-empieza-a-desactivar-la-bomba-y-la-convertibilidad-&quot;&gt;C4: Se empieza a desactivar la bomba y la convertibilidad 💱&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c5-una-decisi%C3%B3n-dif%C3%ADcil-la-pesificaci%C3%B3n-&quot;&gt;C5: Una decisión difícil: la pesificación ⚖️&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c6-el-desarme-del-corralito-&quot;&gt;C6: El desarme del &apos;corralito&apos; 🚪&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c7-la-crisis-de-los-contratos-&quot;&gt;C7: La crisis de los contratos 📃&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c8-desdolarizaci%C3%B3n-y-desindexaci%C3%B3n-de-las-tarifas-de-los-servicios-p%C3%BAblicos-%F0%9F%A7%BE&quot;&gt;C8: Desdolarización y desindexación de las tarifas de los servicios públicos 🧾&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c9-una-de-las-grandes-batallas-equilibrio-fiscal-consolidado-&quot;&gt;C9: Una de las grandes batallas: equilibrio fiscal consolidado 🤸&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c10-anclaje-monetario-y-pol%C3%ADtica-financiera-&quot;&gt;C10: Anclaje monetario y política financiera 🏦&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c11-la-hora-de-las-retenciones-%EF%B8%8F&quot;&gt;C11: La hora de las retenciones ⏰️&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c12-la-negociaci%C3%B3n-con-el-fmi-&quot;&gt;C12: La negociación con el FMI 🤝&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c13-el-trabajo-dio-sus-frutos-&quot;&gt;C13: El trabajo dio sus frutos 🍋&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#conclusi%C3%B3n&quot;&gt;Conclusión&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- /TOC --&gt;
&lt;h2 id=&quot;c3-el-que-despositó-dólares-recibirá-dólares-la-estrategia-económica-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c3-el-que-desposit%C3%B3-d%C3%B3lares-recibir%C3%A1-d%C3%B3lares-la-estrategia-econ%C3%B3mica-&quot; aria-label=&quot;c3 el que despositó dólares recibirá dólares la estrategia económica  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C3: &quot;El que despositó dólares, recibirá dólares&quot;: la estrategia económica 💵&lt;/h2&gt;
&lt;p&gt;El primer capítulo es un repaso de la entrada de Jorge Remes Lenicov y equipo al mando del Ministerio de Economía, y el segundo un resumen del panorama económico colapsado de aquel entonces. En el tercer capítulo la trama se pone más interesante, por esto salteo los primeros 2.&lt;/p&gt;
&lt;p&gt;El 2 de enero de 2002, Duhalde dio su discurso inagural como Presidente ante el Congreso. En él, pronunció la frase que titula al capítulo y que quedaría en la historia. Semejante imprudencia significó un baldazo de agua fría para el autor del libro, que estaba tranquilo porque había revisado el discurso junto con Duhalde durante la noche del 31 de diciembre.&lt;/p&gt;
&lt;p&gt;El equipo de JRL, que ya se había comprometido a asumir con un plan que repasaremos en los próximos capítulos, nunca pensó que se podrían devolver los dólares al vencimiento de las obligaciones originales, ni en un plazo razonable: eso era imposible, porque los dólares depositados por los ahorristas (o pesos convertidos) &lt;em&gt;no estaban&lt;/em&gt; en los bancos. Habían sido prestados a familias y empresas que se encontraban con enormes dificultades para devolverlos (!).&lt;/p&gt;
&lt;p&gt;Evidentemente, alguien convenció a Duhalde entre el 31 y el 2 de cambiar el discurso y agregar esa frase. Probablemente, se debió al temor que había ante una revuelta popular. La sociedad no tenía paciencia ni motivación para escuchar explicaciones. Lo cierto es que después JRL tuvo que desmentirlo tres días después.&lt;/p&gt;
&lt;h3 id=&quot;otra-imprudencia&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#otra-imprudencia&quot; aria-label=&quot;otra imprudencia permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Otra imprudencia&lt;/h3&gt;
&lt;p&gt;Menos de un mes después, un grupo de legisladores del Partido Justicialista y de la Unión Cívica Radical convencieron a Duhalde y a Alfonsín de enjuiciar a toda la Corte Suprema de Justicia. Más allá del razonamiento que se tuviera sobre el desempeño de sus integrantes durante el gobierno de Carlos Menem, la consecuencia no deseada de esta decisión fue el serio enfrentamiento con el máximo tribunal de justicia, que tenía en sus manos la potestad de invalidar cualquier medida del plan de emergencia.&lt;/p&gt;
&lt;h3 id=&quot;habano&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#habano&quot; aria-label=&quot;habano permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Habano&lt;/h3&gt;
&lt;p&gt;Tal fue el error de Duhalde que JRL fue personalmente a ver al presidente de la Corte, Julio Nazareno, para explicarle que era fundamental para la economía que no se abriera el &lt;em&gt;corralito&lt;/em&gt; porque eso podría hacer que los pesos salieran al mercado, se fueran al dólar e hicieran disparar la cotización. Nazareno, fumando un habano, le dijo: &quot;Ahora nosotros estamos preocupados por este tema del juicio político, así que no tenemos tiempo para atender y estudiar ese pedido&quot;. Así fue como autorizaron a abrir el &lt;em&gt;corralito&lt;/em&gt;, lloviendo cautelares y habilitando la salida de pesos del mercado.&lt;/p&gt;
&lt;h3 id=&quot;dejame-tranquilo-con-mis-temas&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#dejame-tranquilo-con-mis-temas&quot; aria-label=&quot;dejame tranquilo con mis temas permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Dejame tranquilo con mis temas&lt;/h3&gt;
&lt;p&gt;Las decisiones que JRL debía tomar requerían, según él, máxima celeridad. No podía sentarse a debatir con otros ministros que no son del área económica cada vez que correspondía tomarse una medida en cuanto a impuestos, retenciones, tipo de cambio, etc. Las discusiones que tuvo JRL a nivel interno fueron tan difíciles como las que se suscitaron con los que estaban afuera del gobierno. Duhalde lo apoyó en esto: &quot;No presentés más el presupuesto en la reunión de gabinete. Lo arreglamos nosotros dos, después vos un día lo presentas ya cocinado, yo te cambio de tema y chau&quot;.&lt;/p&gt;
&lt;h3 id=&quot;60-días&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#60-d%C3%ADas&quot; aria-label=&quot;60 días permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;60 días&lt;/h3&gt;
&lt;p&gt;En sesenta días se adoptaron las diez medidas centrales. Esto sucedió gracias a:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;acuerdo con los radicales para tener mayoría en el Congreso&lt;/li&gt;
&lt;li&gt;Ley de Emergencia con muchas de la medidas&lt;/li&gt;
&lt;li&gt;acuerdo con las provincias&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Las medidas:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;div style=&quot;width:200px&quot;&gt;Medida&lt;/div&gt;&lt;/th&gt;
&lt;th&gt;Implementación&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Política cambiaria&lt;/td&gt;
&lt;td&gt;Se formalizó la salida de la convertibilidad. Devaluación, flotación administrada y control de cambios parcial.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pesificación y contratos&lt;/td&gt;
&lt;td&gt;Conversión a pesos de las obligaciones contraídas en dólares. Las deudas se pesificaron a 1 por 1 y se actualizaron por Coeficiente de Estabilización de Referencia (CER) más tasa de interés; los depósitos se pesificaron a 1,40 por 1 y se actualizaron por CER más tasa de interés, y los contratos privados se pesificaron según costos compartidos. Ese tipo de actualización rigió solo para las deudas anteriores, pero no para las que se contrajeran en el futuro. No hubo seguro de cambios.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Desarme del «corralito»&lt;/td&gt;
&lt;td&gt;Reprogramación de los depósitos y alternativas para retirar los fondos. Opciones para nuevos depósitos. Contraproducente actitud de la Corte Suprema de Justicia.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Política fiscal consolidada&lt;/td&gt;
&lt;td&gt;Se rehízo el Presupuesto Nacional con superávit primario y se impulsaron reformas en la política y administración tributarias. Se firmó un acuerdo entre la Nación y las provincias para reducir el déficit provincial, iniciar el ordenamiento fiscal, normalizar el régimen de coparticipación y eliminar las cuasimonedas.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Política monetaria y financiera&lt;/td&gt;
&lt;td&gt;Reforma de la Carta Orgánica para que el Banco Central de la República Argentina sea prestamista de última instancia y actúe en el mercado cambiario. Expansión monetaria restrictiva e inicio de operaciones de mercado abierto. Política de redescuentos para evitar la caída de bancos.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Derechos de exportación&lt;/td&gt;
&lt;td&gt;Se establecieron de manera decreciente según el mayor el grado de elaboración.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Deuda pública&lt;/td&gt;
&lt;td&gt;Reducción en dólares de la deuda pública interna por su pesificación.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tarifas&lt;/td&gt;
&lt;td&gt;Conversión a pesos, congelamiento transitorio y renegociación limitada de las concesiones.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Salarios&lt;/td&gt;
&lt;td&gt;Se pospuso su incremento para concentrarse en la creación de empleo.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Normalización de las relaciones financieras con el mundo&lt;/td&gt;
&lt;td&gt;Se iniciaron conversaciones con el FMI y otros organismos financieros internacionales.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;c4-se-empieza-a-desactivar-la-bomba-y-la-convertibilidad-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c4-se-empieza-a-desactivar-la-bomba-y-la-convertibilidad-&quot; aria-label=&quot;c4 se empieza a desactivar la bomba y la convertibilidad  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C4: Se empieza a desactivar la bomba y la convertibilidad 💱&lt;/h2&gt;
&lt;p&gt;Durante la década de pizza con champagne (¿o ahora se dice &apos;espumante&apos;?) la economía entera se acomodó a la paridad artificial de 1 peso, 1 dólar estadounidense. Las economías por naturaleza son dinámicas, entonces para sostener el 1 a 1 de la economía argentina se tendría que haber obedecido al comportamiento de la economía EEUU: igual o menor inflación y mayor o igual tasa de crecimiento de la productividad. Por supuesto, nada de esto ocurrió, con lo cual nuestro tipo de cambio quedó con el tiempo desactualizado deliberadamente, o &quot;atrasado&quot;.&lt;/p&gt;
&lt;h2 id=&quot;c5-una-decisión-difícil-la-pesificación-️&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c5-una-decisi%C3%B3n-dif%C3%ADcil-la-pesificaci%C3%B3n-%EF%B8%8F&quot; aria-label=&quot;c5 una decisión difícil la pesificación ️ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C5: Una decisión difícil: la pesificación ⚖️&lt;/h2&gt;
&lt;p&gt;Probablemente es este el capítulo más debatible de todos, digno de horas de café (torrado no, por favor). Como comentaba más arriba, nuestra economía estaba lejísimo de siquiera parecerse a la de EEUU. Además de que el tipo de cambio no reflejaba esto, el común de la gente no lograba enlazar la crisis que se vivía con la falsa premisa del 1 a 1.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Hago una pausa acá sobre la comprensión sobre la economía de &lt;em&gt;&apos;la gente&apos;&lt;/em&gt;. Estudié la mayor parte de mi vida y me gradué de ingeniero en informática, y aún así me llevó una enorme cantidad de horas en internet comprender conceptos básicos de finanzas y economía, incluso al leer este libro. No quiero imaginar lo que debe ser para un trabajador corriente frenar y pensar de qué se habla cuando se escucha decir &quot;tipo de cambio&quot;, &quot;tasa de interés&quot;, &quot;LELIQ&quot;, etc, si es que siquiera tiene el tiempo y la energía para hacerlo. El Estado no debería regalar computadores, subsidiar internet, ni promocionar cursos de programación, sino antes garantizar que su población entienda los conceptos básicos de economía y finanzas. Ahí si seremos más poderosos y menos proclives en el futuro a caer en apuestas de teóricos que juegan con nuestros impuestos y, por transitividad, con nuestra vida.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;la-pesificación-de-roosevelt&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#la-pesificaci%C3%B3n-de-roosevelt&quot; aria-label=&quot;la pesificación de roosevelt permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;La &apos;pesificación&apos; de Roosevelt&lt;/h3&gt;
&lt;p&gt;En la década de 1930, el entonces presidente de EEUU Franklin D. Roosevelt, hizo salir al país de un tipo de cambio fijo, el patrón oro, hacia una moneda nacional, el dólar. De esto se inspiró Remes Lenicov, que remarca que FDR fue aún más duro que su pesificación: el que no depositaba su oro en la Reserva Federal iba preso. Después devaluó 70% y salió del patrón oro. La onza de oro troy pasó de 20,6 USD a 35 USD.&lt;/p&gt;
&lt;p&gt;Como era de esperar, llovieron juicios por doquier. Pero SCOTUS le dió la razón al gobierno: nadie podía enriquecerse sin hacer nada. Entonces, si yo tenía 1000 USD antes de la salida del patrón oro, no podía tener 1700 USD al otro día. En el mismo sentido, nadie podía deber más de lo que debía por la misma cosa (los bancos había enjuiciado a los deudores).&lt;/p&gt;
&lt;h3 id=&quot;la-reingeniería&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#la-reingenier%C3%ADa&quot; aria-label=&quot;la reingeniería permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;La reingeniería&lt;/h3&gt;
&lt;p&gt;Para salir había que necesariamente afectar a todo lo denominado en dólares: depósitos, contratos, préstamos. JLV explica que esto fue de lo más difícil de la gestión, no sólo a nivel técnico sino más bien a nivel social. Claro, pesificar las obligaciones de la economía destrabó el proceso de producción, pero del otro lado del mostrador pulverizó a quienes pretendían atesorar sus ahorros en el &lt;em&gt;greenback&lt;/em&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Casualmente, mientras escribo esto en 2023, se debate cómo dolarizar la economía argentina. Haber leído este libro y preguntarme lo mismo que JRL con el panorama actual no hace más que dejarme claro que es algo completamente inviable y caótico.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;!-- TOC ignore:true --&gt;
&lt;h3 id=&quot;qué-hubiera-pasado-si-se-hubieran-mantenido-los-depósitos-y-préstamos-en-dólares-o-se-hubieran-transformado-en-pesos-al-tipo-de-cambio-libre&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#qu%C3%A9-hubiera-pasado-si-se-hubieran-mantenido-los-dep%C3%B3sitos-y-pr%C3%A9stamos-en-d%C3%B3lares-o-se-hubieran-transformado-en-pesos-al-tipo-de-cambio-libre&quot; aria-label=&quot;qué hubiera pasado si se hubieran mantenido los depósitos y préstamos en dólares o se hubieran transformado en pesos al tipo de cambio libre permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;¿Qué hubiera pasado si se hubieran mantenido los depósitos y préstamos en dólares, o se hubieran transformado en pesos al tipo de cambio libre?&lt;/h3&gt;
&lt;p&gt;Una pregunta contrafáctica que se hace JRL y que responde claramente. En ese escenario, dado que la inflación de todo ese período fue menor que la devaluación, los depositantes hubieran tenido una gran ganancia de capital en pesos, mientas que los deudores se hubieran insolventado masivamente, los bancos se habrían quedado con propiedas como colateral de esas deudas, transfiriendo así la riqueza de los endeudados a los acreedores.&lt;/p&gt;
&lt;p&gt;El valor de las cuotas de los créditos se hubieran triplicado, haciendo imposible a los deudores pagar sus deudas, y por consecuencia, haciendo imposible que los bancos devuelvan los depósitos que tomaron para prestarle a los primeros, en la moneda que sea. Al quebrar los bancos, hubieran quebrado los ahorristas, las familias no habrían pagado nada de sus hipotecas y las empresas hubieran quebrado masivamente al no poder pagar frente a tal incremento de su endeudamiento.&lt;/p&gt;
&lt;p&gt;En diciembre de 2001, 7.5 millones de personas y empresas debían USD 38.430 millones. Coincido con JRL en que dejar esto en manos del mercado a resolverse &apos;mano a mano&apos; era sencillamente inviable. Sin embargo, sí hubo arreglos ad hoc para contratos entre privados, que habían sufrido su ruptura por la crisis de la convertabilidad.&lt;/p&gt;
&lt;p&gt;Es así que se decidió por pesificar todo, y ajustar por CER para evitar licuaciones de créditos y depósitos.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;CER: en el contexto de la economía argentina, el &quot;Coeficiente de Estabilización de Referencia&quot; es un factor utilizado para ajustar ciertos instrumentos financieros y contratos en Argentina para tener en cuenta la inflación.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;JRL explica que esto era lo más equitativo entre ahorristas y deudores, además de comenzar a producir y de realentar los depósitos en un contexto de crisis. Romper el 1 a 1 devaluación sin pesificación no hubiera sido coherente, al igual que no tener moneda propia (según quién lo diga, ¿no cierto, &lt;em&gt;León&lt;/em&gt;?).&lt;/p&gt;
&lt;p&gt;Si a diciembre de 2001, una persona debía 100 dólares/pesos, en febrero de 2002, ¿cuánto debía? ¿50, 150, 300? No, debía $100 más un índice de precios más una tasa de interés, es decir, unos $110 pesos. JRL así explica que no hubo licuación ni se benefició a nadie. Si se hubiera mantenido el dólar, ¡la deuda se triplicaba! Con eso quebraban todas las empresas (su patrimonio neto pasa a ser negativo). ¿Cómo se sale de una crisis con todas las empresas quebradas? Lo que se hizo fue evitar el aumento del valor real de las deudas.&lt;/p&gt;
&lt;p&gt;A fines de 2004 el dólar estaba en $2,97, y un crédito actualizado por CER más tasa de interés exigía multiplicar po 1,98 el valor original. Evidentemente, no hubo &lt;em&gt;licuación&lt;/em&gt; ni imposibilidad de pago.&lt;/p&gt;
&lt;h3 id=&quot;la-asimetría&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#la-asimetr%C3%ADa&quot; aria-label=&quot;la asimetría permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;La asimetría&lt;/h3&gt;
&lt;p&gt;Para los ahorristas, se pesificó a $1,40 por dólar por la particular razón de la promesa de Duhalde de pagarles en dólares a los depositantes. Entonces, JRL y su equipo se atuvo a la cotización del momento de la promesa. Así es que medida en pesos, los ahorristas no perdieron poder adquisitivo, pero en dólares, claramente sí. Incluso, los deudores debían menos dólares.&lt;/p&gt;
&lt;p&gt;Es obvio que en la diferencia entre 1,40 para ahorristas y 1 para endeudados hay una pérdida que alguien paga. Por esa diferencia, se le dieron en el 2002 a los bancos bonos que costaron USD 11.000 millones. A cambio, se pesificaron las deudas internas en dólares de los bancos y de las AFJP a 1,40 más CER, de tal manera que el total bajó de USD 53.450 millones a USD 22.050. Un deal.&lt;/p&gt;
&lt;h3 id=&quot;hospital-de-empresas&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#hospital-de-empresas&quot; aria-label=&quot;hospital de empresas permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Hospital de empresas&lt;/h3&gt;
&lt;p&gt;El FMI, ese ente que vive en nuestra memoria colectiva permanentemente por nuesta nula capacidad de control de gasto, no fue siempre el mismo. De hecho, en esa época, tuvo un comportamiento que años después informes propios internos de la agencia fuertemente criticaron. A Remes Lenicov le propusieron un &lt;em&gt;hospital de empresas&lt;/em&gt;, que consistía en crear un fondo estatal para absorber la deuda de las empresas, capitalizar los bancos y garantizar los depósitos. Este experimento ya había sido implementado en México, en la crisis del Tequila, con un desastre como resultado para el Estado (USD 65.000 millones), y con una fiesta de sobornos por todas partes. Imagínese lo que hubiera sido este hospital en nuestra tierra, donde hacemos un acto para inaugurar una canilla.&lt;/p&gt;
&lt;h3 id=&quot;other-interests&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#other-interests&quot; aria-label=&quot;other interests permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Other interests&lt;/h3&gt;
&lt;p&gt;También hubo presiones de otros bancos para no pesificar. En particular, los bancos de EEUU y EU, que eran mayoristas y no estaban expuestos a depositantes minoristas, preferían seguir todo como está, sabiendo que los otros bancos en la cuerda floja quebrarían, dándoles automáticamente mayor mercado.&lt;/p&gt;
&lt;p&gt;Otras propuestas que llegaban: privatizar el Banco Nación y el Banco Provincia, y echar 500000 empleados públicos. Para la primera, JRL alude al hecho de que son bancos que &quot;nacieron con el país&quot;, y para la segunda, que con los cacerolazos que había, era imposible.&lt;/p&gt;
&lt;p&gt;Es fácil con el diario del lunes (y con la victoria de Milei con el 55%) criticar a JRL por ambos puntos. Pero lo hago igual, ya que quedan en evidencia las prioridades de su equipo en esos momentos determinantes: proteger a dos bancos porque &quot;nacieron con el país&quot; es un argumento nostálgico y débil. Hubiera esperado algo en torno a &quot;qué buenos balances tienen&quot; o &quot;es ilegal por X razón&quot;. En cuanto a los empleados públicos, es aún menos convincente. En momentos donde los que menos tienen peor sufrían, se decidió proteger a empleados del Estado que cobraban de todos. JRL habla sobre &quot;discutirla y esperar el momento&quot;, que no es coherente con sus medidas (acordes) de shock.&lt;/p&gt;
&lt;p&gt;A título personal, me pregunto, ¿cuándo llega ese momento? ¿Cómo nos damos cuenta que estamos en ese momento de discutir tal o cual tema? En 2023, llegó sin más de la mano de la &apos;motosierra&apos; de Milei, quien repartío en un primer momento el ajuste entre la población y &apos;la casta&apos;, cuando se creía que sería sólo sobre la última. Mejor eso que nada, mejor &lt;em&gt;shock&lt;/em&gt; que &quot;discutir y esperar&quot; mientras todos los argentinos son parte de la distribución de las pérdidas, salvo los protegidos que presten servicios en el Estado.&lt;/p&gt;
&lt;h3 id=&quot;deudas-de-empresas-en-el-extranjero&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#deudas-de-empresas-en-el-extranjero&quot; aria-label=&quot;deudas de empresas en el extranjero permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Deudas de empresas en el extranjero&lt;/h3&gt;
&lt;p&gt;Por si faltaba poco, se sumó la presión de las empresas que tenían deudas en el exterior por casi USD 78.000 millones para que les dieran un seguro de cambio.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Seguro de cambio&lt;/em&gt;: también conocido como &quot;forward contract&quot; o &quot;contrato a plazo de divisas&quot;, es un acuerdo financiero entre dos partes para intercambiar una cantidad específica de una moneda por otra en una fecha futura predeterminada y a un precio acordado. Este tipo de instrumento se utiliza comúnmente para gestionar el riesgo de fluctuaciones en los tipos de cambio.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Sucedía que durante los años noventa, muchas de las empresas grandes, extranjeras y nacionales, tomaron deuda en el exterior a tasas de interés mucho más bajas que en el mercado local. Esto fue un gran riesgo pero a su vez una gran ventaja frente a las empresas locales, en su mayoría pymes, que tomaban al 25% anual. Cuando &apos;llegó la cuenta&apos;, fueron de rodillas al Estado a pedirle un salvataje. Por la naturaleza propia del riesgo asumido, y por el costo fiscal imposible de afrontar, fue rechazado. &quot;Te vamos a &apos;pegar&apos; igual, pero te entendemos.&quot; le confesaban los empresarios a JRL.&lt;/p&gt;
&lt;h3 id=&quot;sistema-financiero&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sistema-financiero&quot; aria-label=&quot;sistema financiero permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sistema financiero&lt;/h3&gt;
&lt;p&gt;Pondría a la protección del sistema financiero en el podio de las medidas más claves (sin dejar de ser polémica) de aquellos momentos. Con créditos incobrables y ahorristas licuados, no hay sistema que resista, y por consecuencia, país. Todo esfuerzo compartido (pesificación, devaluación) fue útil para que Argentina se normalizara después. Recomiendo fuertemente el documental &lt;a href=&quot;https://www.imdb.com/title/tt9419838/&quot;&gt;&lt;em&gt;PANIC!&lt;/em&gt;&lt;/a&gt; sobre cómo el rescate (siempre criticable) de los bancos de Wall Street durante la crisis de 2008 evitó un descalabro muchísimo mayor. &lt;a href=&quot;https://www.imdb.com/title/tt1645089/&quot;&gt;Inside Job&lt;/a&gt; es la otra campana.&lt;/p&gt;
&lt;p&gt;Con el tiempo, los ahorristas recuperaron en promedio 85% de los depósitos en dólares, al mismo tiempo que medido en pesos mejoró su poder adquisitivo. JRL señala que no hubo confiscación de depósitos, pues se ofrecieron distintas posibilidades de retiros, compras de bienes registrables, bonos en dólares, entre otras medidas, que confieso suenan más a eufemismos para ese -15% que sufrieron los ahorristas, pero que hicieron al esfuerzo compartido para salir de la convertibilidad.&lt;/p&gt;
&lt;h2 id=&quot;c6-el-desarme-del-corralito-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c6-el-desarme-del-corralito-&quot; aria-label=&quot;c6 el desarme del corralito  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C6: El desarme del &apos;corralito&apos; 🚪&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;La dirigencia política estaba tan asustada con el &quot;que se vayan todos&quot; que muchos legisladores entraban al Congreso vestidos de &lt;em&gt;sport&lt;/em&gt; para pasar desapercibidos, dentro se vestían de traje para las sesiones, y al salir nuevamente en &lt;em&gt;sport&lt;/em&gt; y así fugar rápidamente a bordo de un taxi.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;El corralito se diseñó para detener la acelerada fuga de capitales y evitar el colapso del sistema financiero. Hubo una corrida contra el peso, reduciendo las reservas del BCRA, y contra los depósitos, deteriorando a los bancos. Una combinación explosiva, tanto como la &lt;em&gt;transformación automática&lt;/em&gt; de salarios en pesos a dólares, creando dólares sin ningún respaldo.&lt;/p&gt;
&lt;p&gt;El 3 de diciembre de 2001, el entonces Ministro de Economía Cavallo lo estableció. Por 60 días se congelaron los depósitos, se limitaron los retiros y se incentivó la dolarización de depósitos y deudas. Para eludir controles, la gente abría cuentas a nombre de parientes o amigos. En el interín, fracasó un caje de deuda interna (fase 1 del corralito, a una tasa extrafalaria de 16%), se cumplieron los 60 días, llegó febrero de 2002 con Duhalde y Remes Lenicov y así nunca llegó a finalizar el corralito armoniosamente.&lt;/p&gt;
&lt;p&gt;Muy por el contrario, desmultiplicar los dólares no fue sencillo. Por definición, los depósitos viven en el cortísimo plazo, mientras que el período de recuperación de los préstamos es a plazo mucho mayores. Esta diferencia temporal es insalvable en una corrida (pregúntenle sino a &lt;a href=&quot;https://en.wikipedia.org/wiki/Collapse_of_Silicon_Valley_Bank&quot;&gt;Silicon Valley Bank&lt;/a&gt;). ¿Cómo se devolvían los dólares entonces? ¿Cómo se reestablecía la cadena de pagos? No estaban en el BCRA, ni tampoco los pesos. Emitir habría generado mayor inflación.&lt;/p&gt;
&lt;p&gt;Mientras los deudores pedía pesificación 1 a 1, los ahorristas demandaban sus depósitos de inmediato.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;El 3 de diciembre de 2001 sólo quedaban 10 (sí, diez) depositantes con más de USD 500.000. El resto se había avidado antes e ido.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Se procedió a la reprogramación de los depósitos a plazo fijo, a 12 y a 24 meses, y a la liberación progresiva de las cuentas a la vista (acceso inmediato). A fin de enero ya se habían liberado la mayoría de los depósitos en pesos, y la mitad en dólares. Con &quot;Certificados Representativos de Depósitos Reprogramados&quot; se podían comprar casas, máquinas, vehículos. Más adentrado 2002, se ofrecieron bonos a 10 años en USD, que casi todos los ahorristas aceptaron y cobraron al final de su madurez sin inconvenientes, pero, claro, con una fe ciega en el Estado argentino por 10 veranos seguidos. Qué agallas, a ojos de hoy, después de tantos defaults y reestructuraciones.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/a6c918dacef938fc79da0faeb634ce2f/5fada/reservas.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 74.84662576687117%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAABYlAAAWJQFJUiTwAAAB2UlEQVR42pVT16piUQz1W8WCimAF9dknffcr/ANfREQQ7A1EFMXeey9rZgW2nDNeB24ghGTvrHTDeDxGt9tFp9NBr9dDq9VCtVpFuVzGYDBAv99Hs9kUnbLdboskTyYT0ev1Omq1GqbTKQz3+x2Xy0XH1+sVp9MJx+NReL/fY7fbvSVt5/NZ/lGqf7fbDQb8QI/HA4vFQrKbzWYSmdksl0uMRiN5+0YGLQgj3K63j0+v1+vNWuJ/Zqm1G5SyWq3QaDQwHA4/HH8KQGLW7CXbo+zvDNnLzWaD39J2uxVfXcnaiIfD4VeA7OtXwGQyiUQi8d+Sn8+nBOW01+u1DIn91wHyEymTycBkMsleqUFpwbkiaurMjDpL5nB+BOTyWiwWRKNRceAESZR0JJhy5iByuZwcwsfaqCxSqRQ8Hg+sVivi8bgMiY7cO5apgLPZLCKRCIxGI9LptG7yugwLhQIcDge8Xi/MZrM48bTm87mcZiwWg8/ng81mg9PphN1ulzZ9BSyVSgIWDAaF6RwOhxEKheB2u+FyueD3+xEIBMRGndl+ACqFfatUKnLo7GexWEQ+nxcuFkt/7XWxK6adA9Jdyr9rwZ1in7gS3EuWyyuinf1kUDJt2nVRgH8AImtW8oG1nywAAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/a6c918dacef938fc79da0faeb634ce2f/0cbef/reservas.avif 163w,
/static/a6c918dacef938fc79da0faeb634ce2f/bffb7/reservas.avif 325w,
/static/a6c918dacef938fc79da0faeb634ce2f/69c29/reservas.avif 650w,
/static/a6c918dacef938fc79da0faeb634ce2f/6d24a/reservas.avif 975w,
/static/a6c918dacef938fc79da0faeb634ce2f/a2baf/reservas.avif 1300w,
/static/a6c918dacef938fc79da0faeb634ce2f/229dd/reservas.avif 1706w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/a6c918dacef938fc79da0faeb634ce2f/94563/reservas.webp 163w,
/static/a6c918dacef938fc79da0faeb634ce2f/647a8/reservas.webp 325w,
/static/a6c918dacef938fc79da0faeb634ce2f/c1dc5/reservas.webp 650w,
/static/a6c918dacef938fc79da0faeb634ce2f/1e975/reservas.webp 975w,
/static/a6c918dacef938fc79da0faeb634ce2f/063bf/reservas.webp 1300w,
/static/a6c918dacef938fc79da0faeb634ce2f/25962/reservas.webp 1706w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/a6c918dacef938fc79da0faeb634ce2f/222b7/reservas.png 163w,
/static/a6c918dacef938fc79da0faeb634ce2f/ff46a/reservas.png 325w,
/static/a6c918dacef938fc79da0faeb634ce2f/a6d36/reservas.png 650w,
/static/a6c918dacef938fc79da0faeb634ce2f/e548f/reservas.png 975w,
/static/a6c918dacef938fc79da0faeb634ce2f/3c492/reservas.png 1300w,
/static/a6c918dacef938fc79da0faeb634ce2f/5fada/reservas.png 1706w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/a6c918dacef938fc79da0faeb634ce2f/a6d36/reservas.png&quot;
            alt=&quot;Se excluye el desembolso del FMI de septiembre de 2001 en las reservas. El aumento en los depósitos de enero de 2002 se debe a la pesificación.&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Se excluye el desembolso del FMI de septiembre de 2001 en las reservas. El aumento en los depósitos de enero de 2002 se debe a la pesificación.&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;h3 id=&quot;la-corte-suprema-pido&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#la-corte-suprema-pido&quot; aria-label=&quot;la corte suprema pido permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;La Corte Suprema: &quot;pido&quot;&lt;/h3&gt;
&lt;p&gt;Mientras avanzaba la salida del corralito paulatinamente, el máximo tribunal sentenció sin apreciar la delicada situación económica que el corralito debía abrirse. No era esta vez un lobbysta cualquiera, sino la primera autoridad del Poder Judicial. Pero la Corte fue más allá cuando aceptó que jueces otorgaran cautelares para retirar la totalidad de los fondos sin permitir la defensa de los bancos en cuestión. Varios jueces terminaron enjuiciados.&lt;/p&gt;
&lt;p&gt;Esto produjo filtraciones en los depósitos, distorsionando innecesariamente la cotización del dólar entorpeciendo el acceso al crédito de familias y empresas.&lt;/p&gt;
&lt;p&gt;Sin los cambios realizados en el corralito y con la mecánica de las cauterales, solo habrían cobrado los primeros en llegar, y no hubiera quedado ni un peso para el resto.&lt;/p&gt;
&lt;h3 id=&quot;bancos-offshore&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#bancos-offshore&quot; aria-label=&quot;bancos offshore permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Bancos &lt;em&gt;offshore&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;Algunos proponían, además de dolarizar, que la banca argentina sea &lt;em&gt;offshore&lt;/em&gt;, que dependiera de otro país y que mantuviera los dólares. En este punto JRL argumenta lo mismo que Sergio Massa en el debate 2023: no hay país que no maneje su sistema financiero, como tampoco hay quienes no tengan su propia moneda, salvo algunos muy pequeños. No me convence del todo como justificativo, pero si el resto del mundo tuvo crisis como las nuestras y salió a flote con moneda propia, ¿por qué deberían ir con esta estrategia &lt;em&gt;offshore&lt;/em&gt;? Pienso en Alemania post-guerra con hiperinflación, Brasil en los 90s, Japón últimamente calibrando sus cuentas con el yen, etc. Todas situaciones muy complejas pero que no requirieron saltar a una dolarización.&lt;/p&gt;
&lt;h3 id=&quot;coyuntura&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#coyuntura&quot; aria-label=&quot;coyuntura permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Coyuntura&lt;/h3&gt;
&lt;p&gt;JRL cierra el capítulo diciendo que cuando hay una crisis muy profunda de conyuntura, como la de 2001, hasta que no se normalice la situación no se pueden tomar medidas estructurales, detallando que el acuerdo entre Duhalde y Alfonsín fue para salir de la convertibilidad y crecer sin inflación, nada más (ni nada menos).&lt;/p&gt;
&lt;p&gt;Las primeras semanas del gobierno del Presidente Javier Milei y del Ministro Luis Caputo a fines de 2023 fueron un reto a esta idea. En el momento que escribo estas líneas, queda por verse si el súper DNU que se dictaminó para liberar la economía es aprobado y hecho efectivo, y si sus medidas alcanzan para normalizar la inflación y pobreza rampantes. Sólo el destino lo sabrá.&lt;/p&gt;
&lt;h2 id=&quot;c7-la-crisis-de-los-contratos-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c7-la-crisis-de-los-contratos-&quot; aria-label=&quot;c7 la crisis de los contratos  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C7: La crisis de los contratos 📃&lt;/h2&gt;
&lt;p&gt;Desde fines del 2000 se fue extendiendo una profunda crisis de contratos entre particulares, sumados a las obligaciones con el Estado que se dejaron de pagar (los impuestos). El Estado fue dejando de brindar prestaciones y de pagar sus deudas. Los bancos no cobraban créditos ni tampoco devolvían depósitos.￼￼&lt;/p&gt;
&lt;p&gt;Todo ello fue consecuencia de la generalizada iliquidez, la quiebra del Estado, la ruptura de la cadena de pagos y la aparición de las cuasimonedas.￼ Una macroeconomía absolutamente detonada por los incumplimientos.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;El economista sueco Axel Leijonhufvud dice: “Cuando los reclamos son masivos […] y los reclamos exceden lo que es posible pagar, tienen que tomarse decisiones sobre la distribución de pérdidas.” Sin esta distribución la economía no vuelve a funcionar. Lo que es materialmente imposible no es exigible.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Desde aquí nació en el equipo de JRL la &lt;strong&gt;Ley de Emergencia&lt;/strong&gt;, por la cual nadie debía beneficiarse de la crisis, y todos debían soportar los costos equitativamente. El haber sincerado la relación peso-dólar permitió restablecer, muy progresivamente, la cadena de pagos y la recaudación fiscal.&lt;/p&gt;
&lt;p&gt;Años después, la Corte Suprema no sólo convalidó la constitucionalidad de la ley y sus medidas, sino además aclaró que no haberlas hecho hubiera sido &lt;em&gt;peor&lt;/em&gt;. El derecho es siempre una pretensión de encauzar las conductas sociales en cierta dirección. Cuando esa dirección se desvía, el derecho debe modificarse. No se puede insistir en un &lt;em&gt;deber ser&lt;/em&gt; contrario a la dirección de la realidad.&lt;/p&gt;
&lt;p&gt;Esto cobra más relevancia que nunca a finales de 2023, cuando el DNU de demás de 600 puntos deba ser tratado por el Congreso. Eventualmente, la Corte Suprema puede llegar a expedirse sobre el decreto. Hace más de 20 años apoyó el paquete de medidas para salir de la crisis. ¿Y esta vez?&lt;/p&gt;
&lt;h2 id=&quot;c8-desdolarización-y-desindexación-de-las-tarifas-de-los-servicios-públicos-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c8-desdolarizaci%C3%B3n-y-desindexaci%C3%B3n-de-las-tarifas-de-los-servicios-p%C3%BAblicos-&quot; aria-label=&quot;c8 desdolarización y desindexación de las tarifas de los servicios públicos  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C8: Desdolarización y desindexación de las tarifas de los servicios públicos 🧾&lt;/h2&gt;
&lt;p&gt;Hubo un momento donde los llamados hacia el Ministerio de Economía de JRL llegaban del otro lado del Atlántico. Resulta que muchas de las empresas que habían entrado durante las privatizaciones de los 90s era de origen español. Felipe González, ex presidente español, hablaba con los radicales. El rey Juan Carlos lo llamaba a Duhalde. Rodrigo Ratto, vicepresidente segundo de España, hablaba con JRL.&lt;/p&gt;
&lt;p&gt;Su intención en un primer momento, durante la efímera presidencia de Rodriguez Saá, era postergar todos los cambios al próximo año, de tal manera que no afectasen sus balances para el año corriente. Luego pasaron a presionar para continuar con tarifas atadas al dólar, para continuar con la convertibilidad, y hasta para dolarizar directamente la economía. Curiosas exigencias, puesto que estas empresas tuvieron en los años noventa más del doble de rentabilidad que el resto de las grandes empresas. Además, en el peor período, 1999-2001, mientras el resto sufrió pérdidas, estas continuaban con altas ganancias, todo debido a la absurda indexación de las tarifas a la inflación de EEUU.&lt;/p&gt;
&lt;p&gt;JRL y su equipo permanecieron convencidos que las tarifas iban a ser pesificadas y congeladas transitoriamente. De hecho, de no hacerlo, las tarifas se hubieran triplicado, y en esa realidad no quedaría ni un solo usuario para pagar su tarifa. En otras palabras, la pesificación terminó salvando a las compañías en cuestión. Más adelante, se fueron ajustando las tarifas según el costo de la devaluación. Imposible que todos queden conformes, pero la situación se pudo superar. No por tanto.&lt;/p&gt;
&lt;h3 id=&quot;hablá-con-julio&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#habl%C3%A1-con-julio&quot; aria-label=&quot;hablá con julio permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Hablá con Julio&lt;/h3&gt;
&lt;p&gt;Un bendito día de 2003, el tema de las tarifas quedó a cargo de Julio De Vido, en la presidencia de Nestor Kirchner. Con todo el intelecto que los caracterizaba, decidieron subsidiar la oferta, es decir, a las empresas. Fue una decisión pésima, no sólo por el atraso que produjo que subsistió décadas, sino porque está estudiado que los subsidios deben siempre ir a la demanda. Al subsidiar a la oferta, todos lo usuarios, ricos y pobres, pagan menos por sus tarifas, cuando lo correcto sería que sólo aquellos que verdaderamente lo necesiten lo reciban. Demás está mencionar las sospechas de corrupción entorno a estas maniobras a favor de la oferta.&lt;/p&gt;
&lt;h3 id=&quot;decile-a-jorge-que-afloje&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#decile-a-jorge-que-afloje&quot; aria-label=&quot;decile a jorge que afloje permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;“Decile a Jorge que afloje”&lt;/h3&gt;
&lt;p&gt;Hay que pensar que había en juego miles de millones de dólares. Para abril de 2023, los subsidios eran del 4% del PBI, lo que significa unos u$s 20.000 millones. No es broma. Por ese dinero se puede llegar a hacer cualquier cosa. Por eso, no extrañó el despliegue que se hizo por parte de las empresas para tratar de doblarles el brazo.&lt;/p&gt;
&lt;p&gt;Pero también había comentarios de funcionarios del gobierno y legisladores a los que acudían amigos comunes: «Decile a Jorge
que afloje», ese era el mensaje.&lt;/p&gt;
&lt;p&gt;JRL debe ser recordado cuanto menos por esta actitud, por no rendirse ante los que pedían “que afloje”. Interpretaría el “que afloje” más cercano a “que no toque mi parte”.&lt;/p&gt;
&lt;h2 id=&quot;c9-una-de-las-grandes-batallas-equilibrio-fiscal-consolidado-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c9-una-de-las-grandes-batallas-equilibrio-fiscal-consolidado-&quot; aria-label=&quot;c9 una de las grandes batallas equilibrio fiscal consolidado  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C9: Una de las grandes batallas: equilibrio fiscal consolidado 🤸&lt;/h2&gt;
&lt;p&gt;Comenzó el año 2002 con un déficit financiero del 5,7% del PBI. Era insostenible a nivel Nación y a nivel provincial. ¿Financiamiento internacional? Bien, gracias. Esta situación acarreaba una disminución de la recaudación del 8,9% para el año 2001. El famoso Diciembre de ese año se tocó un piso: una baja del 28%.&lt;/p&gt;
&lt;p&gt;Diez provincias, sin fondos suficientes, emitieron cuasimonedas al notar que el BCRA no podía emitir más del &lt;em&gt;stock&lt;/em&gt; de reservas. Las transferencias de Nación que les correspondían a las provincias fueron suplantadas por un bonito mecanismo financiero: las &lt;em&gt;LECOP&lt;/em&gt;, bonos que circulaban como medio de pago, pero no se podían usar para depósitos y créditos.&lt;/p&gt;
&lt;h3 id=&quot;quiero-default-de-qué-sabor&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#quiero-default-de-qu%C3%A9-sabor&quot; aria-label=&quot;quiero default de qué sabor permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Quiero default. ¿De qué sabor?&lt;/h3&gt;
&lt;p&gt;El mundo funciona aún con déficits fiscales. Muchas veces, estos son mayores al PBI. Los mercados internacionales los financian, primordialmente porque confían en la capacidad de repago de esas naciones (EEUU, Japón, EU). No fue el caso por estas latitudes. Teníamos default &lt;em&gt;implícito&lt;/em&gt; generado por el canje de títulos públicos de mayo de 2001, por el canje forzoso de la deuda interna en octubre o porque el FMI dejó de hacer desembolsos en noviembre de ese mismo año. También teníamos default &lt;em&gt;explícito&lt;/em&gt; declarado a fines de 2001 por Rodriguez Saá.&lt;/p&gt;
&lt;p&gt;Fue imperioso entonces diferenciar la deuda interna de la externa para reconstruir el sistema de pagos. Con el arreglo y reducción en dólares de la deuda interna (USD $22.050 millones), se compensó el costo de la asimetría de la pesificación entre depósitos y créditos. Me pregunto, entonces, a cuánto se hubiera pesificado de no haber ajustado esta deuda: ¿1,80? ¿2,00?&lt;/p&gt;
&lt;p&gt;Así fue que en marzo se pesificaron y pospusieron por tres años (!) todas las obligaciones en dólares que estaban bajo legislación argentina utilizando el mismo criterio de los depósitos: $1,40 más CER más tasas de interés. Claro, si hubiera sido bajo legislación extranjera (Nueva York, por ejemplo) el juicio más pequeño era del tamaño del Taj Mahal.&lt;/p&gt;
&lt;p&gt;Algo no menor es el impacto de la devaluación. Sumado al impacto positivo en las exportaciones, se previó un aumento en los ingresos fiscales, producto del aumento en el nivel de precios post-devaluación. Esto también contribuyó a la reducción del déficit.&lt;/p&gt;
&lt;p&gt;Bajar el déficit de 5% a 3% es una tarea algo rápida, mientras que bajarlo de 3% a 0% es una obra monumental. Con todas estas medidas (Pacto Nación-Provincias) y reprogramaciones (no gastar más de lo que se colecta, es decir, erogar menos de los que ingresa) finalizó 2002 con un superávit primario de 0,7% y un déficit financiero de menos de la mitad del recibido: 1,5%. Las provincias hicieron un esfuerzo mayor al pactado, de manera que sólo 2 no llegaron a la metas acordadas. &lt;em&gt;Underpromise, overdeliver&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id=&quot;la-dékada-ganada&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#la-d%C3%A9kada-ganada&quot; aria-label=&quot;la dékada ganada permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;La dékada ganada&lt;/h3&gt;
&lt;p&gt;El sector público argentino inició así un período de ordenamiento y equilibrio fiscal como no se había registrado en las últimas décadas. Fue en esta etapa que se erigieron los superávits gemelos de los que tanto se vanaglorió después Néstor Kirchner, que en definitiva había heredado de la gestión de JRL. Es más: JRL y equipo tuvieron alto superávit comercial cuando todavía el precio de la soja no se había disparado, porque eso ocurrió recién a partir de 2003.&lt;/p&gt;
&lt;p&gt;Había que ser austeros y no prometer lo que no se podía cumplir.&lt;/p&gt;
&lt;h2 id=&quot;c10-anclaje-monetario-y-política-financiera-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c10-anclaje-monetario-y-pol%C3%ADtica-financiera-&quot; aria-label=&quot;c10 anclaje monetario y política financiera  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C10: Anclaje monetario y política financiera 🏦&lt;/h2&gt;
&lt;p&gt;La crisis del sistema financiero era de una gravedad sin precedentes. Llegando al 2002, los créditos al sector privado, en su mayoría en dólares, habían caído 20%. Las tasas reales de interés eran del 25% anual. La incobrabilidad llegaba al 25%, y como sucede siempre en estos casos, tanto a principio de siglo como en 2023, los bancos preferían prestarle al sector público.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Durante la gran crisis de los años treinta, desapareció el 30% de los bancos de EEUU.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Para estabilizar los precios y ayudar en la recuperación económica, no bastaba con la política fiscal del capítulo anterior. La política monetaria y financiera fue igualmente importante. Los objetivos eran:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Impedir que la explosión de la convertibilidad terminara en hiperinflación&lt;/li&gt;
&lt;li&gt;Circunscribir el &lt;em&gt;overshooting&lt;/em&gt; (o sobrereacción) cambiario&lt;/li&gt;
&lt;li&gt;Evitar la caída de bancos&lt;/li&gt;
&lt;li&gt;Ayudar a definir una tasa de interés de referencia&lt;/li&gt;
&lt;li&gt;Plantear pasos a seguir para recuperar el sistema financiero&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;La idea era simple: controlar la cantidad de pesos que ingresaban al mercado para evitar que fueran a la compra de dólares con un equilibrio tal que esa maniobra no entorpeciera la reactivación. Es así que se les dieron redescuentos a bancos para otorgar créditos &lt;em&gt;baratos&lt;/em&gt; y así expandir la demanda interna. Algunos decían que el plan no tenía ancla monetaria, mientras que otros decían que el ancla era ortodoxa y recesiva. Otros sostenía que no había que dar redescuentos, pues el mercado acomodaría todo.&lt;/p&gt;
&lt;p&gt;En situaciones como estas, hay opiniones e interpretaciones infinitas. Según como uno corte los datos, puede argumentar una mirada o la otra. Esto sucede en la actualidad también, con lecturas opuestas pero simultáneas en cuanto al &lt;em&gt;soft landing&lt;/em&gt; que planea la Reserva Federal de EEUU en su política monetaria post-pandemia. Según a quien leas, se viene el fin del mundo y hay que vender todo, o se debe &lt;em&gt;buy the dip&lt;/em&gt; porque estamos en bull market y &quot;el resto no la ve&quot;.&lt;/p&gt;
&lt;h3 id=&quot;visita-del-diputado-carbonetto&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#visita-del-diputado-carbonetto&quot; aria-label=&quot;visita del diputado carbonetto permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Visita del diputado Carbonetto&lt;/h3&gt;
&lt;p&gt;El diputado del Polo Social Daniel Carbonetto visitó a pedido de Duhalde a JRL, para decirle en el BCRA había dinero suficiente para aumentar salarios y el gasto público sin necesidad de emitir, y que oponerse a esto era entonces algo sin fundamento. Luego de perdile algunas aclaraciones, a JRL le cayó la ficha: Carbonetto confundió &lt;em&gt;emisión&lt;/em&gt; con &lt;em&gt;impresión&lt;/em&gt;. Efectivamente, había dinero en el BCRA, pero eran los encajes mínimos de los bancos (!).&lt;/p&gt;
&lt;h3 id=&quot;nacen-las-lebac&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#nacen-las-lebac&quot; aria-label=&quot;nacen las lebac permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Nacen las LEBAC&lt;/h3&gt;
&lt;p&gt;En la ejecución del programa, se absorbió el desvío de pesos con venta de reservas y, a partir de marzo de 2002, a través de la creación de Letras del BCRA (LEBAC), que se usaron para definir la tasa de interés de referencia. Veinte años después estas letras (y otras con nombres estrambóticos) siguen girando.&lt;/p&gt;
&lt;p&gt;Pese a estas dificultades, hubo una expansión monetaria neta y del circulante muy moderada, y no se terminó convalidando la inflación en el tiempo. No menor fue el hecho de que no se cayó ningún banco y, en los años siguientes, fueron devolviendo todos los redescuentos.&lt;/p&gt;
&lt;h3 id=&quot;cuasimonedas-jefe-me-siento-mal&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cuasimonedas-jefe-me-siento-mal&quot; aria-label=&quot;cuasimonedas jefe me siento mal permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cuasimonedas: &quot;jefe, me siento mal...&quot;&lt;/h3&gt;
&lt;p&gt;Las cuasimonedas, creadas por la Nación y once provincias, funcionaban como medios de pago pero no podían ser usadas para depósitos y créditos. Por esta razón, su impacto sobre la circulación monetaria y sobre el efecto multiplicador era limitado. No se comportan como la emisión de monedas tradicionales, por eso son cuasimonedas.&lt;/p&gt;
&lt;p&gt;JRL recuerda una anécdota de un gobernador que le explicó al Ministro por qué no era necesario pensar cómo eliminar su cuasimoneda: &quot;No te preocupes, Jorge, van a ir desapareciendo solas. Los bonos fueron impresos en papel común, entonces se van a ir desgastando con el uso y van a desaparecer&quot;. Para reir y llorar.&lt;/p&gt;
&lt;h2 id=&quot;c11-la-hora-de-las-retenciones-️&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c11-la-hora-de-las-retenciones-%EF%B8%8F&quot; aria-label=&quot;c11 la hora de las retenciones ️ permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C11: La hora de las retenciones ⏰️&lt;/h2&gt;
&lt;p&gt;Por si faltaban presiones que tironeen, había llegado la hora de las retenciones a las exportaciones. Con la devaluación a $1,40, no había espacio para retenciones. Pero cuando el dólar llegó a $3, se impusieron con una pauta decreciente según el valor agregado de los productos. El objetivo fue múltiple y terminaron conviviendo consideraciones de corto y largo plazo:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;aumentar ingresos fiscales y financiar programas sociales (45% de las retenciones)&lt;/li&gt;
&lt;li&gt;favorecer industrialización del país&lt;/li&gt;
&lt;li&gt;limitar transferencias de ingresos&lt;/li&gt;
&lt;li&gt;atemperar el efecto de la devaluación sobre los precios internos de los alimentos&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A pesar de las retenciones, todas las actividades fueron recuperando la rentabilidad. Con respecto a lo último, los exportadores no se vieron perjudicados porque el tipo de cambio real efectivo multilateral fue del doble del vigente durante la convertibilidad. Esto me sorprendió, porque, como muchos, creía que las retenciones siempre perjudicaban a los exportadores. Pero no es así, porque eso depende más del tipo de cambio efectivo. En la década de los noventa, no había prácticamente retenciones pero como el tipo de cambio estaba atrasado, en 2001 la mayoría de los productores habían quebrado o tenían tierras hipotecadas. Por el contrario, a partir de 2002, con las retenciones, pero con un tipo de cambio competitivo, la producción agropecuaria creció aceleradamente.&lt;/p&gt;
&lt;p&gt;De todas maneras, había que tener cuidado con el nivel de las alícuotas. Un estudió reveló que retenciones más altas habían promovido la subfacturación y la evasión impositiva. Estas discusiones no vinieron sin presiones, inclusive, en el propio gabinete: el entonces secretario de Agricultura terminó renunciando. También algunos gobernadores de provincias agrícolas y petroleras primero comenzando pidiendo que no se pusieran las retenciones, para luego terminar pidiendo que se coparticipara en su recaudación, aunque por precepto constitucional las rentas de aduana son recursos &lt;em&gt;nacionales no coparticipables&lt;/em&gt;. Por su parte y como de costumbre, la mayoría de los legisladores no opinaba públicamente para no quemarse.&lt;/p&gt;
&lt;p&gt;Al tiempo de estas medidas, dirigentes rurales habían propuesto donar el 5% del valor exportado a programas sociales a cambio de 0 retenciones. JRL se plantó: &quot;Nosotros vamos por el 20% y no hay donación que valga, porque esto es una decisión autónoma del Estado.&quot;&lt;/p&gt;
&lt;p&gt;En simultáneo, la Sociedad Rural Argentina se preguntaba, y con razón, por qué no se reducía el gasto público pero sí se les imponían las retenciones. En esto JRL no ahondó. Me parece que faltó un párrafo aparte para argumentar.&lt;/p&gt;
&lt;h2 id=&quot;c12-la-negociación-con-el-fmi-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c12-la-negociaci%C3%B3n-con-el-fmi-&quot; aria-label=&quot;c12 la negociación con el fmi  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C12: La negociación con el FMI 🤝&lt;/h2&gt;
&lt;p&gt;A la hora de negociar con el FMI, había dos problemas: el primero era que no creían lo que se les decía desde la Argentina porque las administraciones anteriores les habían mentido; y el segundo era que le reprochaban al &quot;Mecon&quot; que ya habían implementado un programa económico sin consultarles nada ni darles participación alguna, algo no menor si uno repasa las negociaciones de Macri, Guzmán, Massa y Caputo.&lt;/p&gt;
&lt;p&gt;Fuera como fuere, la negociación con el FMI era clave para posteriormente destrabar arreglos con el Banco Mundial, el Banco Interamericano de Desarrollo y otros organismos internacionales, que entre 2002 y 2003 ascendían a USD 25.699 millones.&lt;/p&gt;
&lt;p&gt;El FMI apuntó naturalmente contra la pesificación asimétrica puesto que hacía menos probable el cumplimiento de los pagos (versus dolarizar o liberar el dólar), y propuso como alternativa el curioso &lt;em&gt;hospital de empresas&lt;/em&gt; del capítulo 5. Terminaron modificando su posición, e incluso, en marzo, cambiaron a los funcionarios que tenían a su cargo el tema de Argentina. Pedían que se avanzara más rápido y hasta querían saber las fechas precisas de aprobación e implementación de las próximas medidas y leyes (sic), aumentando las exigencias antes de iniciar cualquier negociación.&lt;/p&gt;
&lt;p&gt;Después de idas y vueltas, el Fondo pedía por:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;liberación del tipo de cambio y libre movilidad de capitales sin intervención ni controles&lt;/li&gt;
&lt;li&gt;no desdolarizar no congelar las tarifas&lt;/li&gt;
&lt;li&gt;abrir rápidamente el &quot;corralito&quot;&lt;/li&gt;
&lt;li&gt;crear el &quot;hospital de empresas&quot;&lt;/li&gt;
&lt;li&gt;no dar redescuentos a los bancos&lt;/li&gt;
&lt;li&gt;ajuste fiscal con superávit primario durante un año, entre otras&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Para JRL y su equipo, el FMI simplemente quería dolarizar y no ayudar al país. Por esto, no le quedaban dudas de que debían seguir sólos (sin esperar nuevos desembolsos). No hubo acuerdo. La Argentina fue el único caso en el mundo que no sólo recibió fondos frescos, sino que debió pagar al conjunto de los organismos internacionales. A todos los países que habían estado en dificultades unos años antes (México, Indonesia, Turquía) les dieron más de USD 10.000 millones a cada uno.&lt;/p&gt;
&lt;p&gt;El Fondo tuvo en esa época una actitud dogmática, confusa e incluso caótica, algo que fue reconocido en 2004 por la Oficina de Evaluación Independiente del propio organismo, que puso en manifiesto los serios errores y la actitud adversa y negativa del FMI durante la crisis.&lt;/p&gt;
&lt;p&gt;JRL incluye otras propuestas del FMI que me llaman la atención luego de la victoria de La Libertad Avanza en 2023:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;arancelamiento universitario&lt;/li&gt;
&lt;li&gt;despedir a 500.000 empleados públicos&lt;/li&gt;
&lt;li&gt;modificar el régimen de las obras sociales&lt;/li&gt;
&lt;li&gt;reforma impositiva, laboral y de la Coparticipación Federal&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Evidentemente, en 2002 el ajuste no tocaba demasiado el timbre del Estado.&lt;/p&gt;
&lt;h2 id=&quot;c13-el-trabajo-dio-sus-frutos-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c13-el-trabajo-dio-sus-frutos-&quot; aria-label=&quot;c13 el trabajo dio sus frutos  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C13: El trabajo dio sus frutos 🍋&lt;/h2&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/f9c467e199da49a066218fb37b2e7078/799f3/pbi.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 76.07361963190185%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAABYlAAAWJQFJUiTwAAADYUlEQVR42jWTyW+bZRDGncbL52/fPy9xYrepYzteEmMHxw1R7WBII7VK1DZt2Uob1IqKtBLiAEhFQuLCmQsgChyQEBU98vf9mNduD6N3e2beZ56ZSf144x5/fPCI3+59xp8fPuavT57wu5x/ufuQX++e8fOdxfpC3v++/wWvHj7jn0/P+ffBU14+OOeVWuX836Ov+OnWfVJHnT7PJte4Um8yabSZNNtMWx1ZO1yV8369NTe1nzY6vNvscdDqMpX3iZzVquyg2WV3fYOU4dgoW8pmuJDLspTOkFpWliataSwbYlZ+vl8ycqT1PMtaboEVH822cKKQoFjA8jxSruvguS6B51IuJ6xdKtPZLFGrr1AqF/ADnzCJiPyAIAqIo4hQ7pSPMl/8Qt+nVCzKXgV0HHwB2qGLa9uE5YhSLSZaSwgLEY5lLz4MAuZYcc7nDQzDxFHZmSaG5xDHMYpcypEgrvqtFOIVAnRJQfddbMvClnvHd8RRBfLQNJ0w9PnobEptvUT6QpZqq8J6a40kTnCFbcp+HTAv4FQmR2PrIhvtKhnbJKok2IkwEjYK5wmT5maVFy/P+eb7W5yeTTh/fszjp9fkw2D+ccqWlOI4ZHSlxdGNIdvb6+zutRiMGlQqBZqdGnuH27x/NKA/rDN4u8HJ7TGz4x0Ob444OR0z3G1SlKIoYikVNRCRTz/eZ/reFrlcXooRsX/QJZvRZR8LixO+/eGOpOth5E1ywlhzLDJpqXpaQxdNC4VkEVClogSvrJbQdXNeVVf0MlWKch9JwZ58fcyX390kFv1cqWRSLRIIJpB2URg/DAUXLVJ2HHderUwmQy6roVlStZyGI5o6uo4pvXf9dMDnz69jhTZa5ArGIitMTVe01bKC00iS+E3KttBdpdHYEo1a9Aeinazaxhp+r00h6XGxtsNkPGGz1mBU3+StelEsYaXdJV/vY9V7EuO1hqYpOhUvSTH2mR2NmB70qc2GpIdN7J0BtdqMlfJVBitj9lZk5C73OBysMtsqUd19h8xghtEd47iLVpOAhrSEI41qYVqL9jDykqo0qWnoWNIF83dLxxN5Fi1kyRAIXiSxXA9LYpjS4JYKqKgmSSKihlJFMTVaoRovEVyEV92vUnHF0VFj6inNF+f5vfPm3Z0X5X8PAKPFv7Xd4gAAAABJRU5ErkJggg==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/f9c467e199da49a066218fb37b2e7078/0cbef/pbi.avif 163w,
/static/f9c467e199da49a066218fb37b2e7078/bffb7/pbi.avif 325w,
/static/f9c467e199da49a066218fb37b2e7078/69c29/pbi.avif 650w,
/static/f9c467e199da49a066218fb37b2e7078/6d24a/pbi.avif 975w,
/static/f9c467e199da49a066218fb37b2e7078/a2baf/pbi.avif 1300w,
/static/f9c467e199da49a066218fb37b2e7078/9eae2/pbi.avif 1642w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/f9c467e199da49a066218fb37b2e7078/94563/pbi.webp 163w,
/static/f9c467e199da49a066218fb37b2e7078/647a8/pbi.webp 325w,
/static/f9c467e199da49a066218fb37b2e7078/c1dc5/pbi.webp 650w,
/static/f9c467e199da49a066218fb37b2e7078/1e975/pbi.webp 975w,
/static/f9c467e199da49a066218fb37b2e7078/063bf/pbi.webp 1300w,
/static/f9c467e199da49a066218fb37b2e7078/ee7fd/pbi.webp 1642w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/f9c467e199da49a066218fb37b2e7078/222b7/pbi.png 163w,
/static/f9c467e199da49a066218fb37b2e7078/ff46a/pbi.png 325w,
/static/f9c467e199da49a066218fb37b2e7078/a6d36/pbi.png 650w,
/static/f9c467e199da49a066218fb37b2e7078/e548f/pbi.png 975w,
/static/f9c467e199da49a066218fb37b2e7078/3c492/pbi.png 1300w,
/static/f9c467e199da49a066218fb37b2e7078/799f3/pbi.png 1642w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/f9c467e199da49a066218fb37b2e7078/a6d36/pbi.png&quot;
            alt=&quot;Crisis de la Convertibilidad&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Crisis de la Convertibilidad&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;El resultado verdaderamente fue satisfactorio. Si se repasa la historia, entre 1960 y 2001 se registaron veintinueve años con déficit fiscal y en cuenta corriente, y en los 13 años restantes hubo un superávit solo en cuenta corriente. En 2002 se revirtió el resultado del déficit de cuenta corriente, y en los años siguientes, por primera vez en 50 años, se registró superávit en ambos sectores.&lt;/p&gt;
&lt;p&gt;El esquema de la pesificación asimétrica permitió, poco a poco, ir recomponiendo el tejido social y productivo. Los que más ganaron en términos de poder adquisitivo en pesos fueron los que tenían dóalres en el exterior o en el &quot;colchón&quot;. Los que más perdieron, como de costumbre en todas las grandes crisis, fueron quienes tenían ingresos fijos: trabajadores y jubilados.&lt;/p&gt;
&lt;h3 id=&quot;había-forma-de-evitar-injusticias-post-covertibilidad&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#hab%C3%ADa-forma-de-evitar-injusticias-post-covertibilidad&quot; aria-label=&quot;había forma de evitar injusticias post covertibilidad permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;¿Había forma de evitar injusticias post-covertibilidad?&lt;/h3&gt;
&lt;p&gt;No creo que existían salidas indoloras. Sigo creyendo que no las hay aún hoy para salir de la crisis durante 2023. El autor solo puede decir que en esa coyuntura y con el poco tiempo disponible no había medidas diferentes o mejores que las que tomaron, ni mecanismos más adecuados para atemperar costos. Se dio a los secotres más necesitados la máxima protección posible con los pocos instrumentos disponibles.&lt;/p&gt;
&lt;h3 id=&quot;cómo-es-que-no-hubo-una-hiperinflación&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c%C3%B3mo-es-que-no-hubo-una-hiperinflaci%C3%B3n&quot; aria-label=&quot;cómo es que no hubo una hiperinflación permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;¿Cómo es que no hubo una hiperinflación?&lt;/h3&gt;
&lt;p&gt;Gran preocupación del Presidente banfileño Duhalde. Los resguardos estaban para evitarla. La devaluación fue muy importante pero no se aumentaron los salarios ni las tarifas y se desindexó la economía; también se llevó adelante una política monetaria muy prudente, el resultado fiscal primario fue positivo y se redujo a menos de la mitad el déficit financiero, mientras que el altísimo superávit comercial permitió la recomposición de las reservas. Se hizo exactamente lo contrario de lo realizado en las anteriores crisis.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/72dbdf5a164a00461b487fe54b5b2cdf/1e093/inflacion.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 74.84662576687117%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAABYlAAAWJQFJUiTwAAABe0lEQVR42p2Te4uCUBDF+/4fLQjqn9KCINLU3uYrrZzd37AjausGe+Fw577OPfMa7XY7mc1mslwuZb1ei+M4itVqJYvFQlzXlc1mI/P5XO9gczaZTPQdNuD8fD7L6PV6SVEUcr/fJc9zSdNU4jjWOcsyndlPkkTXdsfOWfO2LEt5Pp8ykp8B8X6/l8PhIKgOw1Dt9nw6nfQOCIJA16jirY2G0EjrulYM2W3Yfnt0CJGOG0jnMm6Aqqoa+ze0STuExPJ4PKo72+22If6EQYVZnmlWx+OxTKfTj4TmdofQ5F4uFw22ZZzRj58NW/PhWwxtg4xFUaRZw+0+CcRWKhBRRghgbzCGaZKqUsjtMYXMJ9ie52l8qT1Lxp9JwdXH46Hwfb/pGDoENSinJvEEYPP5Wx3aD+2Kt264Xq/fiLV7UGndQSlxn3lQIYeUC6AzUIGLAMWAPc5wn3Bgd5KCe1a42td50SgFZpN9wH3W1sO87RDebjcNOrHoH/5nfAHyAomCF0bMxwAAAABJRU5ErkJggg==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/72dbdf5a164a00461b487fe54b5b2cdf/0cbef/inflacion.avif 163w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/bffb7/inflacion.avif 325w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/69c29/inflacion.avif 650w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/6d24a/inflacion.avif 975w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/a2baf/inflacion.avif 1300w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/30bb5/inflacion.avif 1376w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/72dbdf5a164a00461b487fe54b5b2cdf/94563/inflacion.webp 163w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/647a8/inflacion.webp 325w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/c1dc5/inflacion.webp 650w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/1e975/inflacion.webp 975w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/063bf/inflacion.webp 1300w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/8aa17/inflacion.webp 1376w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/72dbdf5a164a00461b487fe54b5b2cdf/222b7/inflacion.png 163w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/ff46a/inflacion.png 325w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/a6d36/inflacion.png 650w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/e548f/inflacion.png 975w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/3c492/inflacion.png 1300w,
/static/72dbdf5a164a00461b487fe54b5b2cdf/1e093/inflacion.png 1376w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/72dbdf5a164a00461b487fe54b5b2cdf/a6d36/inflacion.png&quot;
            alt=&quot;Inflación 2002-2005, microscópica comparada con la del último gobierno kirchnerista&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Inflación 2002-2005, microscópica comparada con la del último gobierno kirchnerista&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/bbcefa56096944bd542026b52ec7334d/e9140/empleo.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 77.30061349693251%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAABYlAAAWJQFJUiTwAAABP0lEQVR42qWT646CUAyEef+n4zeJsAEUUQTkDgLHfE1KQM2uuk0ajpx2nE4Hy6xit9sZ27ZN3/fm27D0AIjjOMb3fZOmqbyb5/l7QKJpGtN1nflPWGsmRVFIfhLjOJphGBaMDWBZlqau67eA6Ller9IDCYCfAKuq+pUhdTRScz6fBZA8nU5bQA30Ox6PUqQxTZMkY9GEzlmWCTipdy+Xwrg0kEmSyOYViOa2bYUdIG9vWTUEDPvcbrdlTPIvKz0xXC8FJoAiPMAf+5CRWIzaAUCAeKpe69QavX8CpDmOYxMEgWyO836/Fz3DMJRkaTx5x/lwOEidfl3Woy0YmYLL5SKfoed5slX0y/NcGr0fT/7IdV0TRdFG+8WHj2KrRZBgbQumUDc83gkgo0EfVjomyTvYYGDYcuYeRvxmUa+Wcgebj5ap/SZrYQAAAABJRU5ErkJggg==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/bbcefa56096944bd542026b52ec7334d/0cbef/empleo.avif 163w,
/static/bbcefa56096944bd542026b52ec7334d/bffb7/empleo.avif 325w,
/static/bbcefa56096944bd542026b52ec7334d/69c29/empleo.avif 650w,
/static/bbcefa56096944bd542026b52ec7334d/6d24a/empleo.avif 975w,
/static/bbcefa56096944bd542026b52ec7334d/a5538/empleo.avif 1226w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/bbcefa56096944bd542026b52ec7334d/94563/empleo.webp 163w,
/static/bbcefa56096944bd542026b52ec7334d/647a8/empleo.webp 325w,
/static/bbcefa56096944bd542026b52ec7334d/c1dc5/empleo.webp 650w,
/static/bbcefa56096944bd542026b52ec7334d/1e975/empleo.webp 975w,
/static/bbcefa56096944bd542026b52ec7334d/ab43a/empleo.webp 1226w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/bbcefa56096944bd542026b52ec7334d/222b7/empleo.png 163w,
/static/bbcefa56096944bd542026b52ec7334d/ff46a/empleo.png 325w,
/static/bbcefa56096944bd542026b52ec7334d/a6d36/empleo.png 650w,
/static/bbcefa56096944bd542026b52ec7334d/e548f/empleo.png 975w,
/static/bbcefa56096944bd542026b52ec7334d/e9140/empleo.png 1226w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/bbcefa56096944bd542026b52ec7334d/a6d36/empleo.png&quot;
            alt=&quot;La demanda de empleo y la actividad industrial se reactiva rápidamente. Base 2000 = 100&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;La demanda de empleo y la actividad industrial se reactiva rápidamente. Base 2000 = 100&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;h3 id=&quot;la-salida&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#la-salida&quot; aria-label=&quot;la salida permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;La salida&lt;/h3&gt;
&lt;p&gt;A Remes Lenicov le hubiera gustado quedarse luego de 115 días, pero no es la condiciones de ese entonces. Duhalde, que no debe haber querido quedar en la historia como un presidente peronista que ajustó, quiso comenzar a emitir todo lo posible para aumentar salarios, dar créditos baratos, romper con el mundo, fijar el tipo de cambio y controlar precios. JRL presenta su renuncia allí mismo. Los gobernadores, que tampoco querían cambiar la política monetaria, presionaron para continuar el rumbo con el &lt;em&gt;Documentos de los 14 puntos&lt;/em&gt;. Duhalde luego le pidió que se quedara, pero ya era tarde: la renuncia es una renuncia.&lt;/p&gt;
&lt;p&gt;Fue una pena para JRL y su equipo, porque después tuvieron que escuchar a Nestor Kirchner y la tropa austral decir que todo empezó cuando llegaron ellos en mayo del 2003. El entonces Jefe de Gabinete, Alberto Fernández, recibió una carta de JRL explicándole qué habían hecho en esos 4 meses para que no digan semejante barbaridad, a lo que el primero le contestó: &quot;Sí, tenés razón, pero es lo que vamos a seguir diciendo&quot;. Ahí nació &quot;el relato&quot;.&lt;/p&gt;
&lt;h2 id=&quot;conclusión&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#conclusi%C3%B3n&quot; aria-label=&quot;conclusión permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Conclusión&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;La historia te pone en en el lugar que ella quiere, y no en el que uno pretende.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Sobre la crisis, y en mi humilde opinión, hubiera procurado distribuir el costo de la salida del 2001 más sobre el Estado que sobre la población, pero reconozco que la conyuntura era difícil y que el Estado debía seguir prestando servicios, sobre todo a los más necesitados. JRL agrega que hubiera sido contraproducente y que se corría el riesgo de perder todo lo hecho para ordenar la macro. En ese momento, la sociedad no tenía paciencia ni motivación para escuchar explicaciones. Creo que ahora sí la tiene, y, es más, la necesita (comparar las explicaciones de la herencia recibida de Macri vs Milei).&lt;/p&gt;
&lt;p&gt;En varias partes JRL sobreutiliza lo contrafáctico para justificar las acciones que lideró. Por ejemplo, cuando comenta como &quot;descabellado porque conducía al caos&quot; la propuesta del FMI en las negociaciones del 2002. Aún así, tampoco me parece justo recaerle en esto cuando en semejante crisis hay que tomar decisiones contundentes en el momento, y no se dispone de un largo tiempo para experimentar y analizar. Él mismo reitera que la velocidad de la aplicación de las soluciones era tan importante como la solución misma.&lt;/p&gt;
&lt;p&gt;El libro es un relato formidable de cuatro meses vertiginosos, contado desde el punto de vista de un protagonista central de la historia. Complementa con un gran resumen de los últimos 20 años, y cierra con pautas clave hacia un desarrollo sustentable. Hayas vivido esos años o no, es un &lt;em&gt;racconto&lt;/em&gt; primordial para entender cómo llegamos al presente.&lt;/p&gt;
&lt;p&gt;Cuando la situación es compleja, nadie quiere poner la cara. Los aprietas diversos pero constantes son parte de las reglas del juego. Estas reglas estuvieron, están y seguirán estando vigentes en nuestro país.&lt;/p&gt;
&lt;p&gt;Salir del 2001 no fue un trabajo &lt;em&gt;sucio&lt;/em&gt;: se hizo lo que se pensaba que se debía hacer.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Insights in 'Designing Data-Intensive Applications' - Part 3/3]]></title><description><![CDATA[A post to share key insights after reading Martin Kleppmann's essential book. Part 3/3]]></description><link>https://www.j1nma.com/designing-data-intensive-applications-part-3/</link><guid isPermaLink="false">https://www.j1nma.com/designing-data-intensive-applications-part-3/</guid><pubDate>Sun, 10 Dec 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Welcome to my blog on the book &quot;Designing Data Intensive Applications&quot; by Martin Kleppmann. In this post, I will share with you key principles, trade-offs, and technologies that I found as the most interesting for building robust and scalable data systems.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Most of these notes are as they appear in the original book, or tailored by me, but all ideas are a creation of Martin or authors Martin quotes in his book.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This is Part 3. Check Part 1, &lt;em&gt;Foundations of Data Systems&lt;/em&gt;, &lt;a href=&quot;https://www.j1nma.com/designing-data-intensive-applications&quot;&gt;here&lt;/a&gt;, and Part 2, &lt;em&gt;Distributed Data&lt;/em&gt;, &lt;a href=&quot;https://www.j1nma.com/designing-data-intensive-applications-part-2&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;!-- TOC --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#derived-data&quot;&gt;Derived Data&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#intro&quot;&gt;Intro&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#two-categories-for-store-and-process-systems&quot;&gt;Two Categories for store-and-process systems&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#batch-oriented-dataflows&quot;&gt;Batch-oriented dataflows&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#mapreduce-workflows&quot;&gt;MapReduce workflows&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#output-of-batch-workflows&quot;&gt;Output of Batch Workflows&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#downsides&quot;&gt;Downsides&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#dataflow-engines&quot;&gt;Dataflow Engines&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#streams-processing-batch-but-with-lower-delays&quot;&gt;Streams Processing: Batch but with lower delays.&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#transmitting-event-streams&quot;&gt;Transmitting Event Streams&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#partitioned-logs&quot;&gt;Partitioned Logs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#stream-enrichment&quot;&gt;Stream enrichment&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#fault-tolerance&quot;&gt;Fault Tolerance&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#ideas-for-reliable-scalable-and-maintable-applications&quot;&gt;Ideas for reliable, scalable and maintable applications&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#schema-migration-in-a-railway-&quot;&gt;Schema Migration in a... railway? 🚂&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#lambda-architecture&quot;&gt;Lambda architecture&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#designing-applications-around-dataflow&quot;&gt;Designing Applications Around Dataflow&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#observing-derived-state&quot;&gt;Observing Derived State&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#pushing-state-changes-to-clients&quot;&gt;Pushing state changes to clients&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#aiming-for-correctness&quot;&gt;Aiming for Correctness&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#the-end-to-end-argument-for-databases&quot;&gt;The End-to-End Argument for Databases&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#transaction-abstraction&quot;&gt;Transaction Abstraction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#timeliness-and-integrity&quot;&gt;Timeliness and Integrity&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#loosely-interpreted-constraints&quot;&gt;Loosely interpreted constraints&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#designing-for-auditability&quot;&gt;Designing for Auditability&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#do-the-right-thing&quot;&gt;Do the Right Thing&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#not-so-data-driven&quot;&gt;Not-so-data-driven&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#privacy&quot;&gt;Privacy&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#the-end&quot;&gt;The End&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- /TOC --&gt;
&lt;h1 id=&quot;derived-data&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#derived-data&quot; aria-label=&quot;derived data permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Derived Data&lt;/h1&gt;
&lt;h2 id=&quot;intro&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#intro&quot; aria-label=&quot;intro permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Intro&lt;/h2&gt;
&lt;p&gt;The first two parts went from the layout of the data on disk to the limits of distributed consistency. However, a single database was assumed at all times. In real life, access patterns are more complex, and there is no one database that can satisfy simultaneously different use cases. Thus, applications use a combination of stores, caches and mechanisms.&lt;/p&gt;
&lt;p&gt;In this final part, we&apos;ll have a look at the complexities around integrating multiple different systems. If a vendor offers you a product that can &quot;satisfy all your needs&quot;, think again.&lt;/p&gt;
&lt;h3 id=&quot;two-categories-for-store-and-process-systems&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#two-categories-for-store-and-process-systems&quot; aria-label=&quot;two categories for store and process systems permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Two Categories for store-and-process systems&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Systems of record&lt;/em&gt;
Also known as &quot;source of truth&quot;, it&apos;s the place where new data comes in and is represented exactly once, normally normalized.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Derived data systems&lt;/em&gt;
Existing data is taking from one system and processed in some way i.e. a cache, denormalized values, indexes, materialized views. Good read performance.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;10-batch-oriented-dataflows&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#10-batch-oriented-dataflows&quot; aria-label=&quot;10 batch oriented dataflows permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;10. Batch-oriented dataflows&lt;/h2&gt;
&lt;p&gt;Types of Systems:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;em&gt;Services (online)&lt;/em&gt;
A service waits for a request or instruction from a client to arrive. When one is received, the service tries to handle it as quickly as possible and sends a response back. Response time is usually the primary measure of performance of a service, and availability is often very important (if the client can’t reach the service, the user will probably get an error message).&lt;/li&gt;
&lt;li&gt;Batch processing (offline)
Such system takes a large amount of input data, runs a job to process it, Since normally there isn’t a user waiting for the job to finish, batch jobs are often scheduled to run periodically. The primary performance measure of a batch job is usually throughput (the time it takes to crunch through an input dataset of a certain size). MapReduce is for instance a batch processing algorithm.&lt;/li&gt;
&lt;li&gt;Stream processing (near-real-time)
This type is somewhere between the previous two. Like a batch processing system, a stream processor consumes inputs and produces outputs. However, a stream job operates on events shortly after they happen, whereas a batch job operates on a fixed set of input data. This difference allows stream processing systems to have lower latency than the equivalent batch systems.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;mapreduce-workflows&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#mapreduce-workflows&quot; aria-label=&quot;mapreduce workflows permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;MapReduce workflows&lt;/h3&gt;
&lt;p&gt;A batch job’s output is only considered valid when the job has completed successfully (MapReduce discards the partial output of a failed job). To handle these dependencies between job executions, various workflow schedulers for Hadoop have been developed, including Oozie, Azkaban, Airflow and Luigi.&lt;/p&gt;
&lt;p&gt;While MPP (massively parallel processing) databases focus on parallel execution of analytic SQL queries on a cluster of machines, the combination of MapReduce and a distributed filesystem provides something much more like a general-purpose operating system that can run arbitrary programs.&lt;/p&gt;
&lt;h4 id=&quot;joins&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#joins&quot; aria-label=&quot;joins permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Joins&lt;/h4&gt;
&lt;p&gt;When we talk about joins in the context of batch processing, we mean resolving all occurrences of some association within a dataset. For example, we assume that a job is processing the data for all users simultaneously, not merely looking&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/9767912c94ea5b7d68a225827e8bca3c/78958/batchjoin.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 46.62576687116564%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAABYlAAAWJQFJUiTwAAABMklEQVR42l2SaQ+CMAyG+f+/jw8EghAuuZVTDqH6NJlRlzRltHuPbtYwDHK73aSqKqnrWvI8l77vhXUcx088n09Z11XGcZTH46F5nmfZtk3r/LOmaZKyLCWOY4miSIFput/vGk3T6EGAOLQsi1wuFwnDUHzflyzLlIgFsEUzCouiUFDAOGTbtjiOo4qp0QM5GSe4gIxAEHtILWR+F40FsqkBZOyhCCf0pmmqe9TiTAFpgrV8q2jezLBT/F/neapS1GNx33fNkJuZfizDyDyu16tahJ2DMNLENwEgQN9gZMg+M8ROkRcKyixQy2W4rqskqDWXhQqy53laY8bUAPoBZBZBEGhGJaCoxD7g5K7rFDBJEp0rz61tW+3lv3Gkl0IwS+xDwB4bBE/FWPp/m6ZuvgF8AXVbsRg9MeQDAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/9767912c94ea5b7d68a225827e8bca3c/0cbef/batchjoin.avif 163w,
/static/9767912c94ea5b7d68a225827e8bca3c/bffb7/batchjoin.avif 325w,
/static/9767912c94ea5b7d68a225827e8bca3c/69c29/batchjoin.avif 650w,
/static/9767912c94ea5b7d68a225827e8bca3c/6d24a/batchjoin.avif 975w,
/static/9767912c94ea5b7d68a225827e8bca3c/a2baf/batchjoin.avif 1300w,
/static/9767912c94ea5b7d68a225827e8bca3c/5edaa/batchjoin.avif 1320w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/9767912c94ea5b7d68a225827e8bca3c/94563/batchjoin.webp 163w,
/static/9767912c94ea5b7d68a225827e8bca3c/647a8/batchjoin.webp 325w,
/static/9767912c94ea5b7d68a225827e8bca3c/c1dc5/batchjoin.webp 650w,
/static/9767912c94ea5b7d68a225827e8bca3c/1e975/batchjoin.webp 975w,
/static/9767912c94ea5b7d68a225827e8bca3c/063bf/batchjoin.webp 1300w,
/static/9767912c94ea5b7d68a225827e8bca3c/d33d4/batchjoin.webp 1320w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/9767912c94ea5b7d68a225827e8bca3c/222b7/batchjoin.png 163w,
/static/9767912c94ea5b7d68a225827e8bca3c/ff46a/batchjoin.png 325w,
/static/9767912c94ea5b7d68a225827e8bca3c/a6d36/batchjoin.png 650w,
/static/9767912c94ea5b7d68a225827e8bca3c/e548f/batchjoin.png 975w,
/static/9767912c94ea5b7d68a225827e8bca3c/3c492/batchjoin.png 1300w,
/static/9767912c94ea5b7d68a225827e8bca3c/78958/batchjoin.png 1320w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/9767912c94ea5b7d68a225827e8bca3c/a6d36/batchjoin.png&quot;
            alt=&quot;Batch join example: log of user activity events reduce-side sort-merge joined with a database of user profiles. Figure 10-3&quot;
            title=&quot;Batch join example.&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Batch join example.&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;Making random-access requests over the network for every record you want to process is too slow. Moreover, querying a remote database would mean that the batch job becomes nondeterministic, because the data in the remote database might change while the job is running.&lt;/p&gt;
&lt;p&gt;Thus, a better approach would be to take a copy of the user database and to put it in the same distributed filesystem as the log of user activity events. You would then have the user database in one set of files in HDFS and the user activity records in another set of files, and you could use MapReduce to bring together all of the relevant records in the same place and process them efficiently. If the input datasets are partitioned into multiple files, each could be processed with multiple mappers in parallel.&lt;/p&gt;
&lt;h4 id=&quot;sessionization&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sessionization&quot; aria-label=&quot;sessionization permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sessionization&lt;/h4&gt;
&lt;p&gt;A common use for grouping is collating all the activity events for a particular user session, in order to find out the sequence of actions that the user took—a process called sessionization. For example, such analysis could be used to work out whether users who were shown a new version of your website are more likely to make a purchase than those who were shown the old version (A/B testing), or to calculate whether some marketing activity is worthwhile.&lt;/p&gt;
&lt;h4 id=&quot;handling-skew&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#handling-skew&quot; aria-label=&quot;handling skew permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Handling skew&lt;/h4&gt;
&lt;p&gt;Collecting all activity related to a celebrity (e.g., replies to something they posted) in a single reducer can lead to significant skew (also known as hot spots)—that is, one reducer that must process significantly more records than the others. Since a MapReduce job is only complete when all of its mappers and reducers have completed, any subsequent jobs must wait for the slowest reducer to complete before they can start.&lt;/p&gt;
&lt;p&gt;If a join input has hot keys, there are a few algorithms you can use to compensate. For example, the skewed join method in Pig first runs a sampling job to determine which keys are hot.&lt;/p&gt;
&lt;h3 id=&quot;output-of-batch-workflows&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#output-of-batch-workflows&quot; aria-label=&quot;output of batch workflows permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Output of Batch Workflows&lt;/h3&gt;
&lt;p&gt;Where does batch processing fit in? It is not transaction processing, nor is it analytics. It is closer to analytics, in that a batch process typically scans over large portions of an input dataset. However, a workflow of MapReduce jobs is not the same as a SQL query used for analytic purposes. The output of a batch process is often not a report, but some other kind of structure.&lt;/p&gt;
&lt;h4 id=&quot;philosophy-of-outputs&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#philosophy-of-outputs&quot; aria-label=&quot;philosophy of outputs permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Philosophy of outputs&lt;/h4&gt;
&lt;p&gt;By treating inputs as immutable and avoiding side effects (such as writing to external databases), batch jobs not only achieve good performance but also become much easier to maintain:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;ease of rolling back: being able to recover from buggy code (&apos;human fault tolerance&apos;)&lt;/li&gt;
&lt;li&gt;feature development can proceed more quickly than in an environment where mistakes could mean irreversible damage. This principle of minimizing irreversibility is beneficial for Agile software development&lt;/li&gt;
&lt;li&gt;automatic retry is safe because inputs are immutable and outputs from failed tasks are discarded by the MapReduce framework&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;designing-for-frequent-faults&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#designing-for-frequent-faults&quot; aria-label=&quot;designing for frequent faults permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Designing for frequent faults&lt;/h4&gt;
&lt;blockquote&gt;
&lt;p&gt;At Google, a MapReduce task that runs for an hour has an approximately 5% risk of being terminated to make space for a higher-priority process. This rate is more than an order of magnitude higher than the rate of failures due to hardware issues, machine reboot, or other reasons. At this rate of preemptions, if a job has 100 tasks that each run for 10 minutes, there is a risk greater than 50% that at least one task will be terminated before it is finished.&lt;/p&gt;
&lt;p&gt;And this is why MapReduce is designed to tolerate frequent unexpected task termination: it’s not because the hardware is particularly unreliable, it’s because the freedom to arbitrarily &gt;  terminate processes enables better resource utilization in a computing cluster.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;downsides&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#downsides&quot; aria-label=&quot;downsides permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Downsides&lt;/h3&gt;
&lt;p&gt;MapReduce’s approach of fully materializing (writing to disk) intermediate state has downsides compared to other batch mechanisms like Unix pipes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A MapReduce job can only start when all tasks in the preceding jobs (that generate its inputs) have completed&lt;/li&gt;
&lt;li&gt;Mappers are often redundant: they just read back the same file that was just written by a reducer&lt;/li&gt;
&lt;li&gt;Storing intermediate state in a distributed filesystem means those files are replicated across several nodes, which is often overkill for such temporary data&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;dataflow-engines&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#dataflow-engines&quot; aria-label=&quot;dataflow engines permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Dataflow Engines&lt;/h3&gt;
&lt;p&gt;In order to fix these problems, several new engines were developed, like Spark. They handle an entire workflow as one job, rather than breaking it up into independent subjobs. Since they explicitly model the flow of data through several processing stages, these systems are known as dataflow engines. Like MapReduce, they work by repeatedly calling a user-defined function to process one record at a time on a single thread. They parallelize work by partitioning inputs, and they copy the output of one function over the network to become the input to another function.&lt;/p&gt;
&lt;p&gt;Unlike in MapReduce, these &lt;em&gt;operators&lt;/em&gt; need not take the strict roles of alternating map and reduce, but instead can be assembled in more flexible ways. One option is to repartition and sort records by key, like in the shuffle stage of MapReduce. This feature enables sort-merge joins and grouping in the same way as in MapReduce.&lt;/p&gt;
&lt;h4 id=&quot;advantages&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#advantages&quot; aria-label=&quot;advantages permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Advantages&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Expensive work such as sorting need only be performed in places where it is actually required, rather than always happening by default between every map and reduce stage.&lt;/li&gt;
&lt;li&gt;There are no unnecessary map tasks, since the work done by a mapper can often be incorporated into the preceding reduce operator (because a mapper does not change the partitioning of a dataset).&lt;/li&gt;
&lt;li&gt;Because all joins and data dependencies in a workflow are explicitly declared, the scheduler has an overview of what data is required where, so it can make locality optimizations. For example, it can try to place the task that consumes some data on the same machine as the task that produces it, so that the data can be exchanged through a shared memory buffer rather than having to copy it over the network.&lt;/li&gt;
&lt;li&gt;It is usually sufficient for intermediate state between operators to be kept in memory or written to local disk, which requires less I/O than writing it to HDFS (where it must be replicated to several machines and written to disk on each replica). MapReduce already uses this optimization for mapper output, but dataflow engines generalize the idea to all intermediate state.&lt;/li&gt;
&lt;li&gt;Operators can start executing as soon as their input is ready; there is no need to wait for the entire preceding stage to finish before the next one starts.&lt;/li&gt;
&lt;li&gt;Existing Java Virtual Machine (JVM) processes can be reused to run new operators, reducing startup overheads compared to MapReduce (which launches a new JVM for each task).&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;fault-tolerance&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#fault-tolerance&quot; aria-label=&quot;fault tolerance permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Fault Tolerance&lt;/h4&gt;
&lt;p&gt;Spark, Flink, and Tez avoid writing intermediate state to HDFS, so they take a different approach to tolerating faults: if a machine fails and the intermediate state on that machine is lost, it is recomputed from other data that is still available.&lt;/p&gt;
&lt;p&gt;Nondeterminism when recomputing data needs to be removed in order to reliably recover from faults, for example by generating pseudorandom numbers using a fixed seed.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Recomputing data is not always the right answer: if the intermediate data is much smaller than the source data, or if the computation is very CPU-intensive, it is probably cheaper to materialize the intermediate data to files than to recompute it.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Thanks to the framework, your code in a batch processing job does not need to worry about implementing fault-tolerance mechanisms: the framework can guarantee that the final output of a job is the same as if no faults had occurred, even though in reality various tasks perhaps had to be retried. These reliable semantics are much stronger than what you usually have in online services that handle user requests and that write to databases as a side effect of processing a request.&lt;/p&gt;
&lt;h2 id=&quot;11-streams-processing-batch-but-with-lower-delays&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#11-streams-processing-batch-but-with-lower-delays&quot; aria-label=&quot;11 streams processing batch but with lower delays permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;11. Streams Processing: Batch but with lower delays.&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;A complex system that works is invariably found to have evolved from a simple system that works. The inverse proposition also appears to be true: A complex system designed from scratch never works and cannot be made to work.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;John Gall, Systemantics (1975)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The problem with daily batch processes is that changes in the input are only reflected in the output a day later, which is too slow for many impatient users. To reduce the delay, we can run the processing more frequently—say, processing a second’s worth of data at the end of every second—or even continuously, abandoning the fixed time slices entirely and simply processing every event as it happens. That is the idea behind stream processing.&lt;/p&gt;
&lt;p&gt;Crucially, in batch processing jobs, the input data is &lt;em&gt;bounded&lt;/em&gt;: it has a known, fixed size (for example, it consists of a set of log files at some point in time, or a snapshot of a database’s contents). Because it is bounded, a job knows when it has finished reading the entire input, and so a job eventually completes when it is done. In stream processing, the input is &lt;em&gt;unbounded&lt;/em&gt;. In this case, a job is never complete, because at any time there may still be more work coming in. Both are similar in some respects, but the assumption of unbounded streams also changes a lot about how we build systems&lt;/p&gt;
&lt;p&gt;Some examples that are naturally represented as streams are user activity events, sensors providing periodic readings, and data feeds (e.g., market data in finance).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The writes to a database can also be thought of as a stream: we can capture the changelog—i.e., the history of all changes made to a database—either implicitly through change data capture or explicitly through event sourcing. Log compaction allows the stream to retain a full copy of the contents of a database.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;transmitting-event-streams&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#transmitting-event-streams&quot; aria-label=&quot;transmitting event streams permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Transmitting Event Streams&lt;/h3&gt;
&lt;p&gt;In a stream processing context, a record is more commonly known as an event, but it is essentially the same thing: a small, self-contained, immutable object containing the details of something that happened at some point in time.&lt;/p&gt;
&lt;p&gt;In streaming terminology, an event is generated once by a producer (also known as a publisher or sender), and then potentially processed by multiple consumers (subscribers or recipients). In a filesystem, a filename identifies a set of related records; in a streaming system, related events are usually grouped together into a topic or stream.&lt;/p&gt;
&lt;h4 id=&quot;direct-messaging-from-producers-to-consumers&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#direct-messaging-from-producers-to-consumers&quot; aria-label=&quot;direct messaging from producers to consumers permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Direct messaging from producers to consumers&lt;/h4&gt;
&lt;blockquote&gt;
&lt;p&gt;UDP multicast is widely used in the financial industry for streams such as stock market feeds, where low latency is important.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/d9ed5/lb-fan-out.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 47.852760736196316%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAIAAAA7N+mxAAAACXBIWXMAAFxGAABcRgEUlENBAAABU0lEQVR42iWR6ZKDIBCEef8HzP7YbETjleDJoaLG7AdMWdTA9PR0j+I4jk8Ma+37/e6U6rpu3/fv9+uc01qT6HnmkSs5SE5jDFfRqc5YsyzLNE3ruoZXa3fvyeHd1i00a71tG+g9Bjklv23Ce092nuc8TZ/zpEb/dV1crxg0z/PMCR28qcSVRCilIGaySWcMGMdxTKRJv7POaLM4x1hKiKcqkjYXI5eyqeu2bZ9FwZcMp+Y8l2ykaRreq6piQbwLxIzDUFcVY0Pt+azrOpc5CNBQA2J+SaEIIaUsy7Lvex4FPcG993ggxx4UzKQT/8hLttum+bndZCbvv/fH34OW4BkDSTM40HrW4ccohTDocZiU8y/YDo4gfb1eS8SLtPcE4kQtr7hg+Bn/f5oMV5ZliEdCkedJqei73hgLEx6Ahr1ayyIYBVfaNjgGTGOIYRhQ5CL+H2C2OveW5e03AAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/0cbef/lb-fan-out.avif 163w,
/static/13eb5da78e0782dc1ecfe4e50774710b/bffb7/lb-fan-out.avif 325w,
/static/13eb5da78e0782dc1ecfe4e50774710b/69c29/lb-fan-out.avif 650w,
/static/13eb5da78e0782dc1ecfe4e50774710b/6d24a/lb-fan-out.avif 975w,
/static/13eb5da78e0782dc1ecfe4e50774710b/a2baf/lb-fan-out.avif 1300w,
/static/13eb5da78e0782dc1ecfe4e50774710b/a40d8/lb-fan-out.avif 2880w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/94563/lb-fan-out.webp 163w,
/static/13eb5da78e0782dc1ecfe4e50774710b/647a8/lb-fan-out.webp 325w,
/static/13eb5da78e0782dc1ecfe4e50774710b/c1dc5/lb-fan-out.webp 650w,
/static/13eb5da78e0782dc1ecfe4e50774710b/1e975/lb-fan-out.webp 975w,
/static/13eb5da78e0782dc1ecfe4e50774710b/063bf/lb-fan-out.webp 1300w,
/static/13eb5da78e0782dc1ecfe4e50774710b/d3d72/lb-fan-out.webp 2880w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/222b7/lb-fan-out.png 163w,
/static/13eb5da78e0782dc1ecfe4e50774710b/ff46a/lb-fan-out.png 325w,
/static/13eb5da78e0782dc1ecfe4e50774710b/a6d36/lb-fan-out.png 650w,
/static/13eb5da78e0782dc1ecfe4e50774710b/e548f/lb-fan-out.png 975w,
/static/13eb5da78e0782dc1ecfe4e50774710b/3c492/lb-fan-out.png 1300w,
/static/13eb5da78e0782dc1ecfe4e50774710b/d9ed5/lb-fan-out.png 2880w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/a6d36/lb-fan-out.png&quot;
            alt=&quot;Load-balancing vs fan-out. Figure 11-1.&quot;
            title=&quot;Load-balancing vs fan-out patterns&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Load-balancing vs fan-out patterns&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;h3 id=&quot;partitioned-logs&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#partitioned-logs&quot; aria-label=&quot;partitioned logs permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Partitioned Logs&lt;/h3&gt;
&lt;p&gt;Sending a packet over a network or making a request to a network service is normally a transient operation that leaves no permanent trace. Message brokers are built around this transient messaging mindset. Databases and filesystems take the opposite approach: everything that is written to a database or file is normally expected to be permanently recorded.&lt;/p&gt;
&lt;p&gt;A key feature of batch processes, is that you can run them repeatedly, since the input is read-only. This is not the case with message brokers: receiving a message is destructive if the acknowledgment causes it to be deleted from the broker, so you cannot run the same consumer again and expect to get the same result.&lt;/p&gt;
&lt;p&gt;Further, if you add a new consumer to a messaging system, it typically only starts receiving messages sent after the time it was registered. We need a hybrid solution.&lt;/p&gt;
&lt;h4 id=&quot;using-logs-for-message-storing&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#using-logs-for-message-storing&quot; aria-label=&quot;using logs for message storing permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Using logs for message storing&lt;/h4&gt;
&lt;p&gt;Combining the durable storage approach of databases with the low-latency notification facilities of messaging, we get the hybrid behind &lt;em&gt;log-based message brokers&lt;/em&gt;.
Message brokers and event logs serve as the streaming equivalent of a filesystem.&lt;/p&gt;
&lt;p&gt;Apache Kafka, Amazon Kinesis Streams, and Twitter’s DistributedLog are log-based message brokers that work like this. Even though these message brokers write all messages to disk, they are able to achieve throughput of millions of messages per second by partitioning across multiple machines, and fault tolerance by replicating messages.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/d9ed5/lb-fan-out.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 47.852760736196316%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAIAAAA7N+mxAAAACXBIWXMAAFxGAABcRgEUlENBAAABU0lEQVR42iWR6ZKDIBCEef8HzP7YbETjleDJoaLG7AdMWdTA9PR0j+I4jk8Ma+37/e6U6rpu3/fv9+uc01qT6HnmkSs5SE5jDFfRqc5YsyzLNE3ruoZXa3fvyeHd1i00a71tG+g9Bjklv23Ce092nuc8TZ/zpEb/dV1crxg0z/PMCR28qcSVRCilIGaySWcMGMdxTKRJv7POaLM4x1hKiKcqkjYXI5eyqeu2bZ9FwZcMp+Y8l2ykaRreq6piQbwLxIzDUFcVY0Pt+azrOpc5CNBQA2J+SaEIIaUsy7Lvex4FPcG993ggxx4UzKQT/8hLttum+bndZCbvv/fH34OW4BkDSTM40HrW4ccohTDocZiU8y/YDo4gfb1eS8SLtPcE4kQtr7hg+Bn/f5oMV5ZliEdCkedJqei73hgLEx6Ahr1ayyIYBVfaNjgGTGOIYRhQ5CL+H2C2OveW5e03AAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/0cbef/lb-fan-out.avif 163w,
/static/13eb5da78e0782dc1ecfe4e50774710b/bffb7/lb-fan-out.avif 325w,
/static/13eb5da78e0782dc1ecfe4e50774710b/69c29/lb-fan-out.avif 650w,
/static/13eb5da78e0782dc1ecfe4e50774710b/6d24a/lb-fan-out.avif 975w,
/static/13eb5da78e0782dc1ecfe4e50774710b/a2baf/lb-fan-out.avif 1300w,
/static/13eb5da78e0782dc1ecfe4e50774710b/a40d8/lb-fan-out.avif 2880w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/94563/lb-fan-out.webp 163w,
/static/13eb5da78e0782dc1ecfe4e50774710b/647a8/lb-fan-out.webp 325w,
/static/13eb5da78e0782dc1ecfe4e50774710b/c1dc5/lb-fan-out.webp 650w,
/static/13eb5da78e0782dc1ecfe4e50774710b/1e975/lb-fan-out.webp 975w,
/static/13eb5da78e0782dc1ecfe4e50774710b/063bf/lb-fan-out.webp 1300w,
/static/13eb5da78e0782dc1ecfe4e50774710b/d3d72/lb-fan-out.webp 2880w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/222b7/lb-fan-out.png 163w,
/static/13eb5da78e0782dc1ecfe4e50774710b/ff46a/lb-fan-out.png 325w,
/static/13eb5da78e0782dc1ecfe4e50774710b/a6d36/lb-fan-out.png 650w,
/static/13eb5da78e0782dc1ecfe4e50774710b/e548f/lb-fan-out.png 975w,
/static/13eb5da78e0782dc1ecfe4e50774710b/3c492/lb-fan-out.png 1300w,
/static/13eb5da78e0782dc1ecfe4e50774710b/d9ed5/lb-fan-out.png 2880w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/a6d36/lb-fan-out.png&quot;
            alt=&quot;Topic-partitioning. Figure 11-3.&quot;
            title=&quot;Topic partitioning&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Topic partitioning&lt;/figcaption&gt;
  &lt;/figure&gt;
Since partitioned logs typically preserve message ordering only within a single partition, all messages that need to be ordered consistently need to be routed to the same partition. For example, an application may require that the events relating to one particular user appear in a fixed order. This can be achieved by choosing the partition for an event based on the user ID of that event (in other words, making the user ID the partitioning key).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;You can keep derived data systems such as search indexes, caches, and analytics systems continually up to date by consuming the log of changes and applying them to the derived system.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;when-consumers-cannot-keep-up-with-producers&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#when-consumers-cannot-keep-up-with-producers&quot; aria-label=&quot;when consumers cannot keep up with producers permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;When consumers cannot keep up with producers&lt;/h4&gt;
&lt;p&gt;Even if a consumer does fall too far behind and starts missing messages, only that consumer is affected; it does not disrupt the service for other consumers. This fact is a big operational advantage: you can experimentally consume a production log for development, testing, or debugging purposes, without having to worry much about disrupting production services. When a consumer is shut down or crashes, it stops consuming resources—the only thing that remains is its consumer offset.&lt;/p&gt;
&lt;h4 id=&quot;search-on-streams&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#search-on-streams&quot; aria-label=&quot;search on streams permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Search on streams&lt;/h4&gt;
&lt;p&gt;Conventional search engines first index the documents and then run queries over the index. By contrast, searching a stream turns the processing on its head: the queries are stored, and the documents run past the queries. In the simplest case, you can test every document against every query, although this can get slow if you have a large number of queries. To optimize the process, it is possible to index the queries as well as the documents, and thus narrow down the set of queries that may match.&lt;/p&gt;
&lt;h4 id=&quot;event-time-versus-processing-time&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#event-time-versus-processing-time&quot; aria-label=&quot;event time versus processing time permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Event time versus processing time&lt;/h4&gt;
&lt;p&gt;Confusing event time and processing time leads to bad data. For example, say you have a stream processor that measures the rate of requests (counting the number of requests per second). If you redeploy the stream processor, it may be shut down for a minute and process the backlog of events when it comes back up. If you measure the rate based on the processing time, it will look as if there was a sudden anomalous spike of requests while processing the backlog, when in fact the real rate of requests was steady.
&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/d9ed5/lb-fan-out.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 47.852760736196316%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAIAAAA7N+mxAAAACXBIWXMAAFxGAABcRgEUlENBAAABU0lEQVR42iWR6ZKDIBCEef8HzP7YbETjleDJoaLG7AdMWdTA9PR0j+I4jk8Ma+37/e6U6rpu3/fv9+uc01qT6HnmkSs5SE5jDFfRqc5YsyzLNE3ruoZXa3fvyeHd1i00a71tG+g9Bjklv23Ce092nuc8TZ/zpEb/dV1crxg0z/PMCR28qcSVRCilIGaySWcMGMdxTKRJv7POaLM4x1hKiKcqkjYXI5eyqeu2bZ9FwZcMp+Y8l2ykaRreq6piQbwLxIzDUFcVY0Pt+azrOpc5CNBQA2J+SaEIIaUsy7Lvex4FPcG993ggxx4UzKQT/8hLttum+bndZCbvv/fH34OW4BkDSTM40HrW4ccohTDocZiU8y/YDo4gfb1eS8SLtPcE4kQtr7hg+Bn/f5oMV5ZliEdCkedJqei73hgLEx6Ahr1ayyIYBVfaNjgGTGOIYRhQ5CL+H2C2OveW5e03AAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/0cbef/lb-fan-out.avif 163w,
/static/13eb5da78e0782dc1ecfe4e50774710b/bffb7/lb-fan-out.avif 325w,
/static/13eb5da78e0782dc1ecfe4e50774710b/69c29/lb-fan-out.avif 650w,
/static/13eb5da78e0782dc1ecfe4e50774710b/6d24a/lb-fan-out.avif 975w,
/static/13eb5da78e0782dc1ecfe4e50774710b/a2baf/lb-fan-out.avif 1300w,
/static/13eb5da78e0782dc1ecfe4e50774710b/a40d8/lb-fan-out.avif 2880w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/94563/lb-fan-out.webp 163w,
/static/13eb5da78e0782dc1ecfe4e50774710b/647a8/lb-fan-out.webp 325w,
/static/13eb5da78e0782dc1ecfe4e50774710b/c1dc5/lb-fan-out.webp 650w,
/static/13eb5da78e0782dc1ecfe4e50774710b/1e975/lb-fan-out.webp 975w,
/static/13eb5da78e0782dc1ecfe4e50774710b/063bf/lb-fan-out.webp 1300w,
/static/13eb5da78e0782dc1ecfe4e50774710b/d3d72/lb-fan-out.webp 2880w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/222b7/lb-fan-out.png 163w,
/static/13eb5da78e0782dc1ecfe4e50774710b/ff46a/lb-fan-out.png 325w,
/static/13eb5da78e0782dc1ecfe4e50774710b/a6d36/lb-fan-out.png 650w,
/static/13eb5da78e0782dc1ecfe4e50774710b/e548f/lb-fan-out.png 975w,
/static/13eb5da78e0782dc1ecfe4e50774710b/3c492/lb-fan-out.png 1300w,
/static/13eb5da78e0782dc1ecfe4e50774710b/d9ed5/lb-fan-out.png 2880w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/13eb5da78e0782dc1ecfe4e50774710b/a6d36/lb-fan-out.png&quot;
            alt=&quot;Windowing by processing time introduces artifacts due to variations in processing rate.. Figure 11-7.&quot;
            title=&quot;Windowing&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Windowing&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;h4 id=&quot;whose-clock-are-you-using-anyway&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#whose-clock-are-you-using-anyway&quot; aria-label=&quot;whose clock are you using anyway permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Whose clock are you using, anyway?&lt;/h4&gt;
&lt;p&gt;The timestamp on the events should really be the time at which the user interaction occurred, according to the mobile device’s local clock. However, the clock on a user-controlled device often cannot be trusted, as it may be accidentally or deliberately set to the wrong time. The time at which the event was received by the server (according to the server’s clock) is more likely to be accurate, since the server is under your control, but less meaningful in terms of describing the user interaction.&lt;/p&gt;
&lt;p&gt;To adjust for incorrect device clocks, one approach is to log three timestamps:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The time at which the event occurred, according to the device clock&lt;/li&gt;
&lt;li&gt;The time at which the event was sent to the server, according to the device clock&lt;/li&gt;
&lt;li&gt;The time at which the event was received by the server, according to the server clock&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;By subtracting the second timestamp from the third, you can estimate the offset between the device clock and the server clock (assuming the network delay is negligible). You can then apply that offset to the event timestamp, and thus estimate the true time at which the event actually occurred.&lt;/p&gt;
&lt;h5 id=&quot;session-window&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#session-window&quot; aria-label=&quot;session window permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Session window&lt;/h5&gt;
&lt;p&gt;Unlike other window types, a session window has no fixed duration. Instead, it is defined by grouping together all events for the same user that occur closely together in time, and the window ends when the user has been inactive for some time (for example, if there have been no events for 30 minutes). &lt;em&gt;Sessionization&lt;/em&gt; is a common requirement for website analytics.&lt;/p&gt;
&lt;h3 id=&quot;stream-enrichment&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#stream-enrichment&quot; aria-label=&quot;stream enrichment permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Stream enrichment&lt;/h3&gt;
&lt;p&gt;It is natural to think of the user activity events as a stream, and to perform a join with a user-profile database on a continuous basis within a stream processor: the input is a stream of activity events containing a user ID, and the output is a stream of activity events in which the user ID has been augmented with profile information about the user.&lt;/p&gt;
&lt;p&gt;To perform this join, we can the have a local copy of the database in the stream processor be an in-memory hash table if it is small enough, or an index on the local disk. With this approach, it can be queried locally without a network round-trip.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Consider the Twitter timeline example. We don&apos;t want to iterate over all the people the user is following, find their recent tweets, and merge them to build it. Instead, we want a &lt;em&gt;timeline cache&lt;/em&gt;: a kind of per-user “inbox” to which tweets are written as they are sent, so that reading the timeline is a single lookup.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;sloooowly-changing-dimension&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sloooowly-changing-dimension&quot; aria-label=&quot;sloooowly changing dimension permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sloooowly Changing Dimension&lt;/h4&gt;
&lt;p&gt;For example, if you sell things, you need to apply the right tax rate to invoices, which depends on the country or state, the type of product, and the date of sale (since tax rates change from time to time). When joining sales to a table of tax rates, you probably want to join with the tax rate at the time of the sale, which may be different from the current tax rate if you are reprocessing historical data.&lt;/p&gt;
&lt;p&gt;If the ordering of events across streams is undetermined, the join becomes nondeterministic, which means you cannot rerun the same job on the same input and necessarily get the same result: the events on the input streams may be interleaved in a different way when you run the job again.&lt;/p&gt;
&lt;p&gt;In data warehouses, this issue is known as a &lt;em&gt;slowly changing dimension&lt;/em&gt; (SCD), and it is often addressed by using a unique identifier for a particular version of the joined record: for example, every time the tax rate changes, it is given a new identifier, and the invoice includes the identifier for the tax rate at the time of sale. This change makes the join deterministic, but has the consequence that log compaction is not possible, since all versions of the records in the table need to be retained.&lt;/p&gt;
&lt;h3 id=&quot;fault-tolerance-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#fault-tolerance-1&quot; aria-label=&quot;fault tolerance 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Fault Tolerance&lt;/h3&gt;
&lt;p&gt;The batch approach to fault tolerance ensures that, although restarting tasks means that records may in fact be processed multiple times, the visible effect in the output is as if they had only been processed once. This principle is known as &lt;em&gt;exactly-once&lt;/em&gt; semantics.&lt;/p&gt;
&lt;p&gt;The same issue arises in stream processing, but it is less straightforward to handle: waiting until a task is finished before making its output visible is not an option, because a stream is infinite and so you can never finish processing it.&lt;/p&gt;
&lt;h4 id=&quot;microbatching-and-checkpointing&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#microbatching-and-checkpointing&quot; aria-label=&quot;microbatching and checkpointing permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Microbatching and checkpointing&lt;/h4&gt;
&lt;p&gt;One solution is to break the stream into small blocks, and treat each block like a miniature batch process. This approach is called microbatching, and it is used in Spark Streaming. The batch size is typically around one second, which is the result of a performance compromise: smaller batches incur greater scheduling and coordination overhead, while larger batches mean a longer delay before results of the stream processor become visible.&lt;/p&gt;
&lt;p&gt;However, as soon as output leaves the stream processor (for example, by writing to a database, sending messages to an external message broker, or sending emails), the framework is no longer able to discard the output of a failed batch. In this case, restarting a failed task causes the external side effect to happen twice, and microbatching or checkpointing alone is not sufficient to prevent this problem.&lt;/p&gt;
&lt;h4 id=&quot;idempotence&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#idempotence&quot; aria-label=&quot;idempotence permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Idempotence&lt;/h4&gt;
&lt;p&gt;Our goal is to discard the partial output of any failed tasks so that they can be safely retried without taking effect twice.&lt;/p&gt;
&lt;p&gt;An idempotent operation is one that you can perform multiple times, and it has the same effect as if you performed it only once. For example, setting a key in a key-value store to some fixed value is idempotent (writing the value again simply overwrites the value with an identical value), whereas incrementing a counter is not idempotent (performing the increment again means the value is incremented twice).&lt;/p&gt;
&lt;p&gt;For example, when consuming messages from Kafka, every message has a persistent, monotonically increasing offset. When writing a value to an external database, you can include the offset of the message that triggered the last write with the value. Thus, you can tell whether an update has already been applied, and avoid performing the same update again.&lt;/p&gt;
&lt;h4 id=&quot;rebuilding-state-after-a-failure&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#rebuilding-state-after-a-failure&quot; aria-label=&quot;rebuilding state after a failure permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Rebuilding state after a failure&lt;/h4&gt;
&lt;p&gt;Any stream process that requires state—for example, any windowed aggregations (such as counters, averages, and histograms) and any tables and indexes used for joins—must ensure that this state can be recovered after a failure.&lt;/p&gt;
&lt;p&gt;In some systems, network delay may be lower than disk access latency, and network bandwidth may be comparable to disk bandwidth. There is no universally ideal trade-off for all situations, and the merits of local versus remote state may also shift as storage and networking technologies evolve.&lt;/p&gt;
&lt;h2 id=&quot;12-ideas-for-reliable-scalable-and-maintable-applications&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#12-ideas-for-reliable-scalable-and-maintable-applications&quot; aria-label=&quot;12 ideas for reliable scalable and maintable applications permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;12. Ideas for reliable, scalable and maintable applications&lt;/h2&gt;
&lt;h3 id=&quot;schema-migration-in-a-railway-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#schema-migration-in-a-railway-&quot; aria-label=&quot;schema migration in a railway  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Schema Migration in a... railway? 🚂&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;In the 19th century, there were multiple competing standards for the gauge of railway tracks in England, which created limitations in the train network. To convert tracks to a single standard gauge without disrupting train services for an extended period, a solution was found in the form of dual or mixed gauge tracks, where a third rail was added. This allowed for a gradual conversion as trains of both gauges could operate on the line. Once all trains were converted to the standard gauge, the nonstandard rail could be removed. This approach, although expensive, enabled the gradual change of gauge over several years. As a result, nonstandard gauges still exist today, such as in the BART system in the San Francisco Bay Area.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Just like with an extra gague, derived views offer a method of &lt;em&gt;gradually&lt;/em&gt; evolving a dataset without the need for an abrupt migration. Rather than immediately switching to a new schema, the old and new schemas can coexist as separate derived views of the same underlying data. By gradually shifting a small number of users to the new view while most users continue to use the old view, the performance and bugs of the new view can be tested. Over time, more users can be transitioned to the new view until eventually the old view can be dropped. This gradual approach allows for easy &lt;em&gt;reversibility&lt;/em&gt; at each stage, reducing the risk of irreversible damage and increasing confidence in system improvements.&lt;/p&gt;
&lt;h3 id=&quot;lambda-architecture&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#lambda-architecture&quot; aria-label=&quot;lambda architecture permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Lambda architecture&lt;/h3&gt;
&lt;p&gt;If batch processing is used to reprocess historical data, and stream processing is used to process recent updates, then how do you combine the two?&lt;/p&gt;
&lt;p&gt;With the lambda approach, the stream processor consumes the events and quickly produces an approximate update to the view; the batch processor later consumes the same set of events and produces a corrected version of the derived view. The reasoning behind this design is that batch processing is simpler and thus less prone to bugs, while stream processors are thought to be less reliable and harder to make fault-tolerant. Moreover, the stream process can use fast approximate algorithms while the batch process uses slower exact algorithms.&lt;/p&gt;
&lt;p&gt;It does have some disadvantages, like having to maintain the same logic to run both in a batch and in a stream processing framework.&lt;/p&gt;
&lt;h3 id=&quot;designing-applications-around-dataflow&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#designing-applications-around-dataflow&quot; aria-label=&quot;designing applications around dataflow permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Designing Applications Around Dataflow&lt;/h3&gt;
&lt;h4 id=&quot;unbundled-databases-unifying-writes-across-different-systems&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#unbundled-databases-unifying-writes-across-different-systems&quot; aria-label=&quot;unbundled databases unifying writes across different systems permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Unbundled databases: unifying writes across different systems&lt;/h4&gt;
&lt;p&gt;Within a single database, creating a consistent index is a built-in feature. When we compose several storage systems, we similarly need to ensure that all data changes end up in all the right places, even in the face of faults. Making it easier to reliably plug together storage systems (e.g., through change data capture and event logs) is like &lt;em&gt;unbundling&lt;/em&gt; a database’s index-maintenance features in a way that can synchronize writes across disparate technologies.&lt;/p&gt;
&lt;p&gt;Even spreadsheets have dataflow programming capabilities that are miles ahead of most mainstream programming languages. In a spreadsheet, you can put a formula in one cell (for example, the sum of cells in another column), and whenever any input to the formula changes, the result of the formula is automatically recalculated. This is exactly what we want at a data system level: when a record in a database changes, we want any index for that record to be automatically updated, and any cached views or aggregations that depend on the record to be automatically refreshed.&lt;/p&gt;
&lt;h4 id=&quot;stream-processors-and-services&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#stream-processors-and-services&quot; aria-label=&quot;stream processors and services permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Stream processors and services&lt;/h4&gt;
&lt;p&gt;Say a customer is purchasing an item that is priced in one currency but paid for in another currency. In order to perform the currency conversion, you need to know the current exchange rate. This operation could be implemented in two ways:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In the &lt;em&gt;microservices&lt;/em&gt; approach, the code that processes the purchase queries an exchange-rate service.&lt;/li&gt;
&lt;li&gt;In the &lt;em&gt;dataflow&lt;/em&gt; approach, the code that processes purchases would subscribe to a stream of exchange rate updates ahead of time, and record the current rate in a local database whenever it changes. When it comes to processing the purchase, it only needs to query the local database. Not only is the dataflow approach faster, but it is also more robust to the failure of another service. Instead of RPC, we now have a stream join between purchase events and exchange rate update events.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;The fastest and most reliable network request is &lt;em&gt;no network request at all!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The join is time-dependent: if the purchase events are reprocessed at a later point in time, the exchange rate will have changed. If you want to reconstruct the original output, you will need to obtain the historical exchange rate at the original time of purchase. No matter whether you query a service or subscribe to a stream of exchange rate updates, you will need to handle this time dependence.&lt;/p&gt;
&lt;p&gt;Expressing dataflows as transformations from one dataset to another also helps evolve applications: if you want to change one of the processing steps, for example to change the structure of an index or cache, you can just rerun the new transformation code on the whole input dataset in order to rederive the output. Similarly, if something goes wrong, you can fix the code and reprocess the data in order to recover.&lt;/p&gt;
&lt;h2 id=&quot;observing-derived-state&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#observing-derived-state&quot; aria-label=&quot;observing derived state permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Observing Derived State&lt;/h2&gt;
&lt;h3 id=&quot;pushing-state-changes-to-clients&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#pushing-state-changes-to-clients&quot; aria-label=&quot;pushing state changes to clients permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Pushing state changes to clients&lt;/h3&gt;
&lt;p&gt;Traditional web pages rely on the user manually reloading the page to see updated data from the server, resulting in stale information. However, newer protocols such as server-sent events and WebSockets allow for real-time communication between the server and the browser, enabling the server to actively push messages and updates to the client. This reduces the staleness of the client-side state and extends the write path all the way to end-user devices. While clients still need to use a read path to initially retrieve their state, they can subsequently rely on a continuous stream of state changes from the server. This concept of actively pushing state changes can be extended beyond datacenters to end-user devices.&lt;/p&gt;
&lt;p&gt;The devices will be offline some of the time, and unable to receive any notifications of state changes from the server during that time. But that problem is solved: with &lt;em&gt;consumer offsets&lt;/em&gt;, a consumer of a log-based message broker can reconnect after failing or becoming disconnected, and ensure that it doesn’t miss any messages that arrived while it was disconnected. The same technique works for individual users, where each device is a small subscriber to a small stream of events.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/a758ae4fbe91ad45491f7b0940be398d/d9ed5/write-read-path.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 38.036809815950924%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAIAAAB2/0i6AAAACXBIWXMAAFxGAABcRgEUlENBAAABAUlEQVR42n2Q23qDIBCEef93tBqjQRBB8Rw19C+0XnYu+GYPs7OLOI5j3/cQwiciRLzf75v/A7Ft2zAMsJsApZT3PiWnaUqjnbXzPMPXZVkiEdu6qUYtEeXjMY7jeZ7V8ylfLwT9H6gWRdEaA8EjTRHrujZNU+Q5srZtv7IM29453qqqrLV053kupfTDQEOWZSjRIxSMH71nKsF1XQjowJzFOmOcdciKvCDJuLquy7KE2K6jR6Tv4dsIEMOviJThYOcclxPazhKSNMbg9LP2PE1dh4fRWrN/IyUmJmLoe9a2sUpFK21aQ5X+35uTCS/j2UcrxewjgmTiyY396bn7QwjfnJLJEb9f95IAAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/a758ae4fbe91ad45491f7b0940be398d/0cbef/write-read-path.avif 163w,
/static/a758ae4fbe91ad45491f7b0940be398d/bffb7/write-read-path.avif 325w,
/static/a758ae4fbe91ad45491f7b0940be398d/69c29/write-read-path.avif 650w,
/static/a758ae4fbe91ad45491f7b0940be398d/6d24a/write-read-path.avif 975w,
/static/a758ae4fbe91ad45491f7b0940be398d/a2baf/write-read-path.avif 1300w,
/static/a758ae4fbe91ad45491f7b0940be398d/a40d8/write-read-path.avif 2880w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/a758ae4fbe91ad45491f7b0940be398d/94563/write-read-path.webp 163w,
/static/a758ae4fbe91ad45491f7b0940be398d/647a8/write-read-path.webp 325w,
/static/a758ae4fbe91ad45491f7b0940be398d/c1dc5/write-read-path.webp 650w,
/static/a758ae4fbe91ad45491f7b0940be398d/1e975/write-read-path.webp 975w,
/static/a758ae4fbe91ad45491f7b0940be398d/063bf/write-read-path.webp 1300w,
/static/a758ae4fbe91ad45491f7b0940be398d/d3d72/write-read-path.webp 2880w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/a758ae4fbe91ad45491f7b0940be398d/222b7/write-read-path.png 163w,
/static/a758ae4fbe91ad45491f7b0940be398d/ff46a/write-read-path.png 325w,
/static/a758ae4fbe91ad45491f7b0940be398d/a6d36/write-read-path.png 650w,
/static/a758ae4fbe91ad45491f7b0940be398d/e548f/write-read-path.png 975w,
/static/a758ae4fbe91ad45491f7b0940be398d/3c492/write-read-path.png 1300w,
/static/a758ae4fbe91ad45491f7b0940be398d/d9ed5/write-read-path.png 2880w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/a758ae4fbe91ad45491f7b0940be398d/a6d36/write-read-path.png&quot;
            alt=&quot;In a search index, writes (document updates) meet reads (queries).. Figure 12-1.&quot;
            title=&quot;Search Index&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Search Index&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;In order to extend the write path all the way to the end user, we would need to fundamentally rethink the way we build many of these systems: moving away from request/response interaction and toward publish/subscribe dataflow. If you are designing data systems, &lt;em&gt;keep in mind the option of subscribing to changes, not just querying the current state&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id=&quot;aiming-for-correctness&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#aiming-for-correctness&quot; aria-label=&quot;aiming for correctness permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Aiming for Correctness&lt;/h2&gt;
&lt;p&gt;If your application can tolerate occasionally corrupting or losing data in unpredictable ways, life is a lot simpler, and you might be able to get away with simply crossing your fingers and hoping for the best. On the other hand, if you need stronger assurances of correctness, then serializability and atomic commit are established approaches, but they come at a cost: they typically only work in a single datacenter (ruling out geographically distributed architectures), and they limit the scale and fault-tolerance properties you can achieve.&lt;/p&gt;
&lt;h3 id=&quot;the-end-to-end-argument-for-databases&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-end-to-end-argument-for-databases&quot; aria-label=&quot;the end to end argument for databases permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The End-to-End Argument for Databases&lt;/h3&gt;
&lt;p&gt;Just because an application uses a data system that provides comparatively strong safety properties, such as serializable transactions, that does not mean the application is guaranteed to be free from data loss or corruption. For example, if an application has a bug that causes it to write incorrect data, or delete data from a database, serializable transactions aren’t going to save you.&lt;/p&gt;
&lt;h4 id=&quot;exactly-once-execution-of-an-operation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#exactly-once-execution-of-an-operation&quot; aria-label=&quot;exactly once execution of an operation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Exactly-once execution of an operation&lt;/h4&gt;
&lt;p&gt;Processing twice is a form of data corruption: it is undesirable to charge a customer twice for the same service (billing them too much) or increment a counter twice (overstating some metric). In this context, exactly-once means arranging the computation such that the final effect is the same as if no faults had occurred, even if the operation actually was retried due to some fault.&lt;/p&gt;
&lt;p&gt;One of the most effective approaches to this is to make the operation idempotent. However, taking an operation that is not naturally idempotent and making it idempotent requires some effort and care: you may need to maintain some additional metadata (such as the set of operation IDs that have updated a value), and ensure fencing when failing over from one node to another.&lt;/p&gt;
&lt;h4 id=&quot;uniquely-identifying-requests&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#uniquely-identifying-requests&quot; aria-label=&quot;uniquely identifying requests permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Uniquely identifying requests&lt;/h4&gt;
&lt;p&gt;To make the request idempotent through several hops of network communication, it is not sufficient to rely just on a transaction mechanism provided by a database—you need to consider the end-to-end flow of the request.&lt;/p&gt;
&lt;p&gt;For example, you could generate a unique identifier for a request (such as a UUID) and include it as a hidden form field in the client application, or calculate a hash of all the relevant form fields to derive the request ID. If the web browser submits the POST request twice, the two requests will have the same request ID. You can then pass that request ID all the way through to the database and check that you only ever execute one request with a given ID. If a transaction attempts to insert an ID that already exists, an INSERT would fail and the transaction would be aborted, preventing it from taking effect twice.&lt;/p&gt;
&lt;h3 id=&quot;transaction-abstraction&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#transaction-abstraction&quot; aria-label=&quot;transaction abstraction permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Transaction Abstraction&lt;/h3&gt;
&lt;p&gt;Transactions have long been seen as a good abstraction. They take a wide range of possible issues (concurrent writes, constraint violations, crashes, network interruptions, disk failures) and collapse them down to two possible outcomes: commit or abort.&lt;/p&gt;
&lt;p&gt;When we refuse to use distributed transactions because they are too expensive, we end up having to reimplement fault-tolerance mechanisms in application code. Reasoning about concurrency and partial failure is difficult and counterintuitive, and so if you attempt this in your applications, it most probably won&apos;t work correctly. The consequence is lost or corrupted data.&lt;/p&gt;
&lt;p&gt;For these reasons, Martin is right in thinking it is worth exploring fault-tolerance abstractions that make it easy to provide application-specific end-to-end correctness properties, but also maintain good performance and good operational characteristics in a large-scale distributed environment.&lt;/p&gt;
&lt;h4 id=&quot;uniqueness-constraints-require-consensus&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#uniqueness-constraints-require-consensus&quot; aria-label=&quot;uniqueness constraints require consensus permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Uniqueness constraints require consensus&lt;/h4&gt;
&lt;p&gt;If there are several concurrent requests with the same value, the system somehow needs to decide which one of the conflicting operations is accepted, and reject the others as violations of the constraint. The most common way of achieving this consensus is to make a single node the leader, and put it in charge of making all the decisions.&lt;/p&gt;
&lt;p&gt;Uniqueness checking can be scaled out by partitioning based on the value that needs to be unique. For example, if you need to ensure uniqueness by request ID, you can ensure all requests with the same request ID are routed to the same partition.&lt;/p&gt;
&lt;p&gt;However, asynchronous multi-master replication is ruled out, because it could happen that different masters concurrently accept conflicting writes, and thus the values are no longer unique. If you want to be able to immediately reject any writes that would violate the constraint, synchronous coordination is unavoidable&lt;/p&gt;
&lt;h4 id=&quot;multi-partition-request-processing&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#multi-partition-request-processing&quot; aria-label=&quot;multi partition request processing permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Multi-partition request processing&lt;/h4&gt;
&lt;p&gt;Ensuring that an operation is executed atomically, while satisfying constraints, becomes more interesting when several partitions are involved. Imagine a payments scenario where there are potentially three partitions: the one containing the request ID, the one containing the payee account, and the one containing the payer account. There is no reason why those three things should be in the same partition, since they are all independent from each other.&lt;/p&gt;
&lt;p&gt;It turns out that equivalent correctness can be achieved with &lt;em&gt;partitioned logs, and without an atomic commit&lt;/em&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The request to transfer money from account A to account B is given a unique request ID by the client, and appended to a log partition based on the request ID.&lt;/li&gt;
&lt;li&gt;A stream processor reads the log of requests. For each request message it emits two messages to output streams: a debit instruction to the payer account A (partitioned by A), and a credit instruction to the payee account B (partitioned by B). The original request ID is included in those emitted messages.&lt;/li&gt;
&lt;li&gt;Further processors consume the streams of credit and debit instructions, deduplicate by request ID, and apply the changes to the account balances.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Steps 1 and 2 are necessary because if the client directly sent the credit and debit instructions, it would require an atomic commit across those two partitions to ensure that either both or neither happen. To avoid the need for a distributed transaction, we first durably log the request as a single message, and then derive the credit and debit instructions from that first message. The request either appears in the log or it doesn’t, without any need for a multi-partition atomic commit.&lt;/p&gt;
&lt;h3 id=&quot;timeliness-and-integrity&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#timeliness-and-integrity&quot; aria-label=&quot;timeliness and integrity permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Timeliness and Integrity&lt;/h3&gt;
&lt;p&gt;The term &lt;em&gt;consistency&lt;/em&gt; conflates two different requirements that are worth considering separately:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Timeliness
Timeliness means ensuring that users observe the system in an up-to-date state. We saw previously that if a user reads from a stale copy of the data, they may observe it in an inconsistent state. However, that inconsistency is temporary, and will eventually be resolved simply by waiting and trying again.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The CAP theorem uses consistency in the sense of linearizability (a writer waits until a transaction is committed, and thereafter its writes are immediately visible to all readers), which is a strong way of achieving timeliness. Weaker timeliness properties like read-after-write consistency can also be useful.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Integrity
Integrity means absence of corruption; i.e., no data loss, and no contradictory or false data. In particular, if some derived dataset is maintained as a view onto some underlying data, the derivation must be correct. For example, a database index must correctly reflect the contents of the database—an index in which some records are missing is not very useful.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;On your credit card statement, it is not surprising if a transaction that you made within the last 24 hours does not yet appear—it is normal that these systems have a certain lag. We know that banks reconcile and settle transactions asynchronously, and timeliness is not very important here. However, it would be very bad if the statement balance was not equal to the sum of the transactions plus the previous statement balance (an error in the sums), or if a transaction was charged to you but not paid to the merchant (disappearing money). Such problems would be violations of the integrity of the system.&lt;/p&gt;
&lt;h3 id=&quot;loosely-interpreted-constraints&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#loosely-interpreted-constraints&quot; aria-label=&quot;loosely interpreted constraints permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Loosely interpreted constraints&lt;/h3&gt;
&lt;p&gt;As discussed previously, enforcing a uniqueness constraint requires consensus, typically implemented by funneling all events in a particular partition through a single node. This limitation is unavoidable if we want the traditional form of uniqueness constraint, and stream processing cannot avoid it.&lt;/p&gt;
&lt;p&gt;However, another thing to realize is that many real applications can actually get away with much weaker notions of uniqueness:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Many airlines overbook airplanes in the expectation that some passengers will miss their flight, and many hotels overbook rooms, expecting that some guests will cancel. In these cases, the constraint of “one person per seat” is deliberately violated for business reasons, and compensation processes (refunds, upgrades, providing a complimentary room at a neighboring hotel) are put in place to handle situations in which demand exceeds supply. Even if there was no overbooking, apology and compensation processes would be needed in order to deal with flights being cancelled due to bad weather or staff on strike—recovering from such issues is just a normal part of business.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;These applications do require integrity: you would not want to lose a reservation, or have money disappear due to mismatched credits and debits. But they don’t require timeliness on the enforcement of the constraint: if you have sold more items than you have in the warehouse, you can patch up the problem after the fact by apologizing.&lt;/p&gt;
&lt;h4 id=&quot;how-many-apologies&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-many-apologies&quot; aria-label=&quot;how many apologies permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How many apologies?&lt;/h4&gt;
&lt;p&gt;Although strict uniqueness constraints require timeliness and coordination, many applications are actually fine with loose constraints that may be temporarily violated and fixed up later, as long as integrity is preserved throughout. In other words, they reduce the number of apologies you have to make due to inconsistencies, but potentially also reduce the performance and availability of your system, and thus potentially increase the number of apologies you have to make due to outages. You cannot reduce the number of apologies to zero, but you can aim to find the &lt;em&gt;best trade-off&lt;/em&gt; for your needs—the sweet spot where there are neither too many inconsistencies nor too many availability problems.&lt;/p&gt;
&lt;p&gt;This approach is much more scalable and robust than the traditional approach of using distributed transactions, and fits with how many business processes work in practice.&lt;/p&gt;
&lt;h4 id=&quot;but-hardware-never-fails&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#but-hardware-never-fails&quot; aria-label=&quot;but hardware never fails permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&quot;But hardware never fails!&quot;&lt;/h4&gt;
&lt;p&gt;It seems unlikely, but if you have enough devices running your software, even very unlikely things do happen. Besides random memory corruption due to hardware faults or radiation, certain pathological memory access patterns can flip bits even in memory that has no faults —an effect that can be used to break security mechanisms in operating systems (this technique is known as rowhammer). Once you look closely, hardware isn’t quite the perfect abstraction that it may seem.&lt;/p&gt;
&lt;p&gt;HDFS and Amazon S3 do not fully trust disks: they run background processes that continually read back files, compare them to other replicas, and move files from one disk to another, in order to mitigate the risk of silent corruption.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;It is important to try restoring from your backups from time to time—otherwise you may only find out that your backup is broken when it is too late and you have already lost data. Don’t just blindly trust that it is all working.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;designing-for-auditability&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#designing-for-auditability&quot; aria-label=&quot;designing for auditability permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Designing for Auditability&lt;/h3&gt;
&lt;p&gt;Today, weaker consistency guarantees became the norm under the banner of NoSQL, and less mature storage technologies became widely used. Yet, because the audit mechanisms had not been developed, we continued building applications on the basis of blind trust, even though this approach had now become more dangerous.&lt;/p&gt;
&lt;p&gt;For example, for an event log, we can use hashes to check that the event storage has not been corrupted. For any derived state, we can rerun the batch and stream processors that derived it from the event log in order to check whether we get the same result, or even run a redundant derivation in parallel.&lt;/p&gt;
&lt;p&gt;A deterministic and well-defined dataflow also makes it easier to debug and trace the execution of a system in order to determine why it did something. If something unexpected occurred, it is valuable to have the diagnostic capability to reproduce the exact circumstances that led to the unexpected event—a kind of time-travel debugging capability.&lt;/p&gt;
&lt;h2 id=&quot;do-the-right-thing&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#do-the-right-thing&quot; aria-label=&quot;do the right thing permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Do the Right Thing&lt;/h2&gt;
&lt;p&gt;Kleppmann is accurate in writing that a technology is not good or bad in itself—what matters is how it is used and &lt;em&gt;how it affects people&lt;/em&gt;. I think it is not sufficient for software engineers to focus exclusively on the technology and ignore its consequences: the ethical responsibility is ours to bear also. Think about this as you get closer to users&apos; personal data.&lt;/p&gt;
&lt;p&gt;On a personal note, I have always looked contemptuously at recruiters pushing me towards positions for &quot;the next big thing&quot;, which mostly ended up masquerading as an online casino app, a dodgy mental health app, or scammy crypto platforms. Chosing the companies one works for (or even applies to) is also an act that cannot escape from this responsability.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Reasoning about ethics is difficult, but it is too important to ignore.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;not-so-data-driven&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#not-so-data-driven&quot; aria-label=&quot;not so data driven permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Not-so-data-driven&lt;/h3&gt;
&lt;p&gt;A blind belief in the supremacy of data for making decisions is not only delusional, it is positively dangerous. As data-driven decision making becomes more widespread, we will need to figure out how to make algorithms accountable and transparent, how to avoid reinforcing existing biases, and how to fix them when they inevitably make mistakes.&lt;/p&gt;
&lt;h3 id=&quot;privacy&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#privacy&quot; aria-label=&quot;privacy permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Privacy&lt;/h3&gt;
&lt;p&gt;If the service is funded through advertising, the advertisers are the actual customers, and the users’ interests take second place. Tracking data becomes more detailed, analyses become further-reaching, and data is retained for a long time in order to build up detailed profiles of each person for marketing purposes.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;As a thought experiment, try replacing the word data with surveillance, and observe if common phrases still sound so good. How about this: “In our surveillance-driven organization we collect real-time surveillance streams and store them in our surveillance warehouse. Our surveillance scientists use advanced analytics and surveillance processing in order to derive new insights.”&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;When sharing medical data, there are clear risks to privacy, but there are also potential opportunities: how many deaths could be prevented if data analysis was able to help us achieve better diagnostics or find better treatments? Over-regulation may prevent such breakthroughs. It is difficult to balance such potential opportunities with the risks.&lt;/p&gt;
&lt;h2 id=&quot;the-end&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-end&quot; aria-label=&quot;the end permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The End&lt;/h2&gt;
&lt;p&gt;If you have reached this far, thank you! The purpose of these blog posts is to, through Kleppmann&apos;s magnificent book and ideas, spark different thoughts that you may have not encountered yet as a software engineer. Let&apos;s work together to build better services and products, and ultimately to leave the world a better place than we found it.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Insights in 'Designing Data-Intensive Applications' - Part 2/3]]></title><description><![CDATA[A post to share key insights after reading Martin Kleppmann's essential book. Part 2/3]]></description><link>https://www.j1nma.com/designing-data-intensive-applications-part-2/</link><guid isPermaLink="false">https://www.j1nma.com/designing-data-intensive-applications-part-2/</guid><pubDate>Sat, 09 Dec 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Welcome to my blog on the book &quot;Designing Data Intensive Applications&quot; by Martin Kleppmann. In this post, I will share with you key principles, trade-offs, and technologies that I found as the most interesting for building robust and scalable data systems.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Most of these notes are as they appear in the original book, or tailored by me, but all ideas are a creation of Martin or authors Martin quotes in his book.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This is Part 2. Check Part 1, &lt;em&gt;Foundations of Data Systems&lt;/em&gt;, &lt;a href=&quot;https://www.j1nma.com/designing-data-intensive-applications&quot;&gt;here&lt;/a&gt;, and Part 3, &lt;em&gt;Derived Data&lt;/em&gt;, &lt;a href=&quot;https://www.j1nma.com/designing-data-intensive-applications-part-3&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;!-- TOC --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#distributed-data&quot;&gt;Distributed Data&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#intro&quot;&gt;Intro&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#why-should-i-distribute&quot;&gt;Why should I distribute?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#scaling-to-higher-load&quot;&gt;Scaling to Higher Load&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#replication&quot;&gt;Replication&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#different-from-partitioning&quot;&gt;Different from Partitioning&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#following-the-leader&quot;&gt;Following the leader&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#how-many-leaders-yes&quot;&gt;How many leaders? Yes…&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#we-lost-the-leader-failover&quot;&gt;We lost the Leader: Failover&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#problems-with-replication&quot;&gt;Problems with Replication&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#partitioning&quot;&gt;Partitioning&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#approaches&quot;&gt;Approaches&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#secondary-indexes&quot;&gt;Secondary indexes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#rebalancing&quot;&gt;Rebalancing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#routing-queries-to-the-appropriate-partition&quot;&gt;Routing queries to the appropriate partition&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#transactions&quot;&gt;Transactions&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#isolation-levels-and-famous-race-conditions&quot;&gt;Isolation Levels and Famous Race Conditions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#serializable-isolation&quot;&gt;Serializable isolation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#the-trouble-with-distributed-systems&quot;&gt;The Trouble with Distributed Systems&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#nondeterminism-and-partial-failures&quot;&gt;Nondeterminism and Partial Failures&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#detecting-faults&quot;&gt;Detecting faults&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#cost-trade-off&quot;&gt;Cost Trade-Off&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#knowledge-truth-and-lies&quot;&gt;Knowledge, Truth and Lies&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#byzantine-faults&quot;&gt;Byzantine Faults&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#consistency-and-consensus&quot;&gt;Consistency and Consensus&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#consensus&quot;&gt;Consensus&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#consistency-guarantees&quot;&gt;Consistency guarantees&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#causality&quot;&gt;Causality&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#kicking-the-can-down-the-road-&quot;&gt;Kicking the can down the road 🥫&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- /TOC --&gt;
&lt;h1 id=&quot;distributed-data&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#distributed-data&quot; aria-label=&quot;distributed data permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Distributed Data&lt;/h1&gt;
&lt;p&gt;In the first part, we visited aspects of data systems that apply when data is stored on a single machine. For this second part, we move up a level and ask: what happens if multiple machines are involved in storage and retrieval of data?&lt;/p&gt;
&lt;h2 id=&quot;intro&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#intro&quot; aria-label=&quot;intro permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Intro&lt;/h2&gt;
&lt;h3 id=&quot;why-should-i-distribute&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#why-should-i-distribute&quot; aria-label=&quot;why should i distribute permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Why should I distribute?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt;
If your data volume, read load, or write load grows bigger than a single machine can handle, you could spread the load across multiple machines.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Fault tolerance/High Availability&lt;/strong&gt;
If your application needs to continue working even if one machine (or several machines, or the network, or an entire datacenter) goes down, you can use multiple machines to give you redundancy.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Latency&lt;/strong&gt;
If you have users around the world, you might want to have servers at various locations worldwide so that each user can be served from a datacenter that is geographically close to them (think about Netflix).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;scaling-to-higher-load&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#scaling-to-higher-load&quot; aria-label=&quot;scaling to higher load permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Scaling to Higher Load&lt;/h3&gt;
&lt;p&gt;If all you need is to scale to higher load, the simplest approach is to buy a more powerful machine (vertical scaling or scaling up). The problem with a shared-memory approach is that the cost grows faster than linearly.&lt;/p&gt;
&lt;h4 id=&quot;shared-nothing-architectures&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#shared-nothing-architectures&quot; aria-label=&quot;shared nothing architectures permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Shared-Nothing Architectures&lt;/h4&gt;
&lt;p&gt;Also called &lt;strong&gt;horizontal scaling&lt;/strong&gt; or &lt;strong&gt;scaling out&lt;/strong&gt;, this approach makes each node use its CPUs, RAM, and disks independently. Any coordination done at the software level, using a conventional network.&lt;/p&gt;
&lt;p&gt;No special hardware is required, so you can use whatever machines have the best price/performance ratio. You can potentially distribute data across multiple geographic regions, and thus reduce latency for users and potentially be able to survive the loss of an entire datacenter.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Shared-nothing architecture also implies additional complexity for applications and sometimes limits the expressiveness of the data models you can use.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;5-replication&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#5-replication&quot; aria-label=&quot;5 replication permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;5. Replication&lt;/h2&gt;
&lt;p&gt;It offers:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;high availability: keeping the system running if one machines goes down&lt;/li&gt;
&lt;li&gt;allowing an application to continue working when there is a network interruption&lt;/li&gt;
&lt;li&gt;latency: placing data geographically close to users, for faster interaction&lt;/li&gt;
&lt;li&gt;scalability: performing reads on replicas&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;different-from-partitioning&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#different-from-partitioning&quot; aria-label=&quot;different from partitioning permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Different from Partitioning&lt;/h3&gt;
&lt;p&gt;Partitioning means splitting a big database into smaller subsets called partitions so that different partitions can be assigned to different nodes (also known as &lt;strong&gt;sharding&lt;/strong&gt;).&lt;/p&gt;
&lt;h3 id=&quot;following-the-leader&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#following-the-leader&quot; aria-label=&quot;following the leader permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Following the leader&lt;/h3&gt;
&lt;p&gt;Every write to the database needs to be processed by every replica; otherwise, the replicas would no longer contain the same data. The most common solution for this is called &lt;strong&gt;leader-based replication&lt;/strong&gt; (also known as active/passive or master–slave). Whenever the leader writes new data to its local storage, it also sends the data change to all of its followers as part of a replication log or change stream. Each follower takes the log from the leader and updates its local copy of the database accordingly, by applying all writes in the same order as they were processed on the leader.&lt;/p&gt;
&lt;h3 id=&quot;how-many-leaders-yes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-many-leaders-yes&quot; aria-label=&quot;how many leaders yes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How many leaders? Yes…&lt;/h3&gt;
&lt;p&gt;There are three main approaches:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Single-leader replication&lt;/strong&gt;
Clients send all writes to a single node (the leader), which sends a stream of data change events to the other replicas (followers). Reads can be performed on any replica, but reads from followers might be stale. No conflicts! Great for read-heavy workloads. Only makes sense with asynchronous replication, which in turn translates into temporal outdated data (&lt;strong&gt;eventual consistency&lt;/strong&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Multi-leader replication&lt;/strong&gt;
Clients send each write to one of several leader nodes, any of which can accept writes. The leaders send streams of data change events to each other and to any follower nodes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Leaderless replication&lt;/strong&gt;
Clients send each write to several nodes, and read from several nodes in parallel in order to detect and correct nodes with stale data. The client may get different responses from different nodes. Version numbers are used to determine which value is newer.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;Multi-leader and leaderless replication can be more robust in the presence of faulty nodes, network interruptions, and latency spikes—at the cost of being harder to reason about (concurrency allows for conflicts) and providing only very weak consistency guarantees. If you want synchronous conflict detection, you might as well just use single-leader replication.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;sync-or-async-semi&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sync-or-async-semi&quot; aria-label=&quot;sync or async semi permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sync or Async? Semi!&lt;/h4&gt;
&lt;p&gt;If a synchronous follower becomes unavailable or slow, one of the asynchronous followers is made synchronous. This guarantees that you have an up-to-date copy of the data on at least two nodes: the leader and one synchronous follower. This configuration is sometimes also called semi-synchronous.&lt;/p&gt;
&lt;p&gt;Although asynchronous replication can be fast when the system is running smoothly, it’s important to figure out what happens when replication lag increases and servers fail. If a leader fails and you promote an asynchronously updated follower to be the new leader, recently committed data may be lost.&lt;/p&gt;
&lt;h4 id=&quot;durability-vs-write-throughput&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#durability-vs-write-throughput&quot; aria-label=&quot;durability vs write throughput permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Durability vs Write Throughput&lt;/h4&gt;
&lt;p&gt;If the leader fails and is not recoverable, any writes that have not yet been replicated to followers are lost. This means that a write is not guaranteed to be durable, even if it has been confirmed to the client. However, a fully asynchronous configuration has the advantage that the leader can continue processing writes, even if all of its followers have fallen behind.&lt;/p&gt;
&lt;p&gt;Weakening durability may sound like a bad trade-off, but asynchronous replication is nevertheless widely used, especially if there are many followers or if they are geographically distributed.&lt;/p&gt;
&lt;h3 id=&quot;we-lost-the-leader-failover&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#we-lost-the-leader-failover&quot; aria-label=&quot;we lost the leader failover permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;We lost the Leader: Failover&lt;/h3&gt;
&lt;p&gt;Handling a failure of the leader is trickier: one of the followers needs to be promoted to be the new leader, clients need to be reconfigured to send their writes to the new leader, and the other followers need to start consuming data changes from the new leader.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Discarding writes is especially dangerous if other storage systems outside of the database need to be coordinated with the database contents. For example, in one incident at GitHub, an out-of-date MySQL follower was promoted to leader. The database used an auto-incrementing counter to assign primary keys to new rows, but because the new leader’s counter lagged behind the old leader’s, it reused some primary keys that were previously assigned by the old leader. These primary keys were also used in a Redis store, so the reuse of primary keys resulted in inconsistency between MySQL and Redis, which caused some private data to be disclosed to the wrong users.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;problems-with-replication&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#problems-with-replication&quot; aria-label=&quot;problems with replication permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Problems with Replication&lt;/h3&gt;
&lt;p&gt;In the move to distributed (replicated and partitioned) databases, many systems have abandoned transactions, claiming that they are too expensive in terms of performance and availability, and asserting that eventual consistency is inevitable in a scalable system.&lt;/p&gt;
&lt;p&gt;A few consistency models helpful for deciding how an application should behave under replication lag:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Read-after-write consistency: &lt;strong&gt;read your own writes&lt;/strong&gt;
Users should always see data that they submitted themselves. Always read the user’s own profile from the leader, and any other users’ profiles from a follower. Monitor the replication lag on followers and prevent queries on any follower that is more than one minute behind the leader.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Monotonic reads
Make sure that each user always makes their reads from the same replica. For example, the replica can be chosen based on a hash of the user ID. However, if that replica fails, the user’s queries will need to be rerouted to another replica.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Consistent prefix reads
Users should see the data in a state that makes causal sense: for example, seeing a question and its reply in the correct order. One solution is to make sure that any writes that are causally related to each other are written to the same partition—but in some applications that cannot be done efficiently.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;happens-before&lt;/strong&gt; relationship: whenever you have two operations A and B, there are three possibilities: either A happened before B, or B happened before A, or A and B are concurrent.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;amazin-conflict&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#amazin-conflict&quot; aria-label=&quot;amazin conflict permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Amazin&apos; conflict&lt;/h4&gt;
&lt;blockquote&gt;
&lt;p&gt;For some time, the conflict resolution logic on the Amazon shopping cart would preserve items added to the cart, but not items removed from the cart. Thus, customers would sometimes see items reappearing in their carts even though they had previously been removed.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;6-partitioning&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#6-partitioning&quot; aria-label=&quot;6 partitioning permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;6. Partitioning&lt;/h2&gt;
&lt;p&gt;When you have so much data that storing and processing it on a single machine is no longer feasible, you can partition it to spread the data and query load evenly across multiple machines, avoiding hot nodes (scalability).&lt;/p&gt;
&lt;h3 id=&quot;approaches&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#approaches&quot; aria-label=&quot;approaches permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Approaches&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Key range partitioning&lt;/strong&gt;, where sorting keys has the advantage that efficient range queries are possible. Partitions are typically rebalanced dynamically by splitting the range into two subranges when a partition gets too big (against hot ranges)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hash partitioning&lt;/strong&gt;, where a hash function is applied to each key, and a partition owns a range of hashes. Range queries become inefficient, but may distribute load more evenly.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Hybrid&lt;/strong&gt;, with a compound key: using one part of the key to identify the partition and another part for the sort order.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&quot;consistent-hashing&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#consistent-hashing&quot; aria-label=&quot;consistent hashing permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Consistent Hashing&lt;/h4&gt;
&lt;p&gt;It is a way of evenly distributing load across an internet-wide system of caches such as a CDN. It uses randomly chosen partition boundaries to avoid the need for central control or distributed consensus. Note that consistent here has nothing to do with replica consistency or ACID consistency, but rather describes a particular approach to rebalancing.&lt;/p&gt;
&lt;p&gt;This particular approach actually doesn’t work very well for databases, so it is rarely used in practice. Because this is so confusing, it’s best to avoid the term consistent hashing and just call it hash partitioning instead.&lt;/p&gt;
&lt;h3 id=&quot;secondary-indexes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#secondary-indexes&quot; aria-label=&quot;secondary indexes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Secondary indexes&lt;/h3&gt;
&lt;p&gt;A secondary index can be partitioned in two ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Document-partitioned (&lt;strong&gt;local&lt;/strong&gt;), where the secondary indexes are stored in the same partition as the primary key and value. This means that only a single partition needs to be updated on write, but a read of the secondary index requires a scatter/gather across all partitions.&lt;/li&gt;
&lt;li&gt;Term-partitioned (&lt;strong&gt;global&lt;/strong&gt;), where the secondary indexes are partitioned separately, using the indexed values. An entry in the secondary index may include records from all partitions of the primary key. When a document is written, several partitions of the secondary index need to be updated; however, a read can be served from a single partition.&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Amazon DynamoDB states that its global secondary indexes are updated (asynchronously) within a fraction of a second in normal circumstances.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;rebalancing&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#rebalancing&quot; aria-label=&quot;rebalancing permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Rebalancing&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Data storage, read and write requests (the “load”) should be shared fairly between nodes.&lt;/li&gt;
&lt;li&gt;While rebalancing is happening, the database should continue accepting reads and writes.&lt;/li&gt;
&lt;li&gt;No more data than necessary should be moved between nodes.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&quot;how-not-to-do-it-hash-mod-n&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-not-to-do-it-hash-mod-n&quot; aria-label=&quot;how not to do it hash mod n permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How not to do it: hash mod N&lt;/h4&gt;
&lt;p&gt;If the number of nodes N changes, most of the keys will need to be moved from one node to another. For example, say hash(key) = 123456. If you initially have 10 nodes, that key starts out on node 6 (because 123456 mod 10 = 6). When you grow to 11 nodes, the key needs to move to node 3 (123456 mod 11 = 3), and when you grow to 12 nodes, it needs to move to node 0 (123456 mod 12 = 0). Such frequent moves make rebalancing excessively expensive.&lt;/p&gt;
&lt;p&gt;A better way is to do dynamic partitioning. If there is only a small amount of data, a small number of partitions is sufficient, so overheads are small; if there is a huge amount of data, the size of each individual partition is limited to a configurable maximum.&lt;/p&gt;
&lt;h3 id=&quot;routing-queries-to-the-appropriate-partition&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#routing-queries-to-the-appropriate-partition&quot; aria-label=&quot;routing queries to the appropriate partition permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Routing queries to the appropriate partition&lt;/h3&gt;
&lt;p&gt;How does the component making the routing decision (which may be one of the nodes, the routing tier, or the client) learn about changes in the assignment of partitions to nodes? This is a challenging problem, because it is important that all participants agree—otherwise requests would be sent to the wrong nodes and not handled correctly. Many distributed data systems rely on a separate coordination service such as &lt;em&gt;ZooKeeper&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/8fc2904f034759e5e5b110f0079ec806/218a4/zookeeper.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 50.920245398773%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAABYlAAAWJQFJUiTwAAABkElEQVR42k2S246CQAyGef+n8NZn8VLFlU1clJPIWRBR1G6/RoxNJtOZnv7+rfN4POR+v0sURZJnmTyfT/kW7GmaShzFsvf3cr1eP7bT6SS73c7ij8ej5HkuTns+S1EUFtS1nbxeL3MehkFO+odTFIYSHA5WNDgEcrlczCfU/5/NxopGYSSZAnJIEMexrJYrWS6XEgSBoSRoNpvJYrGQqqrMp65rKbTA8EZJMZLiDyjsDoau6ywo0SDaHsdRQD6fz8V1XfvzPE9SbetXb1pFQO2u1+YfKhBDeLvdjBfuvu+tKglACPoRfpLEEJKoaRrTsZdlaQhpGb0BIcZMHTm0Q0K4m4Tq+GwUKXT86RB488/bXbsyasIPQhK0bWuVaRu90mrfCRNFCEegoG26QUr9Y1D4EGsc4oQynaZu7J6mjTNB3nZrq+P7vlGD7FVfr1b2ZqWgxKF/DoGTzpmExL3yVSuCm64SA5wQwuNZh8eUScosHPaK5QSpcak8xIqoyAtbVv4YCnboSd+7aTb1ZRDf8g+i9vYu2dKjUQAAAABJRU5ErkJggg==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/8fc2904f034759e5e5b110f0079ec806/0cbef/zookeeper.avif 163w,
/static/8fc2904f034759e5e5b110f0079ec806/bffb7/zookeeper.avif 325w,
/static/8fc2904f034759e5e5b110f0079ec806/69c29/zookeeper.avif 650w,
/static/8fc2904f034759e5e5b110f0079ec806/6d24a/zookeeper.avif 975w,
/static/8fc2904f034759e5e5b110f0079ec806/2bd13/zookeeper.avif 1052w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/8fc2904f034759e5e5b110f0079ec806/94563/zookeeper.webp 163w,
/static/8fc2904f034759e5e5b110f0079ec806/647a8/zookeeper.webp 325w,
/static/8fc2904f034759e5e5b110f0079ec806/c1dc5/zookeeper.webp 650w,
/static/8fc2904f034759e5e5b110f0079ec806/1e975/zookeeper.webp 975w,
/static/8fc2904f034759e5e5b110f0079ec806/c18de/zookeeper.webp 1052w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/8fc2904f034759e5e5b110f0079ec806/222b7/zookeeper.png 163w,
/static/8fc2904f034759e5e5b110f0079ec806/ff46a/zookeeper.png 325w,
/static/8fc2904f034759e5e5b110f0079ec806/a6d36/zookeeper.png 650w,
/static/8fc2904f034759e5e5b110f0079ec806/e548f/zookeeper.png 975w,
/static/8fc2904f034759e5e5b110f0079ec806/218a4/zookeeper.png 1052w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/8fc2904f034759e5e5b110f0079ec806/a6d36/zookeeper.png&quot;
            alt=&quot;Zookeeper example. Figure 6-8&quot;
            title=&quot;Using ZooKeeper to keep track of assignment of partitions to nodes.&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Using ZooKeeper to keep track of assignment of partitions to nodes.&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;h2 id=&quot;7-transactions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#7-transactions&quot; aria-label=&quot;7 transactions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;7. Transactions&lt;/h2&gt;
&lt;p&gt;Transactions are an abstraction layer that allows an application to pretend that certain concurrency problems and certain kinds of hardware and software faults don’t exist.&lt;/p&gt;
&lt;p&gt;Conceptually, all the reads and writes in a transaction are executed as one operation: either the entire transaction succeeds (commit) or it fails (abort, rollback). If it fails, the application can safely retry.&lt;/p&gt;
&lt;p&gt;Not every application needs transactions, and sometimes there are advantages to weakening transactional guarantees or abandoning them entirely (for example, to achieve higher performance or higher availability).&lt;/p&gt;
&lt;p&gt;For complex access patterns, transactions can hugely reduce the number of potential error cases you need to think about. Without transactions, various error scenarios (processes crashing, network interruptions, power outages, disk full, unexpected concurrency, etc.) mean that data can become &lt;em&gt;inconsistent&lt;/em&gt; in various ways.&lt;/p&gt;
&lt;h3 id=&quot;isolation-levels-and-famous-race-conditions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#isolation-levels-and-famous-race-conditions&quot; aria-label=&quot;isolation levels and famous race conditions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Isolation Levels and Famous Race Conditions&lt;/h3&gt;
&lt;h4 id=&quot;read-committed&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#read-committed&quot; aria-label=&quot;read committed permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Read Committed&lt;/h4&gt;
&lt;p&gt;The most basic level of transaction isolation. It makes two guarantees:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;When reading from the database, you will only see data that has been committed (no dirty reads).&lt;/li&gt;
&lt;li&gt;When writing to the database, you will only overwrite data that has been committed (no dirty writes).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Dirty reads&lt;/strong&gt;
One client reads another client’s writes before they have been committed.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/3aade7b8f95b37953b229028b2d56564/669eb/nodirtyreads.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 28.22085889570552%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAABYlAAAWJQFJUiTwAAAA20lEQVR42j2R2w6EIAxE+f8/3H1cYxQCKl5Q8NLd04Rt0oidcWaoJucspRQ5jkOo53lk33eJMer8ui6Bw/u2bYovyyLeez3T1LquMk2TmHmeVQyRCsY4iXNWxbquk7ZtxVqrgvDe75fOquB932oKZlJKSuRJASBEAlKN4/gjJiVjQjr4PJ1zcp6n8qu4CSEoiBCDvu81OkKYgJGO1Bhwm3oTuNUYYdpAoBHkY1ZAIYIZwlyJhE3zUTESYTYMg3IJwAoogzrkUrICdN0pGAk4M2Px9QwvBP/ngvETv+rXz+Fnm7jfAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/3aade7b8f95b37953b229028b2d56564/0cbef/nodirtyreads.avif 163w,
/static/3aade7b8f95b37953b229028b2d56564/bffb7/nodirtyreads.avif 325w,
/static/3aade7b8f95b37953b229028b2d56564/69c29/nodirtyreads.avif 650w,
/static/3aade7b8f95b37953b229028b2d56564/6d24a/nodirtyreads.avif 975w,
/static/3aade7b8f95b37953b229028b2d56564/2b301/nodirtyreads.avif 1244w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/3aade7b8f95b37953b229028b2d56564/94563/nodirtyreads.webp 163w,
/static/3aade7b8f95b37953b229028b2d56564/647a8/nodirtyreads.webp 325w,
/static/3aade7b8f95b37953b229028b2d56564/c1dc5/nodirtyreads.webp 650w,
/static/3aade7b8f95b37953b229028b2d56564/1e975/nodirtyreads.webp 975w,
/static/3aade7b8f95b37953b229028b2d56564/428d4/nodirtyreads.webp 1244w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/3aade7b8f95b37953b229028b2d56564/222b7/nodirtyreads.png 163w,
/static/3aade7b8f95b37953b229028b2d56564/ff46a/nodirtyreads.png 325w,
/static/3aade7b8f95b37953b229028b2d56564/a6d36/nodirtyreads.png 650w,
/static/3aade7b8f95b37953b229028b2d56564/e548f/nodirtyreads.png 975w,
/static/3aade7b8f95b37953b229028b2d56564/669eb/nodirtyreads.png 1244w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/3aade7b8f95b37953b229028b2d56564/a6d36/nodirtyreads.png&quot;
            alt=&quot;No dirty reads. Figure 7-4&quot;
            title=&quot;No dirty reads.&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;No dirty reads.&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Dirty writes&lt;/strong&gt;
One client overwrites data that another client has written, but not yet committed.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/86d481282933620fbb6135be316d2a7f/f09ab/dirtywrites.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 44.78527607361963%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAABYlAAAWJQFJUiTwAAABOUlEQVR42m2SiY6DMAxE8/+/uOzSlh4UCgXC3cPLGxRUrTbSEDCeGduJm6bJWO/3W/vlcrEoiux8Pm+xz0V+FH1ZHMd2u922nOfzKbhpmq1pGqvrWsmn02nB0a7Xq8C/ruuEvu/tfr/bfr+3JEnseEyU37at+MAhgss4jnLw3ovIO1W+Xq/NnfdhGBYBr6rILctSgo/HQzHnfbsEC2EYepGorKoqy/NcJAyJA4j8I0ZFmAPvm2XvzOE4z7OFPcyTiiEC2v2cc11Xqor26RDBwHdhfkVRbNWEdsZxkDD/WVS85q/VYxRMyeFbM0QZIi0hCHCnPWYHeT2QUt+MJJjDDSDf8QhOBEMSp7jbxRLL80wHdDgctKfpegOyLJMInI9rM9l/K03TRXCne8liZj8/37oyCIVT/3tXfwGQgrdGQf/31AAAAABJRU5ErkJggg==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/86d481282933620fbb6135be316d2a7f/0cbef/dirtywrites.avif 163w,
/static/86d481282933620fbb6135be316d2a7f/bffb7/dirtywrites.avif 325w,
/static/86d481282933620fbb6135be316d2a7f/69c29/dirtywrites.avif 650w,
/static/86d481282933620fbb6135be316d2a7f/6d24a/dirtywrites.avif 975w,
/static/86d481282933620fbb6135be316d2a7f/09946/dirtywrites.avif 1250w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/86d481282933620fbb6135be316d2a7f/94563/dirtywrites.webp 163w,
/static/86d481282933620fbb6135be316d2a7f/647a8/dirtywrites.webp 325w,
/static/86d481282933620fbb6135be316d2a7f/c1dc5/dirtywrites.webp 650w,
/static/86d481282933620fbb6135be316d2a7f/1e975/dirtywrites.webp 975w,
/static/86d481282933620fbb6135be316d2a7f/e19c7/dirtywrites.webp 1250w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/86d481282933620fbb6135be316d2a7f/222b7/dirtywrites.png 163w,
/static/86d481282933620fbb6135be316d2a7f/ff46a/dirtywrites.png 325w,
/static/86d481282933620fbb6135be316d2a7f/a6d36/dirtywrites.png 650w,
/static/86d481282933620fbb6135be316d2a7f/e548f/dirtywrites.png 975w,
/static/86d481282933620fbb6135be316d2a7f/f09ab/dirtywrites.png 1250w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/86d481282933620fbb6135be316d2a7f/a6d36/dirtywrites.png&quot;
            alt=&quot;Dirty writes. Figure 7-5&quot;
            title=&quot;Dirty writes.&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Dirty writes.&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;h4 id=&quot;snapshot-isolationrepeatable-read&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#snapshot-isolationrepeatable-read&quot; aria-label=&quot;snapshot isolationrepeatable read permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Snapshot Isolation/Repeatable Read&lt;/h4&gt;
&lt;p&gt;There are still plenty of ways in which you can have concurrency bugs even with &lt;strong&gt;read committed&lt;/strong&gt; isolation.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Read skew/Non-repeatable reads&lt;/strong&gt;
A client sees different parts of the database at different points in time. This issue is most commonly prevented with snapshot isolation, which allows a transaction to read from a consistent snapshot corresponding to data committed in one particular point in time.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/55af14b389a8abf88de97d19d19b4e86/89048/readskew.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 45.39877300613497%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAABYlAAAWJQFJUiTwAAABKUlEQVR42m2SiY6EQAhE/f9fdCfreGuM930x/XDbuMmQEBSaoopuR/7sPE+NcRyL67rSNM2//NOO4xTf9+X1+pG+7zW3bZvs+y4ODXVdK8A8zxKGoWRZJm3b3pGmp5MLguCu53muRPh2romHTNOkses6/V6WRcHt5KdTswrsOcAwp6oqZUgCL8tS3u+3JEkiaZoqoBGu0hmIW1XUhqE3BEbN8e8wwTqSibBgEPKKotAhVrrd6TgOyrKqSlWF6Q45eBWqu5F/GGDkLyaDsibSSEQq0TJXQA7DbF1XbTyO/V4+Bvi1jsacWQyz0VxApIMAo9e+BtwhgSyaACTJk/C8X4miUGtRFJm9euZmfb1dAGFrh1p2ukP5YgAgB9mwsDcZhoHmYMlL+PZGP0xPtzUt/Id6AAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/55af14b389a8abf88de97d19d19b4e86/0cbef/readskew.avif 163w,
/static/55af14b389a8abf88de97d19d19b4e86/bffb7/readskew.avif 325w,
/static/55af14b389a8abf88de97d19d19b4e86/69c29/readskew.avif 650w,
/static/55af14b389a8abf88de97d19d19b4e86/6d24a/readskew.avif 975w,
/static/55af14b389a8abf88de97d19d19b4e86/4f997/readskew.avif 1242w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/55af14b389a8abf88de97d19d19b4e86/94563/readskew.webp 163w,
/static/55af14b389a8abf88de97d19d19b4e86/647a8/readskew.webp 325w,
/static/55af14b389a8abf88de97d19d19b4e86/c1dc5/readskew.webp 650w,
/static/55af14b389a8abf88de97d19d19b4e86/1e975/readskew.webp 975w,
/static/55af14b389a8abf88de97d19d19b4e86/a3537/readskew.webp 1242w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/55af14b389a8abf88de97d19d19b4e86/222b7/readskew.png 163w,
/static/55af14b389a8abf88de97d19d19b4e86/ff46a/readskew.png 325w,
/static/55af14b389a8abf88de97d19d19b4e86/a6d36/readskew.png 650w,
/static/55af14b389a8abf88de97d19d19b4e86/e548f/readskew.png 975w,
/static/55af14b389a8abf88de97d19d19b4e86/89048/readskew.png 1242w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/55af14b389a8abf88de97d19d19b4e86/a6d36/readskew.png&quot;
            alt=&quot;Read skew. Alice thinks she has $1000 in total, but only sees $900 between both accounts. Figure 7-6&quot;
            title=&quot;Read skew.&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Read skew.&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;h4 id=&quot;serializable-isolation&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#serializable-isolation&quot; aria-label=&quot;serializable isolation permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Serializable isolation&lt;/h4&gt;
&lt;p&gt;The read committed and snapshot isolation levels are about the guarantees of what a read-only transaction can see in the presence of concurrent writes. What kind of conflicts can occur between concurrently writing transactions?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Lost updates&lt;/strong&gt;
Two clients concurrently perform a read-modify-write cycle. One overwrites the other’s write without incorporating its changes, so data is lost.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/17bb7dfb093747eefba473c1feb0cdad/f09ab/lostupdates.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 28.834355828220858%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAABYlAAAWJQFJUiTwAAAA3UlEQVR42k2R2Q6FIAxE+f9/9FHiAm6IiluvpwZzmzSg005nikkpyb7vktIm4ziKc062bZPruiTGWf9N06QJNgyD4ud5yn3fmgR4CJMYGtZ1FYj7vpemaeQ4DinLUqy12jzPs9R1rTjfRVEoAcFgSOkHM8uyCBlj1IK2bZUAJRSRIvfj4niG1VoLxtDsJCslDYpCCAq+k17rhPdeB0CAxf/BYM75p/bFIOY0WSrFRN4Ja+i67lNtbfk14eAfYz3ZvmEXkGWF2QKqKOTk0Th5FIi4V1X17LVSN/QzCIU/3D7QUmiQiI4AAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/17bb7dfb093747eefba473c1feb0cdad/0cbef/lostupdates.avif 163w,
/static/17bb7dfb093747eefba473c1feb0cdad/bffb7/lostupdates.avif 325w,
/static/17bb7dfb093747eefba473c1feb0cdad/69c29/lostupdates.avif 650w,
/static/17bb7dfb093747eefba473c1feb0cdad/6d24a/lostupdates.avif 975w,
/static/17bb7dfb093747eefba473c1feb0cdad/09946/lostupdates.avif 1250w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/17bb7dfb093747eefba473c1feb0cdad/94563/lostupdates.webp 163w,
/static/17bb7dfb093747eefba473c1feb0cdad/647a8/lostupdates.webp 325w,
/static/17bb7dfb093747eefba473c1feb0cdad/c1dc5/lostupdates.webp 650w,
/static/17bb7dfb093747eefba473c1feb0cdad/1e975/lostupdates.webp 975w,
/static/17bb7dfb093747eefba473c1feb0cdad/e19c7/lostupdates.webp 1250w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/17bb7dfb093747eefba473c1feb0cdad/222b7/lostupdates.png 163w,
/static/17bb7dfb093747eefba473c1feb0cdad/ff46a/lostupdates.png 325w,
/static/17bb7dfb093747eefba473c1feb0cdad/a6d36/lostupdates.png 650w,
/static/17bb7dfb093747eefba473c1feb0cdad/e548f/lostupdates.png 975w,
/static/17bb7dfb093747eefba473c1feb0cdad/f09ab/lostupdates.png 1250w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/17bb7dfb093747eefba473c1feb0cdad/a6d36/lostupdates.png&quot;
            alt=&quot;Lost updates. Figure 7-1&quot;
            title=&quot;Lost updates.&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Lost updates.&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Write skew&lt;/strong&gt;
A transaction reads something, makes a decision based on the value it saw, and writes the decision to the database. However, by the time the write is made, the premise of the decision is no longer true.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/a124ed6b2750ff2975a5142235c38a59/89048/writeskew.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 69.93865030674846%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAABYlAAAWJQFJUiTwAAAB20lEQVR42oWTiW7iQBBE5///DCkkrLIQgmDDaQ4fHMbGYJtOvw4TORHJjjSyPZqqrq4uuyzLZDadSlEUcj6fpa5rubeu1+vnu2FmM7v/HeN2u51EYSRxFEmkG+ImQZqmMplMJAgCWS6XdnY4HCQMQ4njWLGhnE6nBuF2K4vFQlZ6eb1eG/B4PH5eAsw5hVFWVZWdBTfMBoy+p4dU8jwXB7Dz9CTdblfm2sZwODSlnhDyRJVsk0RyJaQ92vzT6UhPMVO1azQaGTEYB4DD+XwuiaoFXKsKvyC4XC5SlqW9YwVKwaCMQmCqm49GiG+FslOB6r8tCPMst/YyxfL84iEVMHe1Wsl+vzd/KIKie8sU34r6wTUTYApbrZY8ttvSf3mxSUJGG1ZA9z0Lflo2lF6vJ6/9vix1wuPxWC5KWCqIdixjDQV80wVxYvLWunpqA9PCznuAj1T2HgL0mUQxoJPepSP2SNMweB3IVDNK9MARKUdbmEtFKnuDm4SQ4XO42UiinnOn/fAgf5+fZfz2Jv80NnX9YYsDBICdKqEnYaGYTBKRtQ6NH+AjEYVGJrBBIiJuRM3Jf5b9XkrK03vGpr2qKs2OqjE091verF21A0Kmji1YwQBoPbr9/6j0hO/ihjijtjrOmgAAAABJRU5ErkJggg==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/a124ed6b2750ff2975a5142235c38a59/0cbef/writeskew.avif 163w,
/static/a124ed6b2750ff2975a5142235c38a59/bffb7/writeskew.avif 325w,
/static/a124ed6b2750ff2975a5142235c38a59/69c29/writeskew.avif 650w,
/static/a124ed6b2750ff2975a5142235c38a59/6d24a/writeskew.avif 975w,
/static/a124ed6b2750ff2975a5142235c38a59/4f997/writeskew.avif 1242w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/a124ed6b2750ff2975a5142235c38a59/94563/writeskew.webp 163w,
/static/a124ed6b2750ff2975a5142235c38a59/647a8/writeskew.webp 325w,
/static/a124ed6b2750ff2975a5142235c38a59/c1dc5/writeskew.webp 650w,
/static/a124ed6b2750ff2975a5142235c38a59/1e975/writeskew.webp 975w,
/static/a124ed6b2750ff2975a5142235c38a59/a3537/writeskew.webp 1242w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/a124ed6b2750ff2975a5142235c38a59/222b7/writeskew.png 163w,
/static/a124ed6b2750ff2975a5142235c38a59/ff46a/writeskew.png 325w,
/static/a124ed6b2750ff2975a5142235c38a59/a6d36/writeskew.png 650w,
/static/a124ed6b2750ff2975a5142235c38a59/e548f/writeskew.png 975w,
/static/a124ed6b2750ff2975a5142235c38a59/89048/writeskew.png 1242w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/a124ed6b2750ff2975a5142235c38a59/a6d36/writeskew.png&quot;
            alt=&quot;Write skew. Figure 7-8&quot;
            title=&quot;Write skew.&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Write skew.&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;Another example around preventing &lt;em&gt;double-spending&lt;/em&gt;: a service that allows users to spend money or points needs to check that a user doesn’t spend more than they have. You might implement this by inserting a tentative spending item into a user’s account, listing all the items in the account, and checking that the sum is positive. With write skew, it could happen that two spending items are inserted concurrently that together cause the balance to go negative, but that neither transaction notices the other.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Phantom reads&lt;/strong&gt;
A transaction reads objects that match some search condition. Another client makes a write that affects the results of that search. Snapshot isolation prevents straightforward phantom reads, but phantoms in the context of write skew require special treatment, such as index-range locks.&lt;/p&gt;
&lt;h3 id=&quot;serializable-isolation-1&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#serializable-isolation-1&quot; aria-label=&quot;serializable isolation 1 permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Serializable isolation&lt;/h3&gt;
&lt;p&gt;Usually regarded as the strongest isolation level. It guarantees that even though transactions may execute in parallel, the end result is the same as if they had executed serially, thus, preventing race conditions.&lt;/p&gt;
&lt;p&gt;But if serializable isolation is so much better than the mess of weak isolation levels, &lt;em&gt;why isn’t everyone using it?!&lt;/em&gt; Most databases that provide serializability today use one of three techniques.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Literally executing transactions in a serial order&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Every transaction must be small and fast, because it takes only one slow transaction to stall all transaction processing.&lt;/li&gt;
&lt;li&gt;Whenever the dataset can fit in memory.&lt;/li&gt;
&lt;li&gt;Write throughput must be low enough to be handled on a single CPU core&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Two-phase locking (2PL)&lt;/strong&gt;
Several transactions are allowed to concurrently read the same object as long as nobody is writing to it. But as soon as anyone wants to modify or delete an object, exclusive access is required. In 2PL, writers don’t just block other writers; they also block readers and vice versa: it&apos;s &lt;strong&gt;pessimistic&lt;/strong&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If transaction A has read an object and transaction B wants to write to that object, B must wait until A commits or aborts before it can continue. (This ensures that B can’t change the object unexpectedly behind A’s back.)&lt;/li&gt;
&lt;li&gt;If transaction A has written an object and transaction B wants to read that object, B must wait until A commits or aborts before it can continue.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Serializable snapshot isolation (SSI)&lt;/strong&gt;
On the one hand, we have implementations of serializability that don’t perform well (two-phase locking) or don’t scale well (serial execution). On the other hand, we have weak isolation levels that have good performance, but are prone to various race conditions (lost updates, write skew, phantoms, etc.).&lt;/p&gt;
&lt;p&gt;A fairly new algorithm (SSI) avoids most of the downsides of the previous approaches. It uses an optimistic approach, allowing transactions to proceed without blocking. When a transaction wants to commit, it is checked, and it is aborted if the execution was not serializable.&lt;/p&gt;
&lt;p&gt;Snapshot isolation has the mantra &lt;strong&gt;&quot;readers never block writers&quot;&lt;/strong&gt;, and &lt;strong&gt;&quot;writers never block readers&quot;&lt;/strong&gt;, which captures this key difference between snapshot isolation and two-phase locking. Because 2PL provides serializability, it protects against all the race conditions, including lost updates and write skew.&lt;/p&gt;
&lt;p&gt;If the database keeps track of each transaction’s activity in great detail, it can be precise about which transactions need to abort, but the bookkeeping overhead can become significant. Less detailed tracking is faster, but may lead to more transactions being aborted than strictly necessary.&lt;/p&gt;
&lt;p&gt;The rate of aborts significantly affects the overall performance of SSI. For example, a transaction that reads and writes data over a long period of time is likely to run into conflicts and abort, so SSI requires that read-write transactions be fairly short (long-running read-only transactions may be okay). However, SSI is probably less sensitive to slow transactions than two-phase locking or serial execution.&lt;/p&gt;
&lt;h2 id=&quot;8-the-trouble-with-distributed-systems&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#8-the-trouble-with-distributed-systems&quot; aria-label=&quot;8 the trouble with distributed systems permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;8. The Trouble with Distributed Systems&lt;/h2&gt;
&lt;p&gt;In the end, our task as engineers is to build systems that meet user expectations, in spite of everything that goes wrong in the real world. In distributed systems, pessimism pays off, because &lt;em&gt;plenty&lt;/em&gt; of things can go wrong:&lt;/p&gt;
&lt;h3 id=&quot;nondeterminism-and-partial-failures&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#nondeterminism-and-partial-failures&quot; aria-label=&quot;nondeterminism and partial failures permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Nondeterminism and Partial Failures&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Ethernet and IP are packet-switched protocols, which suffer from queueing and thus &lt;em&gt;unbounded&lt;/em&gt; delays in the network.&lt;/li&gt;
&lt;li&gt;Clocks in nodes might be out of sync, suddenly jumping in time.&lt;/li&gt;
&lt;li&gt;A node in a distributed system must assume that its execution can be paused (i.e. garbage collection) for a significant length of time at any point.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Such &lt;strong&gt;partial failures&lt;/strong&gt; are inherent to distributed systems, and as such, &lt;strong&gt;nondeterministic&lt;/strong&gt;. When software interacts with other nodes, there&apos;s a possibility of occasional failures, slow responses, or timeouts. &lt;strong&gt;Tolerance of partial failures is a goal, enabling the system to function despite broken parts.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Still, a network doesn’t guard against human error (e.g. misconfigured switches), which is a &lt;del&gt;major&lt;/del&gt; cause of outages.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The bigger a system gets, the more likely it is that one of its components is broken. Over time, broken things get fixed and new things break, but in a system with thousands of nodes, it is reasonable to assume that something &lt;strong&gt;is always broken&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;detecting-faults&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#detecting-faults&quot; aria-label=&quot;detecting faults permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Detecting faults&lt;/h3&gt;
&lt;p&gt;Timeouts are often used, but they can&apos;t distinguish between network and node failures. Even once detected, tolerating faults is complex due to the lack of shared state between nodes. Information flows via an unreliable network, necessitating protocols that involve multiple nodes to reach &lt;strong&gt;agreement&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Rather than using configured constant timeouts, systems can continually measure response times and their variability (&lt;em&gt;jitter&lt;/em&gt;), and automatically adjust timeouts according to the observed response time distribution.&lt;/p&gt;
&lt;p&gt;With careful use of quality of service (prioritization and scheduling of packets) and admission control (rate-limiting senders), it is possible to provide statistically bounded delay.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Deliberately trigger network problems and test the system’s response (this is the idea behind Netflix&apos;s Chaos Monkey).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;tcp-vs-udp&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#tcp-vs-udp&quot; aria-label=&quot;tcp vs udp permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;TCP vs UDP&lt;/h4&gt;
&lt;p&gt;Some latency-sensitive applications, such as videoconferencing, use UDP rather than TCP. It’s a trade-off between reliability and variability of delays: as UDP does not perform flow control and does not retransmit lost packets, it avoids some of the reasons for variable network delays.&lt;/p&gt;
&lt;h4 id=&quot;time-is-money&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#time-is-money&quot; aria-label=&quot;time is money permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Time is Money&lt;/h4&gt;
&lt;p&gt;The &quot;MiFID II&quot; draft European regulation for financial institutions requires all high-frequency trading funds to synchronize their clocks to within 100 microseconds of UTC, in order to help debug market anomalies such as “flash crashes” and to help detect market manipulation.&lt;/p&gt;
&lt;h4 id=&quot;the-worst-error&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-worst-error&quot; aria-label=&quot;the worst error permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The Worst Error&lt;/h4&gt;
&lt;p&gt;Database writes can mysteriously disappear: a node with a lagging clock is unable to overwrite values previously written by a node with a fast clock until the clock skew between the nodes has elapsed. This scenario can cause arbitrary amounts of data to be silently dropped without any error being reported to the application.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In real life it&apos;s extremely difficult to calculate the true, current time. A close exception is Google’s &lt;em&gt;TrueTime API&lt;/em&gt;, which explicitly reports the confidence interval on the local clock. When you ask it for the current time, you get back two values: [earliest, latest], which are the earliest possible and the latest possible timestamp.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;hard-real-time-systems&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#hard-real-time-systems&quot; aria-label=&quot;hard real time systems permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Hard real-time systems&lt;/h4&gt;
&lt;p&gt;Computers that control aircraft, rockets, or cars must respond quickly to their sensor inputs. There is a specified deadline by which the software must respond; if it doesn’t, that may cause a failure of the entire system. Moreover, “real-time” is not the same as “high-performance”—in fact, real-time systems may have lower throughput, since they have to prioritize timely responses above all else.&lt;/p&gt;
&lt;h3 id=&quot;cost-trade-off&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cost-trade-off&quot; aria-label=&quot;cost trade off permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cost Trade-Off&lt;/h3&gt;
&lt;p&gt;You can always have a cheaper system that’s further from the ideal of a distributed system: scalable, fault tolerant, and with low latency. It depends on your situation if you choose cheap and unreliable solutions over expensive reliability.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;There is no such thing as perfect reliability, but only limits of what one can realistically promise.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The internet shares network bandwidth dynamically. Senders want to act as quickly as possible, and the network switches allocates bandwidth for each packet over the wire. This approach has the downside of queueing, but the advantage is that it maximizes utilization of the wire. The wire has a fixed cost, so if you utilize it better, each byte you send over the wire is cheaper.&lt;/p&gt;
&lt;p&gt;Multi-tenancy environments with dynamic resource partitioning provide better utilization, so it is cheaper, but it has the downside of variable delays (vs single-tenancy environments with less delay jitter).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Variable delays in networks are not a law of nature, but simply the result of a cost/benefit trade-off.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;knowledge-truth-and-lies&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#knowledge-truth-and-lies&quot; aria-label=&quot;knowledge truth and lies permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Knowledge, Truth and Lies&lt;/h3&gt;
&lt;p&gt;A service’s clients are often run by people whose priorities are very different from the priorities of the people running the service. I have been both a victim and a perpetrator of this while working for a Big Tech firm, where interests are always at conflict.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The moral of the story is that a node cannot necessarily trust its own judgment of a situation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;byzantine-faults&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#byzantine-faults&quot; aria-label=&quot;byzantine faults permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Byzantine Faults&lt;/h3&gt;
&lt;p&gt;Distributed systems problems become much harder if there is a risk that nodes may “lie” (send arbitrary faulty or corrupted responses)—for example, if a node may claim to have received a particular message when in fact it didn’t. Such behavior is known as a &lt;strong&gt;Byzantine fault&lt;/strong&gt;.&lt;/p&gt;
&lt;h4 id=&quot;the-byzantine-generals-problem&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-byzantine-generals-problem&quot; aria-label=&quot;the byzantine generals problem permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The Byzantine Generals Problem&lt;/h4&gt;
&lt;p&gt;This problem is a generalization of the so-called Two Generals Problem, which imagines a situation in which two army generals need to agree on a battle plan. As they have set up camp on two different sites, they can only communicate by messenger, and the messenger sometimes get delayed or lost (like packets in a network).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A system is Byzantine fault-tolerant if it continues to operate correctly even if some of the nodes are malfunctioning and not obeying the protocol, or if malicious attackers are interfering with the network.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In peer-to-peer networks, where there is no such central authority, Byzantine fault tolerance is more relevant. Think of the blockchain, for example.&lt;/p&gt;
&lt;p&gt;The theoretical description of an algorithm can declare that certain things are simply assumed not to happen—and in non-Byzantine systems, we do have to make some assumptions about faults that can and cannot happen. However, a real implementation may still have to include code to handle the case where something happens that was assumed to be impossible, even if that handling boils down to printf(&quot;Sucks to be you&quot;) and exit(666)—i.e., letting a human operator clean up the mess. (This is arguably the difference between computer science and software engineering.)&lt;/p&gt;
&lt;h2 id=&quot;9-consistency-and-consensus&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#9-consistency-and-consensus&quot; aria-label=&quot;9 consistency and consensus permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;9. Consistency and Consensus&lt;/h2&gt;
&lt;p&gt;Packets can be lost, reordered, duplicated, or arbitrarily delayed in the network; clocks are approximate at best; and nodes can pause due to garbage collection or crash at any time. We need to find ways of tolerating faults in a distributed system.&lt;/p&gt;
&lt;p&gt;The best way of building fault-tolerant systems is to find some general-purpose abstractions with useful guarantees. For example, by using a transaction, the application can pretend that there are no crashes (atomicity), that nobody else is concurrently accessing the database (isolation), and that storage devices are perfectly reliable (durability). Even though crashes, race conditions, and disk failures do occur, the transaction abstraction hides those problems so that the application doesn’t need to worry about them.&lt;/p&gt;
&lt;h3 id=&quot;consensus&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#consensus&quot; aria-label=&quot;consensus permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Consensus&lt;/h3&gt;
&lt;p&gt;When users register for a new social network, how can one ensure that a username is unique? If one node is going to accept a registration, it needs to somehow know that another node isn’t concurrently in the process of registering the same name. This problem leads us toward another useful transaction: consensus.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Achieving &lt;em&gt;consensus&lt;/em&gt; means deciding something in such a way that all nodes agree on what was decided, and such that the decision is &lt;em&gt;irrevocable&lt;/em&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;split-brain-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#split-brain-&quot; aria-label=&quot;split brain  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Split brain 🧠&lt;/h4&gt;
&lt;p&gt;Say you have a database with single-leader replication. If the leader dies and you need to fail over to another node, the remaining database nodes can use consensus to elect a new leader. If two nodes both believe that they are the leader, we have a &lt;em&gt;split brain&lt;/em&gt;, and it often leads to data loss.&lt;/p&gt;
&lt;h3 id=&quot;consistency-guarantees&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#consistency-guarantees&quot; aria-label=&quot;consistency guarantees permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Consistency guarantees&lt;/h3&gt;
&lt;p&gt;Most replicated databases provide at least &lt;em&gt;eventual consistency&lt;/em&gt; (if you stop writing and wait some time, then eventually all reads will return the same value). Stronger guarantees may have worse performance or be less fault-tolerant than systems with weaker guarantees.&lt;/p&gt;
&lt;p&gt;For example, &lt;em&gt;linearizability&lt;/em&gt; is appealing because it makes a database behave like a variable in a single-threaded program, but it’s nevertheless slow, especially with large network delays.&lt;/p&gt;
&lt;h3 id=&quot;causality&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#causality&quot; aria-label=&quot;causality permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Causality&lt;/h3&gt;
&lt;p&gt;Unlike linearizability, which puts all operations in a single, totally ordered timeline, causality provides us with a weaker consistency model: some things can be concurrent, so the version history is like a timeline with branching and merging. Causal consistency does not have the coordination overhead of linearizability and is much less sensitive to network problems.&lt;/p&gt;
&lt;h3 id=&quot;kicking-the-can-down-the-road-&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#kicking-the-can-down-the-road-&quot; aria-label=&quot;kicking the can down the road  permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Kicking the can down the road 🥫&lt;/h3&gt;
&lt;p&gt;Although a single-leader database can provide linearizability without executing a consensus algorithm on every write, it still requires consensus to maintain its leadership and for leadership changes.&lt;/p&gt;
&lt;p&gt;Tools like &lt;em&gt;ZooKeeper&lt;/em&gt; play an important role in providing an “outsourced” consensus, failure detection, and membership service that applications can use.&lt;/p&gt;
&lt;p&gt;Nevertheless, not every system necessarily requires consensus: for example, leaderless and multi-leader replication systems typically do not use global consensus. The conflicts that occur in these systems are a consequence of not having consensus across different leaders, but maybe that’s okay: maybe we simply need to cope without linearizability and learn to work better with data that has branching and merging version histories.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Insights in 'Designing Data-Intensive Applications' - Part 1/3]]></title><description><![CDATA[A post to share key insights after reading Martin Kleppmann's essential book. Part 1/3]]></description><link>https://www.j1nma.com/designing-data-intensive-applications/</link><guid isPermaLink="false">https://www.j1nma.com/designing-data-intensive-applications/</guid><pubDate>Fri, 08 Dec 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Welcome to my blog on the book &quot;Designing Data Intensive Applications&quot; by Martin Kleppmann. In this post, I will share with you key principles, trade-offs, and technologies that I found as the most interesting for building robust and scalable data systems.&lt;/p&gt;
&lt;p&gt;Reading it is no easy feat (&gt;600 pages), but I do strongly recommend it if you want to have a broader vision for the next time you have to design a system, or just want to brush up on some concepts.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Some of these notes are as they appear in the original book, most tailored by me, but all ideas are a creation of Martin or authors Martin quotes in his book.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This is Part 1. Check Part 2, &lt;em&gt;Distributed Data&lt;/em&gt;, &lt;a href=&quot;https://www.j1nma.com/designing-data-intensive-applications-part-2&quot;&gt;here&lt;/a&gt;, and Part 3, &lt;em&gt;Derived Data&lt;/em&gt;, &lt;a href=&quot;https://www.j1nma.com/designing-data-intensive-applications-part-3&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;!-- TOC --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#foundations-of-data-systems&quot;&gt;Foundations of Data Systems&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#preface&quot;&gt;Preface&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#what-is-data-intensive-anyway&quot;&gt;What is data-intensive anyway?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#show-me-the-money-and-the-system&quot;&gt;Show me the money and the system&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#youre-not-google-or-amazon-stop-worrying-about-scale&quot;&gt;&quot;You’re not Google or Amazon. Stop worrying about scale!&quot;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#reliable-scalable-and-maintainable-applications&quot;&gt;Reliable, Scalable, and Maintainable Applications&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#reliability&quot;&gt;Reliability&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#scalability&quot;&gt;Scalability&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#maintainability&quot;&gt;Maintainability&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#a-tool-for-the-task&quot;&gt;A tool for the task&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#faults-and-failures&quot;&gt;Faults and failures&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#expect-the-best-prepare-for-the-worst&quot;&gt;Expect the best, prepare for the worst&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#twitter-example&quot;&gt;Twitter example&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#measuring-performance-response-time-percentiles&quot;&gt;Measuring Performance: response time percentiles&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#bad-effects&quot;&gt;Bad effects&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#data-models-and-query-languages&quot;&gt;Data Models and Query Languages&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#the-birth-of-nosql&quot;&gt;The Birth of NoSQL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#the-object-relational-impedance-mismatch&quot;&gt;The Object-Relational Impedance Mismatch&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#id-or-text-a-question-of-duplication&quot;&gt;ID or text? A question of duplication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#what-to-choose-it-depends&quot;&gt;What to choose? It depends...&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#schemaless&quot;&gt;Schemaless?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#storage-locality&quot;&gt;Storage Locality&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#graph-stuff&quot;&gt;Graph Stuff&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#storage-and-retrieval&quot;&gt;Storage and Retrieval&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#an-important-trade-off-writes&quot;&gt;An Important Trade-Off: writes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#another-trade-off-clustered-indexes&quot;&gt;Another Trade-Off: clustered indexes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#a-question-of-cost-and-encoding&quot;&gt;A question of cost and encoding&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#transaction-processing-vs-analytic-systems&quot;&gt;Transaction processing vs Analytic systems&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#data-warehousing&quot;&gt;Data Warehousing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#columnar-storage&quot;&gt;Columnar Storage&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#encoding-and-evolvability&quot;&gt;Encoding and Evolvability&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#scenarios-in-which-data-encodings-are-important&quot;&gt;Scenarios in which data encodings are important&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#a-bit-of-care&quot;&gt;A bit of care&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#formats-for-encoding-data&quot;&gt;Formats for Encoding Data&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#dont-use-your-languages-built-in-encoding&quot;&gt;Don&apos;t use your language&apos;s built-in encoding&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- /TOC --&gt;
&lt;!-- TOC ignore:true --&gt;
&lt;h4 id=&quot;who-is-this-for-why-should-i-read-this&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#who-is-this-for-why-should-i-read-this&quot; aria-label=&quot;who is this for why should i read this permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;em&gt;Who is this for? Why should I read this?&lt;/em&gt;&lt;/h4&gt;
&lt;p&gt;The book and this blog are for software engineers, architects, and managers who love to code and design systems. It is especially relevant if you need to make decisions about the architecture of the systems you work on. Even if you have no choice over your tools, I hope this blog will help you understand their strengths and weaknesses, just as the book did for me.&lt;/p&gt;
&lt;p&gt;As software engineers and architects, we need to have a technically accurate and precise understanding of the various technologies and their trade-offs if we want to build good applications. Often times, aspects of a system are looked over or outright dismissed, such as message queues, caches, search indexes, frameworks for batch and stream processing.&lt;/p&gt;
&lt;p&gt;If you understand those principles, you’re in a position to see where each tool fits in, how to make good use of it, and how to avoid its pitfalls. That’s where Kleppmann&apos;s book comes in, and that&apos;s what I want to highlight in this post.&lt;/p&gt;
&lt;h1 id=&quot;foundations-of-data-systems&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#foundations-of-data-systems&quot; aria-label=&quot;foundations of data systems permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Foundations of Data Systems&lt;/h1&gt;
&lt;h2 id=&quot;preface&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#preface&quot; aria-label=&quot;preface permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Preface&lt;/h2&gt;
&lt;h3 id=&quot;what-is-data-intensive-anyway&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-is-data-intensive-anyway&quot; aria-label=&quot;what is data intensive anyway permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What is data-intensive anyway?&lt;/h3&gt;
&lt;p&gt;Is it yet another buzz phrase to add traction for lame LinkedIn posts? Maybe. But in essence, an application is &lt;strong&gt;data-intensive&lt;/strong&gt; if data is its primary challenge—the &lt;em&gt;quantity&lt;/em&gt; of data, the &lt;em&gt;complexity&lt;/em&gt; of data, or the &lt;em&gt;speed&lt;/em&gt; at which it is changing—as opposed to compute-intensive, where CPU cycles are the bottleneck.&lt;/p&gt;
&lt;p&gt;A data-intensive application is typically built from standard building blocks that provide commonly needed functionality. For example, many applications need to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Store data for later (&lt;strong&gt;databases&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;Remember the result of an expensive operation, to speed up reads (&lt;strong&gt;caches&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;Allow users to search data by keyword or filter it in various ways (&lt;strong&gt;search indexes&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Periodically crunch a large amount of accumulated data (&lt;strong&gt;batch processing&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;Send a message to another process, to be handled asynchronously (&lt;strong&gt;stream processing&lt;/strong&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;show-me-the-money-and-the-system&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#show-me-the-money-and-the-system&quot; aria-label=&quot;show me the money and the system permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Show me the money (and the system)&lt;/h3&gt;
&lt;p&gt;Businesses need to be agile, test hypotheses cheaply, and respond quickly to new market insights by keeping development cycles short and data models flexible. No matter how strong your business plan looks, without a proper system that fits this ideal, there is little chance that startup or company will prosper.&lt;/p&gt;
&lt;h3 id=&quot;youre-not-google-or-amazon-stop-worrying-about-scale&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#youre-not-google-or-amazon-stop-worrying-about-scale&quot; aria-label=&quot;youre not google or amazon stop worrying about scale permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&quot;You’re not Google or Amazon. Stop worrying about scale!&quot;&lt;/h3&gt;
&lt;p&gt;Building for scale that you don’t need is wasted effort and may lock you into an inflexible design. In effect, it is a form of premature optimization. However, it’s also important to choose the right tool for the job, and different technologies each have their own strengths and weaknesses.&lt;/p&gt;
&lt;h2 id=&quot;1-reliable-scalable-and-maintainable-applications&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#1-reliable-scalable-and-maintainable-applications&quot; aria-label=&quot;1 reliable scalable and maintainable applications permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;1. Reliable, Scalable, and Maintainable Applications&lt;/h2&gt;
&lt;p&gt;An application has to meet various requirements in order to be useful. There are functional requirements (what it should do, such as allowing data to be stored, retrieved, searched, and processed in various ways), and some nonfunctional requirements (general properties like security, reliability, compliance, scalability, compatibility, and maintainability). Let&apos;s discuss the latter.&lt;/p&gt;
&lt;h3 id=&quot;reliability&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#reliability&quot; aria-label=&quot;reliability permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Reliability&lt;/h3&gt;
&lt;p&gt;A system is reliable if it continues to perform the correct function users expect at the desired level of performance, even in the face of &lt;em&gt;adversity&lt;/em&gt; (hardware or software faults, users making mistakes or using the software in unexpected ways).&lt;/p&gt;
&lt;p&gt;There are situations in which we may choose to &lt;del&gt;sacrifice&lt;/del&gt; reliability in order to reduce development cost (e.g., when developing a prototype product for an unproven market) or operational cost (e.g., for a service with a very narrow profit margin)—but we should be very &lt;del&gt;conscious&lt;/del&gt; of when we are cutting corners.&lt;/p&gt;
&lt;h3 id=&quot;scalability&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#scalability&quot; aria-label=&quot;scalability permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Scalability&lt;/h3&gt;
&lt;p&gt;A system is scalable if its performance stays ‘good enough’ under growth in data volume, traffic volume, or complexity.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In an unproven product it’s usually more important to be able to iterate quickly on product features than it is to scale to some hypothetical future load.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The architecture of systems that operate at large scale is usually highly specific to the application—there is no such thing as a one-size-fits-all scalable architecture. The problem may be the volume of reads, the volume of writes, the volume of data to store, the complexity of the data, the response time requirements, the access patterns, or (usually) some mixture of all of these plus many more issues.&lt;/p&gt;
&lt;p&gt;Some systems can automatically add computing resources when they detect a load increase, whereas other systems are scaled manually by a human.&lt;/p&gt;
&lt;p&gt;An architecture that is appropriate for one level of load is unlikely to cope with 10 times that load. If you are working on a fast-growing service, it is therefore likely that you will need to rethink your architecture on every order of magnitude load increase.&lt;/p&gt;
&lt;h3 id=&quot;maintainability&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#maintainability&quot; aria-label=&quot;maintainability permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Maintainability&lt;/h3&gt;
&lt;p&gt;A system is maintainable if, over time, many different people will work on the system, and they are all able to work on it productively. In essence it’s about making life better for the engineering and operations teams who need to work with the system:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;self-healing where appropriate, but also giving administrators manual control&lt;/li&gt;
&lt;li&gt;good documentation and an easy-to-understand operational model&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;It is well known that the majority of the cost of software is not in its initial development, but in its ongoing maintenance.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Maintainability can be divided into three design principles:
&lt;em&gt;Operability: it should be easy to…&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Keep the system running smoothly&lt;/li&gt;
&lt;li&gt;Use monitoring for tracking down the cause of problems&lt;/li&gt;
&lt;li&gt;Make security patches&lt;/li&gt;
&lt;li&gt;Deploy and rollback&lt;/li&gt;
&lt;li&gt;Migrate applications&lt;/li&gt;
&lt;li&gt;Preserve the organization&apos;s knowledge (&lt;em&gt;often looked over&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;Provide visibility into the runtime behavior&lt;/li&gt;
&lt;li&gt;Avoiding dependency on individual machines&lt;/li&gt;
&lt;li&gt;Plan the expected capacity of your systems, and monitor for changes&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Good operations can often work around the limitations of bad (or incomplete) software, but good software cannot run reliably with bad operations.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;em&gt;Simplicity&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Make it easy for new engineers to understand the system, by removing as much complexity as possible from the system. (This is not the same as simplicity of the user interface).&lt;/li&gt;
&lt;li&gt;Complexity slows down everyone who needs to work on the system, further increasing the cost of maintenance.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Evolvability&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Make it easy for engineers to make changes to the system in the future.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;a-tool-for-the-task&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#a-tool-for-the-task&quot; aria-label=&quot;a tool for the task permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;A tool for the task&lt;/h3&gt;
&lt;p&gt;Many new tools for data storage and processing have emerged in recent years. They are optimized for a variety of different use cases, and they no longer neatly fit into traditional categories. For example, there are data stores that are also used as message queues (Redis), and there are message queues with database-like durability guarantees (Apache Kafka).&lt;/p&gt;
&lt;p&gt;This ambiguity can work for specific use cases, but generally makes the choice of a tool harder and sticks your system to the tools limits, opposite to the more flexible approach, where the work is broken down into tasks that can be performed efficiently on a single tool, and those different tools are stitched together using application code.&lt;/p&gt;
&lt;h3 id=&quot;faults-and-failures&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#faults-and-failures&quot; aria-label=&quot;faults and failures permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Faults and failures&lt;/h3&gt;
&lt;p&gt;A &lt;strong&gt;fault&lt;/strong&gt; is usually defined as one component of the system deviating from its spec, whereas a &lt;strong&gt;failure&lt;/strong&gt; is when the system as a whole stops providing the required service to the user.&lt;/p&gt;
&lt;p&gt;Faults can be in hardware (typically random and uncorrelated), software (bugs are typically systematic and hard to deal with), and humans (who inevitably make mistakes from time to time). Fault-tolerance techniques can hide certain types of faults from the end user&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Hard disks are reported as having a mean time to failure (MTTF) of about 10 to 50 years. On a storage cluster with 10,000 disks, we should expect on average one disk to die per day.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;It is impossible to reduce the probability of a fault to zero; it is usually best to design fault-tolerance mechanisms that prevent faults from causing failures. Failures of e-commerce sites can have huge costs in terms of lost revenue and damage to reputation (I was involved in a crash that cost my employer $40K in only 3 hours).&lt;/p&gt;
&lt;p&gt;It is a common practice in big tech companies, such as Netflix, Amazon or MercadoLibre, to deliberately induce faults, so as to ensure that the fault-tolerance machinery is continually exercised and tested. A famous one is Netflix&apos;s &lt;a href=&quot;https://netflix.github.io/chaosmonkey/&quot;&gt;Chaos Monkey&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Such fault-tolerant systems also have operational advantages: a single-server system requires planned downtime if you need to reboot the machine (to apply operating system security patches, for example), whereas a system that can tolerate machine failure can be patched one node at a time, without downtime of the entire system.&lt;/p&gt;
&lt;p&gt;If a system is expected to provide some guarantee (for example, in a message queue, that the number of incoming messages equals the number of outgoing messages), it can constantly check itself while it is running and raise an alert if a discrepancy is found.&lt;/p&gt;
&lt;h3 id=&quot;expect-the-best-prepare-for-the-worst&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#expect-the-best-prepare-for-the-worst&quot; aria-label=&quot;expect the best prepare for the worst permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Expect the best, prepare for the worst&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Design systems in a way that minimizes opportunities for error. For example, well-designed abstractions, APIs, and admin interfaces make it easy to do “the right thing” and discourage “the wrong thing.” However, if the interfaces are too restrictive people will work around them, negating their benefit, so this is a tricky balance to get right.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Provide fully featured non-production sandbox environments where people can explore and experiment safely, using real data, without affecting real users.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set up detailed and clear monitoring, such as performance metrics and error rates. When a problem occurs, metrics can be invaluable in diagnosing the issue: requests per second to a web server, the ratio of reads to writes in a database, the number of simultaneously active users in a chat room, the hit rate on a cache, or something else.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;twitter-example&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#twitter-example&quot; aria-label=&quot;twitter example permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Twitter example&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Post tweet&lt;/em&gt;: a user can publish a new message to their followers (4.6k requests/sec on average, over 12k requests/sec at peak).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Home timeline&lt;/em&gt;: a user can view tweets posted by the people they follow (300k requests/sec).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Twitter’s scaling challenge is not primarily due to tweet volume, but due to &lt;strong&gt;fan-out&lt;/strong&gt;: each user follows many people, and each user is followed by many people. When a user posts a tweet, the system has to look up all the people who follow that user, and insert the new tweet into each of their home timeline caches. The request to read the home timeline is then cheap, because its result has been computed ahead of time.&lt;/p&gt;
&lt;p&gt;This works better because the average rate of published tweets is almost two orders of magnitude lower than the rate of home timeline reads, and so in this case it’s preferable to do more work at write time and less at read time. But some users have over 30 million followers. This means that a single tweet may result in over 30 million writes to home timelines! Doing this in a timely manner—Twitter tries to deliver tweets to followers within five seconds—is a significant challenge.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/5751d4f14e942d78c731f4d2f5502bbd/d9ed5/post-tweet.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 36.19631901840491%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAIAAACHqfpvAAAACXBIWXMAAFxGAABcRgEUlENBAAAA3UlEQVR42l2Q2XKEIBBF+f8/dNTkwQV1GMUNEdTMgVRZydwHxO6+SyN+/mMcddu2Usqu6zidc8dx7PvOxVrbRFRVta4rw+KDLGX9eCTfEfDhLMuSZVmapq8AVRRF00hjDHyxBjAwO7df17VtxgZgFn45N0rGMOG9vz1oee8EIbXWwzCg8RWQK/WkqJSa5xnyNE11XSdJgu95nj6COoqCzy2GPKNjBEw8if3rj/o9CVCh9bnzX8RsvixLFs7zHGce73ZGWjBBbBqc3G8mKUiOoY7gQk4qvGLf9yxsrX0DrEuRI75uLKQAAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/5751d4f14e942d78c731f4d2f5502bbd/0cbef/post-tweet.avif 163w,
/static/5751d4f14e942d78c731f4d2f5502bbd/bffb7/post-tweet.avif 325w,
/static/5751d4f14e942d78c731f4d2f5502bbd/69c29/post-tweet.avif 650w,
/static/5751d4f14e942d78c731f4d2f5502bbd/6d24a/post-tweet.avif 975w,
/static/5751d4f14e942d78c731f4d2f5502bbd/a2baf/post-tweet.avif 1300w,
/static/5751d4f14e942d78c731f4d2f5502bbd/a40d8/post-tweet.avif 2880w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/5751d4f14e942d78c731f4d2f5502bbd/94563/post-tweet.webp 163w,
/static/5751d4f14e942d78c731f4d2f5502bbd/647a8/post-tweet.webp 325w,
/static/5751d4f14e942d78c731f4d2f5502bbd/c1dc5/post-tweet.webp 650w,
/static/5751d4f14e942d78c731f4d2f5502bbd/1e975/post-tweet.webp 975w,
/static/5751d4f14e942d78c731f4d2f5502bbd/063bf/post-tweet.webp 1300w,
/static/5751d4f14e942d78c731f4d2f5502bbd/d3d72/post-tweet.webp 2880w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/5751d4f14e942d78c731f4d2f5502bbd/222b7/post-tweet.png 163w,
/static/5751d4f14e942d78c731f4d2f5502bbd/ff46a/post-tweet.png 325w,
/static/5751d4f14e942d78c731f4d2f5502bbd/a6d36/post-tweet.png 650w,
/static/5751d4f14e942d78c731f4d2f5502bbd/e548f/post-tweet.png 975w,
/static/5751d4f14e942d78c731f4d2f5502bbd/3c492/post-tweet.png 1300w,
/static/5751d4f14e942d78c731f4d2f5502bbd/d9ed5/post-tweet.png 2880w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/5751d4f14e942d78c731f4d2f5502bbd/a6d36/post-tweet.png&quot;
            alt=&quot;Twitter&amp;#39;s data pipeline for delivering posts. Raffi Krikorian: “Timelines at Scale,” at QCon San Francisco, November 2012.&quot;
            title=&quot;Post tweet&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Post tweet&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;Tweets from any celebrities that a user may follow are fetched separately and merged with that user’s home timeline when it is read. This hybrid approach is able to deliver consistently good performance.&lt;/p&gt;
&lt;h3 id=&quot;measuring-performance-response-time-percentiles&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#measuring-performance-response-time-percentiles&quot; aria-label=&quot;measuring performance response time percentiles permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Measuring Performance: response time percentiles&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;When you increase a load parameter and keep the system resources (CPU, memory, network bandwidth, etc.) unchanged, how is the performance of your system affected?&lt;/li&gt;
&lt;li&gt;When you increase a load parameter, how much do you need to increase the resources if you want to keep performance unchanged?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Both questions require performance numbers.&lt;/p&gt;
&lt;p&gt;In a batch processing system such as Hadoop, we usually care about throughput—the number of records we can process per second, or the total time it takes to run a job on a dataset of a certain size. In online systems, what’s usually more important is the service’s response time.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Latency&lt;/strong&gt; and &lt;strong&gt;response time&lt;/strong&gt; are often used synonymously, &lt;em&gt;but they are not the same&lt;/em&gt;. The response time is what the client sees: besides the actual time to process the request (the service time), it includes network delays and queueing delays. Latency is the duration that a request is waiting to be handled—during which it is latent, awaiting service.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;We therefore need to think of response time not as a single number, but as a &lt;em&gt;distribution of values&lt;/em&gt; that you can measure. The mean is not a very good metric if you want to know your “typical” response time, because it doesn’t tell you how many users actually experienced that delay.&lt;/p&gt;
&lt;p&gt;If your median response time is 200ms, that means half your requests return in less than 200ms, and half your requests take longer than that. The median is also known as the 50th percentile, and sometimes abbreviated as p50. If the 95th percentile response time is 1.5 seconds, that means 95 out of 100 requests take less than 1.5 seconds.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Amazon describes response time requirements for internal services in terms of the 99.9th percentile, even though it only affects 1 in 1,000 requests. This is because the customers with the slowest requests are often those who have the most data on their accounts because they have made many purchases—that is, they’re the most valuable customers!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;You may want to keep a rolling window of response times of requests in the last 10 minutes.&lt;/p&gt;
&lt;h3 id=&quot;bad-effects&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#bad-effects&quot; aria-label=&quot;bad effects permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Bad effects&lt;/h3&gt;
&lt;p&gt;As a server can only process a small number of things in parallel (limited, for example, by its number of CPU cores), it only takes a small number of slow requests to hold up the processing of subsequent requests—an effect sometimes known as &lt;strong&gt;head-of-line blocking&lt;/strong&gt;. Therefore, it is important to measure response times on the client side.&lt;/p&gt;
&lt;p&gt;Even if only a small percentage of backend calls are slow, the chance of getting a slow call increases if an end-user request requires multiple backend calls, and so a higher proportion of end-user requests end up being slow (an effect known as &lt;strong&gt;tail latency amplification&lt;/strong&gt;).&lt;/p&gt;
&lt;h2 id=&quot;2-data-models-and-query-languages&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#2-data-models-and-query-languages&quot; aria-label=&quot;2 data models and query languages permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;2. Data Models and Query Languages&lt;/h2&gt;
&lt;p&gt;The best-known data model today, proposed by Edward Codd in 1970, is data organized into relations (&lt;em&gt;tables&lt;/em&gt; in SQL), where each relation is an unordered collection of tuples (&lt;em&gt;rows&lt;/em&gt; in SQL). The typical use cases for mainframes in the 1960s and 1970s were transaction processing (sales transactions, stock-keeping in warehouses) and batch processing (customer invoicing, payroll).&lt;/p&gt;
&lt;p&gt;Decades later, new use cases and changes in scale brought new solutions to the space.&lt;/p&gt;
&lt;h3 id=&quot;the-birth-of-nosql&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-birth-of-nosql&quot; aria-label=&quot;the birth of nosql permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The Birth of NoSQL&lt;/h3&gt;
&lt;p&gt;NoSQL is the latest attempt to overthrow the relational model’s dominance. The name “NoSQL” is unfortunate, since it doesn’t actually refer to any particular technology—it was originally intended simply as a catchy Twitter hashtag for a meetup on open source, distributed, non-relational databases in 2009.&lt;/p&gt;
&lt;p&gt;There are several driving forces behind the adoption of NoSQL databases, including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A need for greater scalability: very large datasets or write throughput&lt;/li&gt;
&lt;li&gt;A preference for free and open source over commercial products&lt;/li&gt;
&lt;li&gt;Specialized query operations that are not well supported by the relational model&lt;/li&gt;
&lt;li&gt;Frustration with the restrictiveness of relational schemas&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;the-object-relational-impedance-mismatch&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#the-object-relational-impedance-mismatch&quot; aria-label=&quot;the object relational impedance mismatch permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;The Object-Relational Impedance Mismatch&lt;/h3&gt;
&lt;p&gt;Picture the database model of a profile on LinkedIn. It may have multiple one-to-many relations: one user can have many positions, many education entries and many contact info options. This translates into a separate table for each relation, and into multiple joins when constructing the entire profile.&lt;/p&gt;
&lt;p&gt;A JSON representation of this profile has better locality than this multi-table schema. If you want to fetch a profile in the relational example, you need to either perform multiple queries or perform a messy multi-way join between the users table and its subordinate tables. In the JSON representation, all the relevant information is in one place, and one query is sufficient.&lt;/p&gt;
&lt;h3 id=&quot;id-or-text-a-question-of-duplication&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#id-or-text-a-question-of-duplication&quot; aria-label=&quot;id or text a question of duplication permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;ID or text? A question of duplication&lt;/h3&gt;
&lt;p&gt;When you use an ID, the information that is meaningful to humans (millions of users can share the same education entry) is stored in only one place, and everything that refers to it uses an ID (which only has meaning within the database). When you store the text directly, you are duplicating the human-meaningful information in every record that uses it. Anything that is meaningful to humans may need to change sometime in the future—and if that information is duplicated, all the redundant copies need to be updated. That incurs write overheads, and risks inconsistencies. Removing such duplication is the key idea behind &lt;strong&gt;normalization&lt;/strong&gt; in databases.&lt;/p&gt;
&lt;p&gt;Unfortunately, normalizing this data requires many-to-one relationships (many people live in one particular region, many people work in one particular industry), which don’t fit nicely into the document model. In relational databases, it’s normal to refer to rows in other tables by ID, because joins are easy. In document databases, joins are not needed for one-to-many tree structures, and support for joins is often weak.&lt;/p&gt;
&lt;p&gt;Moreover, even if the initial version of an application fits well in a join-free document model, data has a tendency of becoming more interconnected as features are added to applications.&lt;/p&gt;
&lt;h3 id=&quot;what-to-choose-it-depends&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-to-choose-it-depends&quot; aria-label=&quot;what to choose it depends permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What to choose? It depends...&lt;/h3&gt;
&lt;p&gt;The main arguments in favor of the document data model are schema flexibility, better performance due to locality, and that for some applications it is closer to the data structures used by the application. The relational model counters by providing better support for joins, and many-to-one and many-to-many relationships.&lt;/p&gt;
&lt;p&gt;If your application does use many-to-many relationships, the document model becomes less appealing. It’s possible to reduce the need for joins by denormalizing, but then the application code needs to do additional work to keep the denormalized data consistent.&lt;/p&gt;
&lt;h3 id=&quot;schemaless&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#schemaless&quot; aria-label=&quot;schemaless permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Schemaless?&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;No schema means that arbitrary keys and values can be added to a document, and when reading, clients have no guarantees as to what fields the documents may contain.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Document databases are sometimes called schemaless, but that’s misleading, as the code that reads the data usually assumes some kind of structure. A more accurate term is &lt;strong&gt;schema-on-read&lt;/strong&gt; (the structure of the data is implicit, and only interpreted when the data is read), in contrast with schema-on-write (the traditional approach of relational databases, where the schema is explicit and the database ensures all written data conforms to it).&lt;/p&gt;
&lt;p&gt;Schema-on-read is similar to dynamic (runtime) type checking in programming languages, whereas schema-on-write is similar to static (compile-time) type checking.&lt;/p&gt;
&lt;p&gt;On the one hand, changes to the the structure of data in a document database have to be added to application code to handle the old and new documents. On the other hand, in a “statically typed” database schema, you would typically perform a migration, which often requires downtime and is slow. In cases where all records are expected to have the same structure, schemas are a useful mechanism for documenting and enforcing that structure. Otherwise, the schema-on-read approach is more advantageous.&lt;/p&gt;
&lt;h3 id=&quot;storage-locality&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#storage-locality&quot; aria-label=&quot;storage locality permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Storage Locality&lt;/h3&gt;
&lt;p&gt;A document is usually stored as a single continuous string, encoded as JSON for example. If your application often needs to access the entire document, there is a performance advantage to this storage locality. This advantage only applies if you need large parts of the document at the same time. The database typically needs to load the entire document, even if you access only a small portion of it, which can be wasteful on large documents.&lt;/p&gt;
&lt;h3 id=&quot;graph-stuff&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#graph-stuff&quot; aria-label=&quot;graph stuff permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Graph Stuff&lt;/h3&gt;
&lt;p&gt;What if many-to-many relationships are very common in your data? The relational model can handle simple cases of many-to-many relationships, but as the connections within your data become more complex, it becomes more natural to start modeling your data as a graph.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Social graphs&lt;/em&gt;
Vertices are people, and edges indicate which people know each other.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The web graph&lt;/em&gt;
Vertices are web pages, and edges indicate HTML links to other pages.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Graphs are also good for evolvability: as you add features to your application, a graph can easily be extended to accommodate changes in your application’s data structures.&lt;/p&gt;
&lt;h4 id=&quot;graph-queries&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#graph-queries&quot; aria-label=&quot;graph queries permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Graph Queries&lt;/h4&gt;
&lt;p&gt;In a relational database, you usually know in advance which joins you need in your query. In a graph query, you may need to traverse a variable number of edges before you find the vertex you’re looking for—that is, the number of joins is not fixed in advance.&lt;/p&gt;
&lt;p&gt;If the same query can be written in 4 lines in one query language but requires 29 lines in another, that just shows that different data models are designed to satisfy different use cases. It’s important to pick a data model that is suitable for your application.&lt;/p&gt;
&lt;h2 id=&quot;3-storage-and-retrieval&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#3-storage-and-retrieval&quot; aria-label=&quot;3 storage and retrieval permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;3. Storage and Retrieval&lt;/h2&gt;
&lt;p&gt;In order to tune a storage engine to perform well on your kind of workload, you need to have a rough idea of what the storage engine is doing under the hood. There is a big difference between storage engines that are optimized for transactional workloads and those optimized for analytics.&lt;/p&gt;
&lt;h3 id=&quot;an-important-trade-off-writes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#an-important-trade-off-writes&quot; aria-label=&quot;an important trade off writes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;An Important Trade-Off: writes&lt;/h3&gt;
&lt;p&gt;Well-chosen indexes speed up read queries, but every index slows down writes. You can then choose the indexes that give your application the greatest benefit, without introducing more overhead than necessary (i.e. indexes must fit in memory).&lt;/p&gt;
&lt;p&gt;Some indexes, like log-structured indexes, rewrite data multiple times due to their repeated compaction and merging nature. This effect—one write to the database resulting in multiple writes to the disk—is known as &lt;strong&gt;write amplification&lt;/strong&gt;, and has a direct performance cost.&lt;/p&gt;
&lt;p&gt;Another type of indexes, &lt;strong&gt;B-trees&lt;/strong&gt;, are very ingrained in the architecture of databases and provide consistently good performance for many workloads. In new datastores, log-structured indexes are becoming increasingly popular. There is no quick and easy rule for determining which type of storage engine is better for your use case, so it is worth testing empirically.&lt;/p&gt;
&lt;h3 id=&quot;another-trade-off-clustered-indexes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#another-trade-off-clustered-indexes&quot; aria-label=&quot;another trade off clustered indexes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Another Trade-Off: clustered indexes&lt;/h3&gt;
&lt;p&gt;A compromise between a clustered index (storing all row data within the index) and a non-clustered index (storing only references to the data within the index) is known as a covering index or index with included columns.&lt;/p&gt;
&lt;p&gt;As with any kind of duplication of data, clustered and covering indexes can speed up reads, but they require additional storage and can add overhead on writes. Databases also need to go to additional effort to enforce transactional guarantees, because applications should not see inconsistencies due to the duplication.&lt;/p&gt;
&lt;h4 id=&quot;multi-column-indexes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#multi-column-indexes&quot; aria-label=&quot;multi column indexes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Multi-column indexes&lt;/h4&gt;
&lt;p&gt;In a database of weather observations you could have a two-dimensional index (on date, temperature) in order to efficiently search for all the observations during the year 2013 where the temperature was between 25 and 30C. With a one-dimensional index, you would have to either scan over all the records from 2013 (regardless of temperature) and then filter them by temperature, or vice versa. A 2D index could narrow down by timestamp and temperature simultaneously!&lt;/p&gt;
&lt;h3 id=&quot;a-question-of-cost-and-encoding&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#a-question-of-cost-and-encoding&quot; aria-label=&quot;a question of cost and encoding permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;A question of cost and encoding&lt;/h3&gt;
&lt;p&gt;As RAM becomes cheaper, the cost-per-gigabyte argument in favor of disks is eroded. Many datasets are simply not that big, so it’s quite feasible to keep them entirely in memory, potentially distributed across several machines. This has led to the development of in-memory databases.&lt;/p&gt;
&lt;p&gt;Some in-memory key-value stores, such as &lt;em&gt;Memcached&lt;/em&gt;, are intended for caching use only, where it’s acceptable for data to be lost if a machine is restarted. But other in-memory databases aim for durability, which can be achieved with special hardware (such as battery-powered RAM), by writing a log of changes to disk or snapshots to disk.&lt;/p&gt;
&lt;p&gt;Counterintuitively, the performance advantage of in-memory databases is not due to the fact that they don’t need to read from disk. Even a disk-based storage engine may never need to read from disk if you have enough memory, because the operating system caches recently used disk blocks in memory anyway. Rather, they can be faster because they can avoid the overheads of encoding in-memory data structures in a form that can be written to disk.&lt;/p&gt;
&lt;h3 id=&quot;transaction-processing-vs-analytic-systems&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#transaction-processing-vs-analytic-systems&quot; aria-label=&quot;transaction processing vs analytic systems permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Transaction processing vs Analytic systems&lt;/h3&gt;
&lt;p&gt;A transaction needn’t necessarily have ACID properties. Transaction processing just means allowing clients to make low-latency reads and writes—as opposed to batch processing jobs, which only run periodically.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Property&lt;/th&gt;
&lt;th&gt;Transaction processing systems (OLTP)&lt;/th&gt;
&lt;th&gt;Analytic systems (OLAP)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Main read pattern&lt;/td&gt;
&lt;td&gt;Small number of records per query, fetched by key&lt;/td&gt;
&lt;td&gt;Aggregate over large number of records&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Main write pattern&lt;/td&gt;
&lt;td&gt;Random-access, low-latency writes from user input&lt;/td&gt;
&lt;td&gt;Bulk import (ETL) or event stream&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Primarily used by&lt;/td&gt;
&lt;td&gt;End user/customer, via web app&lt;/td&gt;
&lt;td&gt;Internal analyst, for decision support&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;What data represents&lt;/td&gt;
&lt;td&gt;Latest state of data (current point in time)&lt;/td&gt;
&lt;td&gt;History of events that happened over time&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dataset size&lt;/td&gt;
&lt;td&gt;Gigabytes to terabytes&lt;/td&gt;
&lt;td&gt;Terabytes to petabytes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;In the early 1990s, there was a trend for companies to stop using their OLTP systems for analytics purposes, and to run the analytics on a separate database instead. This separate database was called a &lt;em&gt;data warehouse&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id=&quot;data-warehousing&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#data-warehousing&quot; aria-label=&quot;data warehousing permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Data Warehousing&lt;/h3&gt;
&lt;p&gt;OLTP systems (i.e. checkout, inventory, etc) are expected to be highly available and to process transactions with low latency, since they are critical for business. It&apos;s a bad idea to let business analysts run ad hoc analytic queries on an OLTP database, since those queries are often expensive, which can harm the performance of concurrently executing transactions.&lt;/p&gt;
&lt;p&gt;A data warehouse, by contrast, is a separate database that analysts can query without affecting OLTP operations. It contains read-only copy of the data in all the various OLTP systems in the company.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/0ce7cf43dd02f2a84b1fd702e19c264e/5a791/warehouse.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 69.93865030674846%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAOCAYAAAAvxDzwAAAACXBIWXMAABYlAAAWJQFJUiTwAAABmElEQVR42m2T626DMAyFef8nXP+OFQh3aAOUAhmfIyNXmyVELvbxsU+cNE0d1nUN2LZtYRzH0HVteD6fwdrj8Qj3+08oy/Lyx5ZlCUWRB++jf4IjQNi+72GeZwl4v98fgJw75wTY2uv1CpDy3kfA4zgEaFlmcR7HQbICyN00TeLcdZ2sAVBm+Pd9f577M+EkxBKy4sjnXBGyLAtt2wojAGlBVVVSVpp+SzswWlIUhbDO81zWkEjK0klW0AEho5YPIE60gHtYKkP2fMMQK8LwT0AnuG2bk91dytA28AcMhmmaSjIbzFmsZpK9ABJgg+mHZchfGVGmFZA16vK/AFUtNmSnbN3bj2SIY4MxFUoTJ1b+uq4vlXEEHADAuMvzTFoS773EwJo7/AWQRts3Bwj9pLc4UhI+7FEcMAXHTytSS3gqqpztnZbNKwAEQRCnrpuLgO2xAXTXdMQJiSKRhHOCASMxYwe4ThJ+fwApg7d0u31JWXFK1vOsl5HS+d62CBxbUckAcG4F+hDFqqdZdQ8breI49ovZfwx/AWz1QlwSmqbEAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/0ce7cf43dd02f2a84b1fd702e19c264e/0cbef/warehouse.avif 163w,
/static/0ce7cf43dd02f2a84b1fd702e19c264e/bffb7/warehouse.avif 325w,
/static/0ce7cf43dd02f2a84b1fd702e19c264e/69c29/warehouse.avif 650w,
/static/0ce7cf43dd02f2a84b1fd702e19c264e/6d24a/warehouse.avif 975w,
/static/0ce7cf43dd02f2a84b1fd702e19c264e/8ed15/warehouse.avif 1248w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/0ce7cf43dd02f2a84b1fd702e19c264e/94563/warehouse.webp 163w,
/static/0ce7cf43dd02f2a84b1fd702e19c264e/647a8/warehouse.webp 325w,
/static/0ce7cf43dd02f2a84b1fd702e19c264e/c1dc5/warehouse.webp 650w,
/static/0ce7cf43dd02f2a84b1fd702e19c264e/1e975/warehouse.webp 975w,
/static/0ce7cf43dd02f2a84b1fd702e19c264e/1b8e7/warehouse.webp 1248w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/0ce7cf43dd02f2a84b1fd702e19c264e/222b7/warehouse.png 163w,
/static/0ce7cf43dd02f2a84b1fd702e19c264e/ff46a/warehouse.png 325w,
/static/0ce7cf43dd02f2a84b1fd702e19c264e/a6d36/warehouse.png 650w,
/static/0ce7cf43dd02f2a84b1fd702e19c264e/e548f/warehouse.png 975w,
/static/0ce7cf43dd02f2a84b1fd702e19c264e/5a791/warehouse.png 1248w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/0ce7cf43dd02f2a84b1fd702e19c264e/a6d36/warehouse.png&quot;
            alt=&quot;Simplified outline of ETL into a data warehouse. Figure 3-8.&quot;
            title=&quot;Data Warehousing&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Data Warehousing&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;Even though data warehouse and OLTP databases share an SQL interface, they differ in their query optimizations, leading to specialization for transaction processing or analytics workloads by most vendors (but not both).&lt;/p&gt;
&lt;h4 id=&quot;separate-table-of-dates&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#separate-table-of-dates&quot; aria-label=&quot;separate table of dates permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Separate table of dates&lt;/h4&gt;
&lt;p&gt;Date and time are often represented using dimension tables (a subset of fact tables), because this allows additional information about dates (such as public holidays) to be encoded, allowing queries to differentiate between sales on holidays and non-holidays.&lt;/p&gt;
&lt;h3 id=&quot;columnar-storage&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#columnar-storage&quot; aria-label=&quot;columnar storage permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Columnar Storage&lt;/h3&gt;
&lt;p&gt;When your queries require sequentially scanning across a large number of rows, it becomes important to encode data very compactly, to minimize the amount of data that the query needs to read from disk.&lt;/p&gt;
&lt;p&gt;The idea behind column-oriented storage is simple: don’t store all the values from one row together, but store all the values from each column together instead. If each column is stored in a separate file, a query only needs to read and parse those columns that are used in that query, which can save a lot of work.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Column storage is easiest to understand in a relational data model, but it applies equally to non-relational data. For example, Parquet is a columnar storage format that supports a document data model, based on Google’s Dremel.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h4 id=&quot;datadatadata-data-cubes&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#datadatadata-data-cubes&quot; aria-label=&quot;datadatadata data cubes permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Data^Data^Data: Data Cubes&lt;/h4&gt;
&lt;p&gt;A common special case of a materialized view is known as a data cube or OLAP cube.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A materialized view is an actual copy of query results written to disk, unlike a virtual view, which is a shortcut for writing queries, as the SQL engine expands it into the underlying query on-the-fly when read.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The advantage of a materialized data cube is that certain queries become very fast because they have effectively been precomputed. For example, if you want to know the total sales per store yesterday, you just need to look at the totals along the appropriate dimension—no need to scan millions of rows.&lt;/p&gt;
&lt;p&gt;The disadvantage is that a data cube doesn’t have the same flexibility as querying the raw data. For example, there is no way of calculating which proportion of sales comes from items that cost more than $100, because the price isn’t one of the dimensions. Most data warehouses therefore try to keep as much raw data as possible, and use aggregates such as data cubes only as a performance boost for certain queries.&lt;/p&gt;
&lt;h2 id=&quot;4-encoding-and-evolvability&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#4-encoding-and-evolvability&quot; aria-label=&quot;4 encoding and evolvability permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;4. Encoding and Evolvability&lt;/h2&gt;
&lt;h3 id=&quot;scenarios-in-which-data-encodings-are-important&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#scenarios-in-which-data-encodings-are-important&quot; aria-label=&quot;scenarios in which data encodings are important permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Scenarios in which data encodings are important&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Databases, where the process writing encodes the data and the process reading decodes it&lt;/li&gt;
&lt;li&gt;RPC and REST APIs, where the client encodes a request, the server decodes it and encodes a response, and the client finally decodes the response&lt;/li&gt;
&lt;li&gt;Asynchronous message passing (using message brokers), where nodes communicate by sending each other messages that are encoded by the sender and decoded by the recipient&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;a-bit-of-care&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#a-bit-of-care&quot; aria-label=&quot;a bit of care permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;A bit of care&lt;/h3&gt;
&lt;p&gt;Relational databases generally assume that all data in the database conforms to one schema at any one point in time. By contrast, &lt;strong&gt;schema-on-read&lt;/strong&gt; (“schemaless”) databases don’t enforce a schema, so the database can contain a mixture of older and newer data formats written at different times.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;With server-side applications you may want to perform a rolling upgrade of nodes. This allows new versions to be deployed without service downtime, and thus encourages more frequent releases and better evolvability.&lt;/li&gt;
&lt;li&gt;With client-side applications you’re at the mercy of the user, who may not install the update for some time!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Backward compatibility&lt;/strong&gt;
Newer code can read data that was written by older code.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Forward compatibility&lt;/strong&gt;
Older code can read data that was written by newer code.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The JSON returned by Twitter’s API includes tweet IDs twice, once as a JSON number and once as a decimal string, to work around the fact that the numbers are not correctly parsed by JavaScript applications&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&quot;formats-for-encoding-data&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#formats-for-encoding-data&quot; aria-label=&quot;formats for encoding data permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Formats for Encoding Data&lt;/h3&gt;
&lt;p&gt;Programs usually work with data in two different representations:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In memory, data is kept in objects, structs, lists, arrays, hash tables, trees, and so on. These data structures are optimized for efficient access and manipulation by the &lt;strong&gt;CPU&lt;/strong&gt; (typically using pointers).&lt;/li&gt;
&lt;li&gt;When you want to write data to a file or send it over the network, you have to encode it as some kind of self-contained sequence of bytes (for example, a JSON document). Since a pointer wouldn’t make sense to any other process, this &lt;strong&gt;sequence-of-bytes&lt;/strong&gt; representation looks quite different from the data structures that are normally used in memory.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;dont-use-your-languages-built-in-encoding&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#dont-use-your-languages-built-in-encoding&quot; aria-label=&quot;dont use your languages built in encoding permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Don&apos;t use your language&apos;s built-in encoding&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;If an attacker can get your application to decode an arbitrary byte sequence, they can instantiate arbitrary classes.&lt;/li&gt;
&lt;li&gt;Efficiency (CPU time taken to encode or decode, and the size of the encoded structure) is also often an afterthought. For example, Java’s built-in serialization is notorious for its bad performance and bloated encoding.&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Revelatory Facts in 'Why We Sleep']]></title><description><![CDATA[A post to learn and reflect about a crutial aspect of life: sleep.]]></description><link>https://www.j1nma.com/why-we-sleep/</link><guid isPermaLink="false">https://www.j1nma.com/why-we-sleep/</guid><pubDate>Sun, 03 Sep 2023 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;Matthew Walker’s book, “Why We Sleep,” is a real game-changer. All the cool stuff I’m sharing comes straight from him or the authors he quotes. And hey, I might’ve rephrased some things to make it easier to understand.&lt;/p&gt;
&lt;p&gt;Turns out, sleep is super crucial for everything we do! If we don’t get enough shut-eye, our thinking gets fuzzy, and our memory goes bust. Plus, it messes with our health big time, making us more prone to all sorts of problems.&lt;/p&gt;
&lt;p&gt;Let me me share with you the facts and practices that most caught my attention after reading the book, and, in the last part, I will talk about some insights about my last 4 years of sleep (hint: they are not good).&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Most of the sentences in this text were extracted and readapted. All ideas and quotes are found on the pages of the book.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;!-- MarkdownTOC autolink=true --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#part-1-this-thing-called-sleep&quot;&gt;Part 1: This Thing Called Sleep&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#c1-to-sleep&quot;&gt;C1: To Sleep&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c2-caffeine-jet-lag-and-melatonin-losing-and-gaining-control-of-your-sleep-rhythm&quot;&gt;C2: Caffeine, jet lag, and melatonin: losing and gaining control of your sleep rhythm&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c3-defining-and-generating-sleep&quot;&gt;C3: Defining and generating sleep&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c4-ape-beds-dinosaurs-and-napping-with-half-a-brain-who-sleeps-how-do-we-sleep-and-how-much&quot;&gt;C4: Ape beds, dinosaurs, and napping with half a brain: who sleeps, how do we sleep, and how much?&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#to-dream-or-not-to-dream&quot;&gt;To dream or not to dream&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#how-should-we-sleep&quot;&gt;How should we sleep&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c5-changes-in-sleep-across-the-life-span&quot;&gt;C5: Changes in sleep across the life span&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#sleep-after-birth&quot;&gt;Sleep after birth&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sleep-and-adolescence&quot;&gt;Sleep and adolescence&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#part-2-why-should-you-sleep&quot;&gt;Part 2: Why Should You Sleep?&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#c6-your-mother-and-shakespeare-knew&quot;&gt;C6: Your Mother and Shakespeare Knew&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#sleep-to-forget&quot;&gt;Sleep to forget?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#practice-alone-does-not-make-perfect&quot;&gt;Practice alone does not make perfect&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sleep-and-sport&quot;&gt;Sleep and Sport&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sleep-for-creativity&quot;&gt;Sleep for Creativity&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c7-too-extreme-for-the-guinness-book-of-world-records&quot;&gt;C7: Too extreme for the Guinness book of world records&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#sleep-deprivation-and-the-brain&quot;&gt;Sleep deprivation and the brain&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#you-do-not-know-how-sleep-deprived-you-are-when-you-are-sleep-deprived&quot;&gt;You do not know how sleep-deprived you are when you are sleep-deprived&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sleep-and-alzheimer%E2%80%99s-disease&quot;&gt;Sleep and Alzheimer’s disease&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c8-cancer-heart-attacks-and-a-shorter-life&quot;&gt;C8: Cancer, heart attacks, and a shorter life&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#sleep-deprivation-and-the-body&quot;&gt;Sleep deprivation and the body&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sleep-loss-and-metabolism-diabetes-and-weight-gain&quot;&gt;Sleep loss and metabolism: diabetes and weight gain&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#part-3-how-and-why-we-dream&quot;&gt;Part 3: How and Why We Dream&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#c9-routinely-psychotic&quot;&gt;C9: Routinely Psychotic&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#part-4-from-sleeping-pills-to-society-transformed&quot;&gt;Part 4: From Sleeping Pills to Society Transformed&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#c15-sleep-and-society&quot;&gt;C15: Sleep and Society&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#sleep-and-education&quot;&gt;Sleep and education&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#sleep-and-health-care&quot;&gt;Sleep and Health Care&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#c16-a-new-vision-for-sleep-in-the-twenty-first-century&quot;&gt;C16:  A New Vision for Sleep in the Twenty-First Century&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#public-policy-and-societal-change&quot;&gt;Public Policy and Societal Change&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#my-data-what-can-i-learn-from-4-years-of-sleep-tracking&quot;&gt;My Data: What can I learn from 4 years of sleep tracking?&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#sleep-quality&quot;&gt;Sleep Quality&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#regularity&quot;&gt;Regularity&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#went-to-bed&quot;&gt;Went to Bed&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#efficiency&quot;&gt;Efficiency&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#asleep&quot;&gt;Asleep&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#farewell&quot;&gt;Farewell&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- /MarkdownTOC --&gt;
&lt;h1 id=&quot;part-1-this-thing-called-sleep&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#part-1-this-thing-called-sleep&quot; aria-label=&quot;part 1 this thing called sleep permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Part 1: This Thing Called Sleep&lt;/h1&gt;
&lt;h2 id=&quot;c1-to-sleep&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c1-to-sleep&quot; aria-label=&quot;c1 to sleep permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C1: To Sleep&lt;/h2&gt;
&lt;p&gt;Routinely sleeping less than six hours demolishes your immune system. This affected lifestyle increases the likelihood you will develop Alzheimer’s disease, blood sugar level disruptions, pre-diabetes, blocked arteries, and multiple other complications.&lt;/p&gt;
&lt;p&gt;The WHO even declared a sleep loss epidemic throughout industrialized nations— nevermind coronavirus.&lt;/p&gt;
&lt;p&gt;Sleep is no joke. After all, one third of our entire lives will be spent sleeping. That’s about 25 years out of a life expectancy of 75. 25 years! And each second is very much needed! But it is puzzling in its own way. While we sleep, we cannot reproduce, nurture, protect ourselves or others, work, study, laugh, cry, nothing albeit sleep. It’s a time of complete vulnerability.&lt;/p&gt;
&lt;p&gt;Still, the benefits are unavoidable to our brains and bodies. Sleeping allows us to navigate next-day social and psychological challenges with cool-header composure. I imagine you can notice the difference in your mood and sharpness whenever you went through hours of no sleep.&lt;/p&gt;
&lt;p&gt;This are not shiny, unfounded words. Science is increasingly experimenting and observing the consequences of irregular, &lt;em&gt;bad&lt;/em&gt; sleep. By studying sleep wave recordings, researchers can potentially diagnose which type of dementia a sleep deprived person can develop.&lt;/p&gt;
&lt;h2 id=&quot;c2-caffeine-jet-lag-and-melatonin-losing-and-gaining-control-of-your-sleep-rhythm&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c2-caffeine-jet-lag-and-melatonin-losing-and-gaining-control-of-your-sleep-rhythm&quot; aria-label=&quot;c2 caffeine jet lag and melatonin losing and gaining control of your sleep rhythm permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C2: Caffeine, jet lag, and melatonin: losing and gaining control of your sleep rhythm&lt;/h2&gt;
&lt;p&gt;I have always been an owl. That is, I am the &lt;em&gt;owlness&lt;/em&gt; chronotype, not the &lt;em&gt;larkness&lt;/em&gt; one. Whether you are a night owl like me or a morning lark, it is believed to be strongly linked to genetics (you probably share any with one or both your parents).&lt;/p&gt;
&lt;p&gt;Sadly, society (and parents most of the time) treats labels us as lazy, since we won’t wake up early in the day. Morning larks go to the extent of criticizing owls, citing their lack of ‘willingness and discipline’, as if owls deliberately chose such chronotype. This is unfair and wrong: night owls are not such by choice, but by genetics. They are bound to a delayed schedule by &lt;strong&gt;unavoidable&lt;/strong&gt; DNA hardwiring. It is not the owls’ conscious fault, but their genetic fate.&lt;/p&gt;
&lt;p&gt;Besides, think about this trait in terms of survival. What if we were all owls or all larks? We would all leave a window of time were we are fully asleep, and thus completely vulnerable to threats and attacks. Mother Nature seems to have triggered a smarted move. By spreading us between the two chronotypes, we increase our survival fitness, with ‘guards’ on call on every hour.&lt;/p&gt;
&lt;p&gt;Another interest comment is that on the difference we experience when travel either west or east. When we travel westward, in the direction of our internal clock (our circadian rhythm), that “day” is longer than 24 hours and it feels easier to accommodate to. However, if we travel eastward, the “day” seems shorter, goes against our clock, and thus feels rather harder to adapt to.&lt;/p&gt;
&lt;p&gt;Watchout for caffeine consumption. By hijacking and occupying these receptors, caffeine blocks the sleepiness signal normally communicated to the brain by adenosine. The upshot: caffeine tricks you into feeling alert and awake, despite the high levels of adenosine that would otherwise seduce you into sleep.&lt;/p&gt;
&lt;p&gt;Caffeine has an average half-life of 5 to 7 hours. Let&apos;s say that you have a cup of coffee after your evening dinner, around 7:30 PM. This means that by 1:30 AM, 50% of the caffeine may still be active and circulating throughout your brain tissue. In other words, by 1:30 AM, you&apos;re only halfway to completing the job of cleansing your brain of the caffeine you drink after dinner.&lt;/p&gt;
&lt;p&gt;Also be aware that de-caffeinated does not mean non-caffeinated. One cup of decaf usually contains 15% to 30% of the dose of a regular cup of coffee, which is far from caffeine free. Should you drink 3 to 4 cups of decaf in the evening, it is just as damaging to your sleep as one regular cup of coffee.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 462px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/02027a8dc4d98bc1dedf1781a926c845/e389b/two-factors.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 74.23312883435584%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB7klEQVR42m2UB6tCMQyF+/9/kYgigop74d4L9947jy+Qx30+C6XtTXqSc5JeJ1/G+/3W9Xg8ynq9ltVqJZFIRDKZjMTjcUmlUpJOpyWZTOq5WCyq72KxEOcFsfl6vfTb5XKRyWQio9FIms2m1Go1aTQa0mq19Nzr9aTf70u321W/P4DfBsBkt9ls5Ha7yfV61SDelUl25ueM3uFwkHK5LNVqVaPu93t5Pp9qA8z8PgPe73edNv4AQqfdbstwONTI7KEHpdPppKCAPx4P2W63akcG73DfigEdnKfTqczncw1EcciarNALO0lUKhUNYvfdJxhO2WxWNTG6AALGHgCmyQEb5i8g6bNhZaAjFBF4uVzqRcA6nY4kEgmp1+tyPp+1ogRHPzSnE8jeoUGhUNALOHAZ/TCiE60BXVZahUEQEhiPxzIYDNROIlTb4cQBWmQKGA7M3W6nmZRKJaXpbXSzA4hEs9lMGTmokRVGMgTA2yLYDYACeW1Q5xt3KSDnf1U2LW1wtgKY3l5/NLTXhd2RFe80l8spNagjQzQa1X0+n9de5P1i593S/LFYTPd8501TB80QVBwAtHeJ2BSL1d4uGgLAxAfdmFQdH+5rUT77kD+Kz+eTcDis0UOhkDIIBALi9/slGAyqDQY0t/cuL+UHa1VnFPmVyV8AAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/02027a8dc4d98bc1dedf1781a926c845/0cbef/two-factors.avif 163w,
/static/02027a8dc4d98bc1dedf1781a926c845/bffb7/two-factors.avif 325w,
/static/02027a8dc4d98bc1dedf1781a926c845/28233/two-factors.avif 462w&quot;
              sizes=&quot;(max-width: 462px) 100vw, 462px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/02027a8dc4d98bc1dedf1781a926c845/94563/two-factors.webp 163w,
/static/02027a8dc4d98bc1dedf1781a926c845/647a8/two-factors.webp 325w,
/static/02027a8dc4d98bc1dedf1781a926c845/c589b/two-factors.webp 462w&quot;
              sizes=&quot;(max-width: 462px) 100vw, 462px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/02027a8dc4d98bc1dedf1781a926c845/222b7/two-factors.png 163w,
/static/02027a8dc4d98bc1dedf1781a926c845/ff46a/two-factors.png 325w,
/static/02027a8dc4d98bc1dedf1781a926c845/e389b/two-factors.png 462w&quot;
            sizes=&quot;(max-width: 462px) 100vw, 462px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/02027a8dc4d98bc1dedf1781a926c845/e389b/two-factors.png&quot;
            alt=&quot;Two Factors&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Two Factors&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;Setting aside the extreme case of sleep deprivation, how do you know that are your routine getting enough sleep? While a sleep assessment is needed to thoroughly address this issue, an easy rule of thumb is to answer two simple questions. First, after waking up in the morning, could you fall back asleep at 10 or 11 AM? If the answer is “yes”, you are likely not getting sufficient sleep quantity and/or quality. Second, can you function optimally without caffeine before noon? If the answer is “no”, then you are most likely self-medicating your state of chronic sleep deprivation.&lt;/p&gt;
&lt;h2 id=&quot;c3-defining-and-generating-sleep&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c3-defining-and-generating-sleep&quot; aria-label=&quot;c3 defining and generating sleep permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C3: Defining and generating sleep&lt;/h2&gt;
&lt;p&gt;The two stages of sleep NREM and REM play out in a recurring push-pull battle of brain domination across the night. The cerebral war between the two is one and lost every 90 minutes, rolled first by NREM sleep, followed by the comeback of REM sleep.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/70c86b2fdbef5f602bedbe64ae9a9a68/6c2f2/architecture-of-sleep.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 49.69325153374233%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsTAAALEwEAmpwYAAABRElEQVR42m2SiY6CUAxF+f//g2BQAVkUBJFdAenkNHkEkmnSdKG9ve3Dkp2s66q26zpxXVd831f1PE8cx1H/crmIbdvyfr8PPUYs+UeGYZCqqjbbtq0qft/3Ute1DkV+v598v98N+ABIEcUoYPM8y+v10gYUQHKfz0d9ctRRT25ZliNgEAS6GkIxbJCyLCWOY/VhSrOpL4pCWfKdHgUcx1Gez6ekaboBRlEkSZKoH4ahPB6PrZFN6KGGPFuY4Za5GYW3200fAyGmwTAhhh0A5GHWNI3mAWcYd7TY/3w+a9P1etUX5QWZmue5MgeI+H6/a2OWZQqGz90QbqsMp2nSqUxkRUDM4VkDa46PJYYRfeSw1OMz4PAoFLMONzudTsqIYdwWy3pYTsNDQQDmfCdmW8v8nCgTjLKKySMwYRhnYYv9T723f1Fe/0ECsTRaAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/70c86b2fdbef5f602bedbe64ae9a9a68/0cbef/architecture-of-sleep.avif 163w,
/static/70c86b2fdbef5f602bedbe64ae9a9a68/bffb7/architecture-of-sleep.avif 325w,
/static/70c86b2fdbef5f602bedbe64ae9a9a68/69c29/architecture-of-sleep.avif 650w,
/static/70c86b2fdbef5f602bedbe64ae9a9a68/b2575/architecture-of-sleep.avif 767w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/70c86b2fdbef5f602bedbe64ae9a9a68/94563/architecture-of-sleep.webp 163w,
/static/70c86b2fdbef5f602bedbe64ae9a9a68/647a8/architecture-of-sleep.webp 325w,
/static/70c86b2fdbef5f602bedbe64ae9a9a68/c1dc5/architecture-of-sleep.webp 650w,
/static/70c86b2fdbef5f602bedbe64ae9a9a68/e0ad8/architecture-of-sleep.webp 767w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/70c86b2fdbef5f602bedbe64ae9a9a68/222b7/architecture-of-sleep.png 163w,
/static/70c86b2fdbef5f602bedbe64ae9a9a68/ff46a/architecture-of-sleep.png 325w,
/static/70c86b2fdbef5f602bedbe64ae9a9a68/a6d36/architecture-of-sleep.png 650w,
/static/70c86b2fdbef5f602bedbe64ae9a9a68/6c2f2/architecture-of-sleep.png 767w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/70c86b2fdbef5f602bedbe64ae9a9a68/a6d36/architecture-of-sleep.png&quot;
            alt=&quot;Architecture of sleep&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Architecture of sleep&lt;/figcaption&gt;
  &lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;In the first half of the night, the vast majority of our 90 minute cycles are consumed by deep NREM sleep, and very little by REM sleep, as can be seen in cycle one of the figure above. But as we transition through into the second half of the night, this seesaw balance shifts, with most of the time dominated by REM sleep, with little, if any, deep NREM sleep. Cycle 5 is a perfect example of this REM-rich type of sleep.&lt;/p&gt;
&lt;p&gt;A key function of deep NREM sleep, which predominates early in the night, is to do the work of weeding out and removing unnecessary neural connections. In contrast, the dreaming stage of REM sleep, which prevails later in the night, plays a role in strengthening those connections.&lt;/p&gt;
&lt;p&gt;When you decide to sleep full eight hours of sleep starting from midnight but you decide to wake up at 6 AM instead of 8 AM you will lose 60 to 90% of all your REM sleep, even though you are losing 25% of your total sleep time.&lt;/p&gt;
&lt;p&gt;NREM sleep is one of the most epic display of neural coordination that we know of. Many thousands of brain cells have all decided to unite and fire at the same time.&lt;/p&gt;
&lt;p&gt;Each night, the long range brain waves of deep sleep will move memory packets (recent experiences) from short-term storage site, which is fragile, to a more permanent, and thus safer, long-term storage location.&lt;/p&gt;
&lt;p&gt;When it comes to information processing, think of the wake state principally as reception, NREM sleep as reflection, and REM sleep as integration.&lt;/p&gt;
&lt;p&gt;By eliminating muscle activity during REM sleep you are prevented from acting out your dream experience. Wise, then, of Mother Nature to have tailored a physiological straight jacket that forbids fictional movements from becoming a reality, specially considering that you have stopped consciously perceiving your surroundings.&lt;/p&gt;
&lt;h2 id=&quot;c4-ape-beds-dinosaurs-and-napping-with-half-a-brain-who-sleeps-how-do-we-sleep-and-how-much&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c4-ape-beds-dinosaurs-and-napping-with-half-a-brain-who-sleeps-how-do-we-sleep-and-how-much&quot; aria-label=&quot;c4 ape beds dinosaurs and napping with half a brain who sleeps how do we sleep and how much permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C4: Ape beds, dinosaurs, and napping with half a brain: who sleeps, how do we sleep, and how much?&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;Theodosius Dobzhansky: Nothing in biology makes sense except in light of evolution&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Considering how biologically beneficial the state of sleep is, we can pose a very different theory: sleep was the first stage of life on this planet, and it was from sleep  that wakefulness emerged. It may be a preposterous hypothesis, and one that nobody is taking seriously or exploring, but I personally do not think it to be entirely unreasonable.&lt;/p&gt;
&lt;p&gt;As millennia unfolded and evolution crowned its current accomplishment with the genesis of the brain, the demand for sleep only increased, tending to the needs of this most precious of all physiological apparatus. It can be suggested that one evolutionary function that demands more also is the need to service an increasingly complex nervous system.&lt;/p&gt;
&lt;h3 id=&quot;to-dream-or-not-to-dream&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#to-dream-or-not-to-dream&quot; aria-label=&quot;to dream or not to dream permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;To dream or not to dream&lt;/h3&gt;
&lt;p&gt;Insects, fish and most reptiles show no queer signs of REM sleep. Only birds and mammals have full-blown REM sleep. It suggests that dream (REM sleep) is the new kid on the evolutionary block. REM sleep seems to have emerged to support functions that are NREM sleep alone could not accomplish, or that REM sleep was more efficient at accomplishing.&lt;/p&gt;
&lt;p&gt;It is important to note that regardless of the amount of recovery opportunity, the brain never comes close to getting back all the sleep it has lost. This is true for total sleep time, just as it is for NREM sleep and for REM sleep. That humans can never “sleep back” that which we have previously lost is one of the most important take-homes of this book, the saddening consequences of which I will describe in chapter 7 and 8.&lt;/p&gt;
&lt;p&gt;Cetaceans, such as dolphins and whales, have sleep which is only NREM, which can be &lt;em&gt;unihemispheric&lt;/em&gt;, meaning they will sleep with half of the brain at a time! One half always stays awake to maintain life necessary movement, but the other half of the brain will fall into NREM sleep.&lt;/p&gt;
&lt;p&gt;Even more, in-flight migrating birds will grab remarkably brief periods of sleep lasting only seconds in duration. This ultra power naps are just sufficient to avert the ruinous brain and body deficits that what otherwise ensure from prolonged total sleep deprivation.&lt;/p&gt;
&lt;h3 id=&quot;how-should-we-sleep&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-should-we-sleep&quot; aria-label=&quot;how should we sleep permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How should we sleep&lt;/h3&gt;
&lt;p&gt;Hunter-gatherer tribes, whose way of life has changed little over the past thousands of years, sleep in a &lt;em&gt;biphasic&lt;/em&gt; pattern. These groups take a similarly longer to sleep period at night, greater than the average of Western cultures, filled by a 30 to 60 minute nap in the afternoon.&lt;/p&gt;
&lt;p&gt;Not enjoying a full afternoon nap, further contributes to our state of sleep bankruptcy.&lt;/p&gt;
&lt;p&gt;The practice of biphasic sleep is not cultural in origin, it is deeply biological.
All humans have a genetically hardwire dip in alertness that occurs in the midafternoon hours. We all experience a brief dissent from high degree wakefulness to low level alertness after the midday meal. Should you ever have to give a presentation at work, for your own sake – and then of the conscious state of your listeners – if you can, avoid the afternoon slot!&lt;/p&gt;
&lt;p&gt;There is genetic evidence that the true painter of biphasic sleep consists of continuous sleep at night, followed by a shorter midafternoon nap.&lt;/p&gt;
&lt;p&gt;A study made in more than 23,000 Greek adults consisted of tracking the group across a six-year period as the siesta practice came to an end for many of them.&lt;/p&gt;
&lt;p&gt;Does that abandoned regular siestas went on to suffer at 37% increase risk of death from heart disease across the six year period, relative to those who maintained regular daytime naps. The effect was specially strong in workingmen, were the ensuing mortality risk of not napping increased by well over 60%.&lt;/p&gt;
&lt;p&gt;It is perhaps surprising that in the small enclaves of Greece were siestas still remain intact, men are nearly 4 times as likely to reach the age of 90 as American males.&lt;/p&gt;
&lt;p&gt;NREM sleep helps transfer and make safe newly learned information into long-term storage sites of the brain. But it is REM sleep that takes these freshly minted memories and begins colliding them with the entire back catalogue of your life’s autobiography.&lt;/p&gt;
&lt;p&gt;REM sleep dreaming therefore represents tenable new contributing factor, among others, that led to our astonishingly rapid evolutionary rise to power, for better and worse, a new sleep-fueled, globally dominant social superclass!&lt;/p&gt;
&lt;h2 id=&quot;c5-changes-in-sleep-across-the-life-span&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c5-changes-in-sleep-across-the-life-span&quot; aria-label=&quot;c5 changes in sleep across the life span permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C5: Changes in sleep across the life span&lt;/h2&gt;
&lt;h3 id=&quot;sleep-after-birth&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sleep-after-birth&quot; aria-label=&quot;sleep after birth permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sleep after birth&lt;/h3&gt;
&lt;p&gt;Depriving infants rats of REM sleep stalled construction of their neural rooftop-the cerebral cortex of the brain. Day after day, the half-finished roofline of the sleep-starved cerebral cortex shows no growth change.&lt;/p&gt;
&lt;p&gt;Infants and young children who show signs of autism, or who are diagnosed with autism, do not have normal sleep patterns or amounts. The circadian rhythms of autistic children are also weaker than their non-autistic counterparts, showing a flatter profile of melatonin across the 24 hour period rather than a powerful rise in concentration at night and rapid fall throughout the day.&lt;/p&gt;
&lt;p&gt;Autistic individuals show a 30% to 50% deficit in the amount of REM sleep they obtain, relative to children without autism.
Irrespective of casuality issues, tracking sleep abnormalities represents a new diagnostic hope for the early detection of autism.&lt;/p&gt;
&lt;p&gt;The newborns of heavy drinking mothers spent far less time in the active state of REM sleep compared with infants of similar age but who were born of mothers who did not drink during pregnancy. Besides, infants of heavy drinking mothers showed a 200% reduction of vibrant electrical activity relative to the infants born of non-alcohol-consuming mothers.
When babies consume alcohol laced milk, their sleep is more fragmented, they spend more time awake, and they suffer a 20 to 30% suppression of REM sleep soon after.&lt;/p&gt;
&lt;h3 id=&quot;sleep-and-adolescence&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sleep-and-adolescence&quot; aria-label=&quot;sleep and adolescence permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sleep and adolescence&lt;/h3&gt;
&lt;p&gt;Even though the degree of neural networks connectivity decreases during development, the physical size of our brain cells, and thus the physical size of the brain and head, increases. Adolescents have a less rational version of an adult brain, one that takes more risks and has relatively poor decision making skills.&lt;/p&gt;
&lt;p&gt;Deep sleep may be a driving force of brain maturation, not the other way around. Rationality is one of the last things to flourish in teenagers, as it is the last brain territory to receive sleep’s maturational treatment.&lt;/p&gt;
&lt;p&gt;The circadian rhythm of a teenager will not be miraculously coaced into a change. Asking that same teenager to wake up at seven the next morning and function with intellect, grace, and good mood is the equivalent of asking you, their parent, to do the same at 4 or 5 AM.&lt;/p&gt;
&lt;p&gt;Passing into your mid- and late 40s, age will have stripped you of 60% to 70% of the deep sleep you were enjoying as a young teenager. By the time you reach 70 years old, you will have lost 80 to 90% of your youthful deep sleep.&lt;/p&gt;
&lt;p&gt;Many seniors progress through their later years not fully realizing how degraded their deep sleep quantity and quality have become. This is an important point: it means that elderly individuals fail to connect their deterioration in health with their deterioration in sleep, despite casual links between the two having been known to scientists for many decades.&lt;/p&gt;
&lt;p&gt;Any individual, no matter what age, will exhibit physical ailments, mental health instability, reduced alertness, and impaired memory if their sleep is chronically disrupted.&lt;/p&gt;
&lt;p&gt;The third sleep change with advanced age is that of circadian timing. In sharp contrast to adolescents, seniors commonly experience a regression in sleep timing, leading to earlier and earlier bedtimes. The cause is an earlier evening release and peak of melatonin as we get older, instructing an earlier start time for sleep. Restaurants in retirement communities have long known of this age related shift in bed time preference, epitomized and accommodated by the “early bird special”.
Their regressed circadian rhythm, instructed by an earlier release of melatonin, left them no choice.&lt;/p&gt;
&lt;p&gt;Plentiful later-afternoon daylight will help the delay the evening release of melatonin, helping push the timing of sleep to a later hour. Make sure to wear sun protection of some sort, such as a hat, but leave the sunglasses at home.&lt;/p&gt;
&lt;h1 id=&quot;part-2-why-should-you-sleep&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#part-2-why-should-you-sleep&quot; aria-label=&quot;part 2 why should you sleep permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Part 2: Why Should You Sleep?&lt;/h1&gt;
&lt;h2 id=&quot;c6-your-mother-and-shakespeare-knew&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c6-your-mother-and-shakespeare-knew&quot; aria-label=&quot;c6 your mother and shakespeare knew permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C6: Your Mother and Shakespeare Knew&lt;/h2&gt;
&lt;p&gt;Observations of the brain show a strikingly reliable loop of electrical current pulsing throughout the brain that repeats every 100 to 200 ms.&lt;/p&gt;
&lt;p&gt;This electrical transaction in the quiet secrecy of sleep is one that shifts fact-based memories from the temporary storage depot, the hippocampus, to a long-term secure vault, the cortex. This shift is the product of slow brainwaves of deep NREM sleep that serve as a courier service. In doing so, sleep helps future-proof those memories.&lt;/p&gt;
&lt;p&gt;Studies shows a memory retention benefit of between 20% and 40% being offered by sleep, compared to the same amount of time awake.&lt;/p&gt;
&lt;p&gt;Not only does NREM sleep maintain those memories you have successfully learned before bed, but it will even salvage those that appear to have been lost soon after learning.&lt;/p&gt;
&lt;p&gt;Another study shows that relative to a control group that slept but had no synchronous auditory chimes at night, the auditory stimulation increased the power of the slow brainwaves and returned an impressive 40% memory enhancement the next morning&lt;/p&gt;
&lt;h3 id=&quot;sleep-to-forget&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sleep-to-forget&quot; aria-label=&quot;sleep to forget permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sleep to forget?&lt;/h3&gt;
&lt;p&gt;The capacity to forget can, in certain contexts, be as important as the need for remembering. In this way, sleep helps you retain everything you need and nothing that you don’t.&lt;/p&gt;
&lt;p&gt;This occurs when taking a nap while studying for an exam, for instance. The more of those NREM sleep spindles a person has during a nap, the greater the efficiency with which they strengthen concepts tagged for remembering and actively eliminate those designated for forgetting.&lt;/p&gt;
&lt;h3 id=&quot;practice-alone-does-not-make-perfect&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#practice-alone-does-not-make-perfect&quot; aria-label=&quot;practice alone does not make perfect permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Practice alone does not make perfect&lt;/h3&gt;
&lt;p&gt;Muscle memory is, in fact, brain memory. The routine itself, the memory program, resides firmly and exclusively within the brain.&lt;/p&gt;
&lt;p&gt;A pianist friend of the author told him that he would be practicing a particular piece for hours and wouldn’t be able to master it. Often, he would make the same mistake at the same place in a particular movement. He would then go to bed frustrated, but the next morning, after sitting back down at the piano, he would just play it perfectly.&lt;/p&gt;
&lt;p&gt;Does this mean that the most repeated and entrusted teaching edict, “practice makes perfect“ is violated? Perhaps it was practice, &lt;em&gt;&lt;strong&gt;with sleep&lt;/strong&gt;&lt;/em&gt;, that makes perfect?&lt;/p&gt;
&lt;p&gt;Perhaps more relevant to the modern world is the time-of-night that was discovered. Those last two hours of sleep are precisely the window that many of us feel it is OK to cut short to get a jump start on the day. As a result, we miss out on this feast of late morning sleep spindles that are deeply linked with the offline memory boost. Loose out on the last hours of sleep for an 8 hour night, and your memory capacity can be seriously affected.&lt;/p&gt;
&lt;h3 id=&quot;sleep-and-sport&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sleep-and-sport&quot; aria-label=&quot;sleep and sport permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sleep and Sport&lt;/h3&gt;
&lt;p&gt;Some teams are aware of sleep’s importance before a game. But sleep after a game can be as essential. Post-performance sleep accelerates physical recovery from common inflammation, stimulates muscle repair, and helps restock cellular energy in the form of glucose and glycogen.&lt;/p&gt;
&lt;h3 id=&quot;sleep-for-creativity&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sleep-for-creativity&quot; aria-label=&quot;sleep for creativity permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sleep for Creativity&lt;/h3&gt;
&lt;p&gt;Sleep provides a nighttime theater in which your brain tests out and builds connections between vast stores of information. This task is accomplished using a bizarre algorithm that is biased towards seeking out the most distant, non-obvious associations, rather like a backward Google search.&lt;/p&gt;
&lt;h2 id=&quot;c7-too-extreme-for-the-guinness-book-of-world-records&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c7-too-extreme-for-the-guinness-book-of-world-records&quot; aria-label=&quot;c7 too extreme for the guinness book of world records permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C7: Too extreme for the Guinness book of world records&lt;/h2&gt;
&lt;h3 id=&quot;sleep-deprivation-and-the-brain&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sleep-deprivation-and-the-brain&quot; aria-label=&quot;sleep deprivation and the brain permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sleep deprivation and the brain&lt;/h3&gt;
&lt;p&gt;Most worrying from a societal perspective were the individuals in the group who obtained six hours of sleep a night—something that may sound familiar to many of you. Ten days of six hours of sleep a night was all it took to become as impaired in performance as going without sleep for 24 hours straight.&lt;/p&gt;
&lt;h3 id=&quot;you-do-not-know-how-sleep-deprived-you-are-when-you-are-sleep-deprived&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#you-do-not-know-how-sleep-deprived-you-are-when-you-are-sleep-deprived&quot; aria-label=&quot;you do not know how sleep deprived you are when you are sleep deprived permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;You do not know how sleep-deprived you are when you are sleep-deprived&lt;/h3&gt;
&lt;p&gt;With chronic sleep restriction over months or years, an individual will actually acclimate to their impaired performance, lower alertness, and reduced energy levels.&lt;/p&gt;
&lt;p&gt;60 years of scientific research prevents the author from accepting anyone who tells him that he or she can “get by on just four or five hours of sleep a night just fine“.&lt;/p&gt;
&lt;p&gt;And I can also say this. I had teachers at school who showed off how little they slept. This different influenced me in believing that sleep was an obstacle to one’s progress. Even into my university years, I always compromised sleep over extra study time, with questionable results.&lt;/p&gt;
&lt;p&gt;Even though one might believe that sleep hours can be recovered during the weekend, studies show that the brain is in capable of that. It is simply not enough to repair the damage done by a work week of sleep deprivation.&lt;/p&gt;
&lt;p&gt;Operating on less than five hours of sleep and your risk of a car crash increases threefold. Get behind the wheel of a car when having slept just four hours or less the night before and you are 11.5 times more likely to be involved in a car accident.&lt;/p&gt;
&lt;p&gt;The recycle rate of a human being is around 16 hours. After 16 hours of being awake, the brains begins to fail. Humans need more than seven hours of sleep each night to maintain competitive performance. After 10 days of just seven hours of sleep, the brain is as dysfunctional as it would be after going without sleep for 24 hours. Three full nights of recovery sleep are insufficient to restore performance back to normal levels after a week of short sleeping. Besides, the human mind cannot actually sense how sleep deprived it is when sleep deprived.&lt;/p&gt;
&lt;p&gt;Drowsy driving alone is worse than driving drunk. Drunk drivers are often late in breaking, and late in making evasive maneuvers. But when you fall asleep, or have a microsleep, you stop reacting altogether!&lt;/p&gt;
&lt;p&gt;With a full night of plentiful sleep we have a balanced mix between our emotional gas pedal (amygdala) and break (prefrontal cortex). Without sleep, however, the strong coupling between these two brain regions is lost. We cannot rein in our impulses -too much emotional gas pedal and not enough regulatory break. Without the rational control giving to us each night by sleep, we are not on a neurological and emotional balance.&lt;/p&gt;
&lt;p&gt;There is no psychiatric condition in which sleep is normal. This is true of depression, anxiety, PTSD, schizophrenia, and bipolar disorder. Studies show that improving sleep quantity, quality, and regularity heals the mind of numerous psychiatric populations.&lt;/p&gt;
&lt;p&gt;A lack of sleep is a deeply penetrating and corrosive force that enfeebles the memory making apparatus within your brain, preventing you from constructing lasting memory traces. It is rather like building a sand castle too close to the tide line—the consequences are inevitable.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;It is clear now that pulling all nighter‘s is not a wise idea for learning, not because you won’t learn during those hours, but because you won’t recall later on what you learned previously!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This, of course, is really not under the consideration of faculties around the globe. Teachers accumulate exams in the final days of a semester, leaving no other choice to students than to compromise sleep hours in favor of learning.&lt;/p&gt;
&lt;p&gt;Many can answer to that argument saying that the students “make their own choices” or that students “are responsible if they do not sleep properly”. But science shows something different. If you don’t sleep the very first night after learning, you lose the chance to consolidate those memories, even if you get lots of “catch up“ sleep thereafter. Sleep is not like the bank. You cannot accumulate a debt and hope to pay it off at a later point in time. Sleep for memory consolidation is an all or nothing event. It is a concerning result in our 24 seven, hurry up, don’t wait society.&lt;/p&gt;
&lt;h3 id=&quot;sleep-and-alzheimers-disease&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sleep-and-alzheimers-disease&quot; aria-label=&quot;sleep and alzheimers disease permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sleep and Alzheimer’s disease&lt;/h3&gt;
&lt;p&gt;As we get older, it is common for us to have a general loss of deep sleep. But for Alzheimer’s patients, there is a ruthless eroding of the very deepest of the powerful slow brain waves of NREM sleep. This distinction is important, since it means that the sleep impairment caused by amyloid buildup in the brain is more than just “normal aging“.&lt;/p&gt;
&lt;p&gt;Patients with a high amyloid deposits in the frontal regions of the brain have the most severe loss of deep sleep. As a consequence, they fail to successfully consolidate new memories. Overnight forgetting, rather than remembering, takes place. The disruption of deep NREM sleep is therefore a hidden middleman brokering the bad deal between amyloid and memory impairment in Alzheimer’s disease.&lt;/p&gt;
&lt;p&gt;Should you experimentally prevent a mouse from getting NREM sleep, keeping it awake instead, there is an immediate increase in amyloid deposits within the brain. Without sufficient sleep, amyloid plaques buildup in the brain, specially in deep sleep generating regions, attacking and degrading them. The loss of deep and NREM sleep caused by this assault therefore lessens the ability to remove amyloid from the brain at night, resulting in greater amyloid deposition. More amyloid, less deep sleep, less deep sleep, more amyloid, and so on and so forth.&lt;/p&gt;
&lt;h2 id=&quot;c8-cancer-heart-attacks-and-a-shorter-life&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c8-cancer-heart-attacks-and-a-shorter-life&quot; aria-label=&quot;c8 cancer heart attacks and a shorter life permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C8: Cancer, heart attacks, and a shorter life&lt;/h2&gt;
&lt;h3 id=&quot;sleep-deprivation-and-the-body&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sleep-deprivation-and-the-body&quot; aria-label=&quot;sleep deprivation and the body permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sleep deprivation and the body&lt;/h3&gt;
&lt;p&gt;Over a 14 year period, those sleeping six hours or less were 400% or 500% more likely to suffer one or more cardiac arrests than those sleeping more than six hours. This relationship between short sleep and a heart failure remains strong even after controlling for other known cardiac risk factors, such as smoking or physical activity.&lt;/p&gt;
&lt;p&gt;Like a car engine that is revved to shrieking extreme for sustained periods of time, your sympathetic nervous system is flawed into perpetual overdrive by lack of sleep. The consequential strain that is placed on your body by the persistent force of sympathetic activation will leak out in all manner of health issues, just like the failed pistons, gaskets, seals, and gears of an abuse car engine.&lt;/p&gt;
&lt;p&gt;In the northern hemisphere, the switch to daylight savings time in March results in most people losing an hour of sleep opportunity. Researchers have discovered that this seemingly trivial sleep production comes with a frightening spike in heart attacks the following day. In the autumn within the northern hemisphere, when the clocks move back and we gain an hour of sleep opportunity time, rates of heart attacks plummet the day after. A similar rise and fall relationship can be seen with the number of traffic accidents.&lt;/p&gt;
&lt;h3 id=&quot;sleep-loss-and-metabolism-diabetes-and-weight-gain&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sleep-loss-and-metabolism-diabetes-and-weight-gain&quot; aria-label=&quot;sleep loss and metabolism diabetes and weight gain permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sleep loss and metabolism: diabetes and weight gain&lt;/h3&gt;
&lt;p&gt;In one study, participants were limited to sleeping four hours a night for just six nights. By the end of that week, the formerly healthy participants were 40% less effective at observing a standard dose of glucose, compared to when they were for the rest.&lt;/p&gt;
&lt;p&gt;Inadequate sleep decreased concentrations of satiety signaling hormone leptin and increase levels of the hunger instigating hormone ghrelin&lt;/p&gt;
&lt;p&gt;Recents study found that a lack of sleep makes your body produce &lt;em&gt;endocannabinoids&lt;/em&gt;, chemicals very similar to the drug cannabis which stimulate appetite and increase your desire to snack.&lt;/p&gt;
&lt;p&gt;Ample sleep can restore a system of impulse control within your brain, putting the appropriate brakes on potentially excessive eating.&lt;/p&gt;
&lt;p&gt;When you’re not getting enough sleep, the body becomes specially stingy about giving up fat. Instead, muscle mass is depleted while fat is retained.&lt;/p&gt;
&lt;p&gt;I report that studied over 40 years of more than 100,000 employed woman, working irregular nighttime hours (such as nurses who perform shift work) had a 33% higher rate of abnormal menstrual cycles than those working regular daytime hours.&lt;/p&gt;
&lt;p&gt;Studies have found that short sleep duration will also disrupt activity of genes regulating cholesterol. In particular, a lack of sleep will cause a drop in high density lipoproteins, a directional profile profile that has consistently been linked to cardiovascular disease. Inappropriately time sleep, such as the imposed by jet lag or shift work, can I have equally large effects on the expression of human genes as inadequate sleep.&lt;/p&gt;
&lt;p&gt;Neglect sleep, and you’re deciding to perform a genetic engineering manipulation on yourself each night, tempering with that nucleic// alphabet that spells out your daily health story. Permit the same in your children and teenagers and your imposing a similar genetic engineering experiment on them as well.&lt;/p&gt;
&lt;h1 id=&quot;part-3-how-and-why-we-dream&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#part-3-how-and-why-we-dream&quot; aria-label=&quot;part 3 how and why we dream permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Part 3: How and Why We Dream&lt;/h1&gt;
&lt;h2 id=&quot;c9-routinely-psychotic&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c9-routinely-psychotic&quot; aria-label=&quot;c9 routinely psychotic permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C9: Routinely Psychotic&lt;/h2&gt;
&lt;p&gt;Our emotional regions of the brain are up to 30% more active in REM sleep compared to when we are awake!&lt;/p&gt;
&lt;p&gt;Since REM sleep is associated with an active, conscious experience of dreaming, it was perhaps predictable that REM sleep would involve a similarly enthusiastic pattern of increased brain activity.&lt;/p&gt;
&lt;p&gt;This CEO region of your brain, which otherwise maintains your cognitive capacity for ordered, logical thought, is temporarily ousted each time you enter into the dreaming state of REM sleep.&lt;/p&gt;
&lt;p&gt;REM sleep can therefore for be considered as a state characterized by strong activation in visual, motor, emotional and autobiographical memory regions of the brain, yet relative deactivation in regions that control rational thought.&lt;/p&gt;
&lt;p&gt;Scientists were able to predict with significant accuracy the content of participants’ dreams at anyone moment in time using just the MRI scans, operating completely blind to the dream reports of the participants. Using the template data from the MRI images, they could tell if you were dreaming of a man or a woman, a dog or a bed, flowers or a knife.&lt;/p&gt;
&lt;p&gt;My immediate reaction to this reasearch is fear. In the future this could mean that we could hold the dreamer responsible for what they dream. Is it fair to judge what it is they are dreaming, since they were not the conscious architect of their dream?&lt;/p&gt;
&lt;h1 id=&quot;part-4-from-sleeping-pills-to-society-transformed&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#part-4-from-sleeping-pills-to-society-transformed&quot; aria-label=&quot;part 4 from sleeping pills to society transformed permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Part 4: From Sleeping Pills to Society Transformed&lt;/h1&gt;
&lt;h2 id=&quot;c15-sleep-and-society&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c15-sleep-and-society&quot; aria-label=&quot;c15 sleep and society permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C15: Sleep and Society&lt;/h2&gt;
&lt;p&gt;Early studies demonstrated shorter sleep amounts, predict lower work, right and slow completion speed of basic tasks. Sleep deprived individuals also generate fewer and less accurate solutions to work relevant problems they are challenge with.&lt;/p&gt;
&lt;p&gt;Studies also found that those individuals who obtained less sleep in the preceding days are the same people who consistently select less challenging problems. The opt for the easy way out, generating if you were creative solutions in the process.&lt;/p&gt;
&lt;p&gt;The irony that employees miss is that when you are not getting enough sleep, you work less productively, and thus need to work longer to accomplish a goal. This means you often must work longer and later into the evening, arrive home later, go to bed later, and need to wake up earlier, creating a negative feedback loop.&lt;/p&gt;
&lt;h3 id=&quot;sleep-and-education&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sleep-and-education&quot; aria-label=&quot;sleep and education permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sleep and education&lt;/h3&gt;
&lt;p&gt;Keep in mind at 5:15 AM to a teenager is not the same as 5:15 AM to an adult. The circadian rhythm of teenagers shifts forward dramatically by 1 to 3 hours. So for a teenager to wake up at 5:15 AM in order to get to school by 7:20 AM is equivalent for adults to wake up at 3:15 AM day after day after day.&lt;/p&gt;
&lt;p&gt;One school in Minnesota that moved start times from 7:25 AM to 8:30 AM not only gave 43 minutes of extra sleep to students but also improved their SAT academic performance.&lt;/p&gt;
&lt;p&gt;Children from lower socioeconomic backgrounds are less likely to be taken to school in a car, in part, because their parents often have jobs in the service industry demanding work start times at or before 6 AM. Such children, therefore rely on the school buses for transit, and must wake up earlier than those taken to school by their parents. As a result, those already disadvantaged children become even more so because they routinely obtain less sleep than children from more affluent families. The upshot is a vicious cycle that perpetuates from one generation to the next, a closed loop system that is very difficult to break out of.&lt;/p&gt;
&lt;h3 id=&quot;sleep-and-health-care&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sleep-and-health-care&quot; aria-label=&quot;sleep and health care permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sleep and Health Care&lt;/h3&gt;
&lt;p&gt;Residents working a 30 hour straight shift will commit 36% more serious medical errors, such as prescribing the wrong dose of a drug, or leaving a surgical implement inside of a patient.&lt;/p&gt;
&lt;p&gt;One in 20 residents will kill a patient due to a lack of sleep.&lt;/p&gt;
&lt;p&gt;I knew report has discovered that medical errors are the third leading cause of death among Americans after heart attacks and cancer. Sleeplessness, undoubtedly plays a role in those lives lost.&lt;/p&gt;
&lt;p&gt;The Chernobyl nuclear power disaster was the fault of sleep-deprived operators, working an exhaustive shift, occurring, without coincidence, at 1 AM.&lt;/p&gt;
&lt;p&gt;The Exxon Valdez oil tanker that spilled millions of gallons of crude oil and destroyed a coastal ecosystem happened because of a captain that had only slept six out of the previous 48 hours.&lt;/p&gt;
&lt;h2 id=&quot;c16--a-new-vision-for-sleep-in-the-twenty-first-century&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#c16--a-new-vision-for-sleep-in-the-twenty-first-century&quot; aria-label=&quot;c16  a new vision for sleep in the twenty first century permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;C16:  A New Vision for Sleep in the Twenty-First Century&lt;/h2&gt;
&lt;p&gt;To convert a healthy new habit into a permanent way of life, you should have exposure to your own data. “Seeing is believing“ ensures longer-term adherence to healthy habits.  This means using tools such as mobile apps to track your sleep and see how changes in your habit impact the your sleep patterns.&lt;/p&gt;
&lt;h3 id=&quot;public-policy-and-societal-change&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#public-policy-and-societal-change&quot; aria-label=&quot;public policy and societal change permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Public Policy and Societal Change&lt;/h3&gt;
&lt;p&gt;At the highest levels, we need better public campaigns educating the population about sleep. We spend a tiny fraction of our transportation safety budget warning people of the dangers of drowsy driving compared with the countless campaigns and awareness efforts regarding accidents, linked to drugs or alcohol. This despite the fact that drowsy driving is responsible for more accidents than either of these two issues – and this more deadly. The governments could save hundreds of thousands of lives each year if they mobilize such a campaign. It would easily pay for itself, based on the cost savings to the health care and emergency services bills that drowsy driving accidents impose. It would of course help lower healthcare and I’ll be insurance rates and premiums for individuals.&lt;/p&gt;
&lt;h1 id=&quot;my-data-what-can-i-learn-from-4-years-of-sleep-tracking&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#my-data-what-can-i-learn-from-4-years-of-sleep-tracking&quot; aria-label=&quot;my data what can i learn from 4 years of sleep tracking permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;My Data: What can I learn from 4 years of sleep tracking?&lt;/h1&gt;
&lt;p&gt;For the past couple of years, I have used a mobile app on many (but not most) nights to track my sleep. By “track” I mean the app on my iPhone using the microphone to analyze noise around my movements in bed. I don’t trust this method entirely, but I do feel it is related somehow to how the way I ended up performing around the time my sleep improved or worsened.&lt;/p&gt;
&lt;p&gt;Below I share the insights the app let me export I consider are the richest.&lt;/p&gt;
&lt;p&gt;I was not paid in any way by the app developer nor is this an endorsement for you to implement this or with any other app. But I do recommend to investigate on current (and not-that-invasive) state-of-the-art ways for you to track your sleep and improve your health.&lt;/p&gt;
&lt;p&gt;Now, onto the data!&lt;/p&gt;
&lt;h2 id=&quot;sleep-quality&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#sleep-quality&quot; aria-label=&quot;sleep quality permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Sleep Quality&lt;/h2&gt;
&lt;p&gt;“We calculate your sleep quality on a number of factors, but most importantly on the time you spend asleep, movements during the night and moments when you&apos;re fully awake. Use Sleep Cycle continuously, and it will learn and calibrate your quality score accordingly. We&apos;re all different even in sleep, which is why Sleep Cycle adapts its Sleep Quality algorithm to your patterns and sleep habits over time.”&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 582px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/7c0194381b8ed29838f9e961c2ce9ad9/7c1cd/sleep-quality.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 76.07361963190185%; position: relative; bottom: 0; left: 0; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/7c0194381b8ed29838f9e961c2ce9ad9/0cbef/sleep-quality.avif 163w,
/static/7c0194381b8ed29838f9e961c2ce9ad9/bffb7/sleep-quality.avif 325w,
/static/7c0194381b8ed29838f9e961c2ce9ad9/4e9f5/sleep-quality.avif 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/7c0194381b8ed29838f9e961c2ce9ad9/94563/sleep-quality.webp 163w,
/static/7c0194381b8ed29838f9e961c2ce9ad9/647a8/sleep-quality.webp 325w,
/static/7c0194381b8ed29838f9e961c2ce9ad9/f6aeb/sleep-quality.webp 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/7c0194381b8ed29838f9e961c2ce9ad9/222b7/sleep-quality.png 163w,
/static/7c0194381b8ed29838f9e961c2ce9ad9/ff46a/sleep-quality.png 325w,
/static/7c0194381b8ed29838f9e961c2ce9ad9/7c1cd/sleep-quality.png 582w&quot;
            sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/7c0194381b8ed29838f9e961c2ce9ad9/7c1cd/sleep-quality.png&quot;
            alt=&quot;Sleep quality&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Sleep quality&lt;/figcaption&gt;
  &lt;/figure&gt;
I can say right from the beginning what is going on here, specially in 2021. Up to that moment, my sleep worsened as I finished up my studies on Software Engineering, which took a big toll on my nerves, I must confess. Rushing to apply with the best marks as possible for 2018 and the first half of 2019, I made it to Vienna from Buenos Aires for a Double Degree program. The program was harder than expected, and I found myself pulling all-nighters frequently, but happily finished graduating in mid 2020.&lt;/p&gt;
&lt;p&gt;The true minimum in quality was at the beginning of 2021, when I returned home for the Covid-19 pandemic, but kept the office hours of a timezone 4 hours later than Argentina. This meant waking up extra early for many weeks, but having a hard time going to bed earlier.&lt;/p&gt;
&lt;p&gt;Then I returned to Vienna, later quit that job, and was much clearly more relaxed. I moved back to Argentina for good and my sleep quality has not fell from 60%, but at the time of writing it’s 20 points down from my all time high. Must be my addiction to Twitter before bed.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 582px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/1432605400ece813bae2903228a2dbae/7c1cd/location.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 133.74233128834356%; position: relative; bottom: 0; left: 0; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/1432605400ece813bae2903228a2dbae/0cbef/location.avif 163w,
/static/1432605400ece813bae2903228a2dbae/bffb7/location.avif 325w,
/static/1432605400ece813bae2903228a2dbae/4e9f5/location.avif 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/1432605400ece813bae2903228a2dbae/94563/location.webp 163w,
/static/1432605400ece813bae2903228a2dbae/647a8/location.webp 325w,
/static/1432605400ece813bae2903228a2dbae/f6aeb/location.webp 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/1432605400ece813bae2903228a2dbae/222b7/location.png 163w,
/static/1432605400ece813bae2903228a2dbae/ff46a/location.png 325w,
/static/1432605400ece813bae2903228a2dbae/7c1cd/location.png 582w&quot;
            sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/1432605400ece813bae2903228a2dbae/7c1cd/location.png&quot;
            alt=&quot;Location Factor&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Location Factor&lt;/figcaption&gt;
  &lt;/figure&gt;
This is pretty insightful! I got my best sleep during vacations, and my worst during the hardest part of the Austrian lockdown.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 582px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/26ba534874c964492929446557c03cf2/7c1cd/week.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 93.25153374233128%; position: relative; bottom: 0; left: 0; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/26ba534874c964492929446557c03cf2/0cbef/week.avif 163w,
/static/26ba534874c964492929446557c03cf2/bffb7/week.avif 325w,
/static/26ba534874c964492929446557c03cf2/4e9f5/week.avif 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/26ba534874c964492929446557c03cf2/94563/week.webp 163w,
/static/26ba534874c964492929446557c03cf2/647a8/week.webp 325w,
/static/26ba534874c964492929446557c03cf2/f6aeb/week.webp 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/26ba534874c964492929446557c03cf2/222b7/week.png 163w,
/static/26ba534874c964492929446557c03cf2/ff46a/week.png 325w,
/static/26ba534874c964492929446557c03cf2/7c1cd/week.png 582w&quot;
            sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/26ba534874c964492929446557c03cf2/7c1cd/week.png&quot;
            alt=&quot;Week times&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Week times&lt;/figcaption&gt;
  &lt;/figure&gt;
Saturday a clear winner in terms of sleep. Friday the worse performer, but only because of the night outs 🕺!&lt;/p&gt;
&lt;h2 id=&quot;regularity&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#regularity&quot; aria-label=&quot;regularity permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Regularity&lt;/h2&gt;
&lt;p&gt;“Your Regularity is one of the most important factors for better sleep, but also a factor you can totally own.
We all have habits that affect our well-being, and when you go to bed or rise in the morning is one of the strongest influencers. In fact, if you&apos;re sliding here, it&apos;s like being jetlagged without the travelling involved.
Regularity tells you about your bedtimes and wake up times over a period of time. The higher it is, the more regular your bedtime and wakeup times, and that leads to better sleep. If you&apos;re not happy with this rating, just find your sleep beat and stick to it. Doesn&apos;t matter if you&apos;re a night owl or a lark. Results will come quickly either way.”&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 582px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/614e3a742d305b6181a7fa329968fa45/7c1cd/regularity.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 76.07361963190185%; position: relative; bottom: 0; left: 0; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/614e3a742d305b6181a7fa329968fa45/0cbef/regularity.avif 163w,
/static/614e3a742d305b6181a7fa329968fa45/bffb7/regularity.avif 325w,
/static/614e3a742d305b6181a7fa329968fa45/4e9f5/regularity.avif 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/614e3a742d305b6181a7fa329968fa45/94563/regularity.webp 163w,
/static/614e3a742d305b6181a7fa329968fa45/647a8/regularity.webp 325w,
/static/614e3a742d305b6181a7fa329968fa45/f6aeb/regularity.webp 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/614e3a742d305b6181a7fa329968fa45/222b7/regularity.png 163w,
/static/614e3a742d305b6181a7fa329968fa45/ff46a/regularity.png 325w,
/static/614e3a742d305b6181a7fa329968fa45/7c1cd/regularity.png 582w&quot;
            sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/614e3a742d305b6181a7fa329968fa45/7c1cd/regularity.png&quot;
            alt=&quot;Regularity&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Regularity&lt;/figcaption&gt;
  &lt;/figure&gt;
Again, the double degree program (and no work at the time) took the worst out of my regularity. It took me the entirety of 2020 to recover from that; the lockdown did not help at all.
&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 582px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/19bdcdc03e1f14ff5e2ecb1ec7307d97/7c1cd/regularity-week.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 93.25153374233128%; position: relative; bottom: 0; left: 0; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/19bdcdc03e1f14ff5e2ecb1ec7307d97/0cbef/regularity-week.avif 163w,
/static/19bdcdc03e1f14ff5e2ecb1ec7307d97/bffb7/regularity-week.avif 325w,
/static/19bdcdc03e1f14ff5e2ecb1ec7307d97/4e9f5/regularity-week.avif 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/19bdcdc03e1f14ff5e2ecb1ec7307d97/94563/regularity-week.webp 163w,
/static/19bdcdc03e1f14ff5e2ecb1ec7307d97/647a8/regularity-week.webp 325w,
/static/19bdcdc03e1f14ff5e2ecb1ec7307d97/f6aeb/regularity-week.webp 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/19bdcdc03e1f14ff5e2ecb1ec7307d97/222b7/regularity-week.png 163w,
/static/19bdcdc03e1f14ff5e2ecb1ec7307d97/ff46a/regularity-week.png 325w,
/static/19bdcdc03e1f14ff5e2ecb1ec7307d97/7c1cd/regularity-week.png 582w&quot;
            sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/19bdcdc03e1f14ff5e2ecb1ec7307d97/7c1cd/regularity-week.png&quot;
            alt=&quot;Regularity of the week&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Regularity of the week&lt;/figcaption&gt;
  &lt;/figure&gt;
Same party-reasons here as before.&lt;/p&gt;
&lt;h2 id=&quot;went-to-bed&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#went-to-bed&quot; aria-label=&quot;went to bed permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Went to Bed&lt;/h2&gt;
&lt;p&gt;“You&apos;d be forgiven for thinking this one&apos;s pretty obvious. It measures when you go to bed. And that&apos;s it. Right? Not quite, because a key component to getting a good night&apos;s rest is to maintain your bedtime routines, and going to bed at about the same time every night, is a factor. Some argue that maintaining your bedtime routine is more important than getting enough hours of sleep, but until that&apos;s settled, we&apos;ll stick with just saying that it makes a difference. A potentially major one.”&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 582px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/10ef9e35042f8443ab34677fe6972427/7c1cd/went-to-bed.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 76.07361963190185%; position: relative; bottom: 0; left: 0; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/10ef9e35042f8443ab34677fe6972427/0cbef/went-to-bed.avif 163w,
/static/10ef9e35042f8443ab34677fe6972427/bffb7/went-to-bed.avif 325w,
/static/10ef9e35042f8443ab34677fe6972427/4e9f5/went-to-bed.avif 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/10ef9e35042f8443ab34677fe6972427/94563/went-to-bed.webp 163w,
/static/10ef9e35042f8443ab34677fe6972427/647a8/went-to-bed.webp 325w,
/static/10ef9e35042f8443ab34677fe6972427/f6aeb/went-to-bed.webp 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/10ef9e35042f8443ab34677fe6972427/222b7/went-to-bed.png 163w,
/static/10ef9e35042f8443ab34677fe6972427/ff46a/went-to-bed.png 325w,
/static/10ef9e35042f8443ab34677fe6972427/7c1cd/went-to-bed.png 582w&quot;
            sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/10ef9e35042f8443ab34677fe6972427/7c1cd/went-to-bed.png&quot;
            alt=&quot;Went to bed&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Went to bed&lt;/figcaption&gt;
  &lt;/figure&gt;
Common denominator once again. Final thesis and lockdown made me feel I was living with Siberia’s timezone. A disaster! I remember waking up with the sunset of the Austrian winter.&lt;/p&gt;
&lt;p&gt;It’s still bad. Provided my job starts at 9:30 am or later, I don’t see myself improving here.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 582px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/50f78fcef7e51e161521722d404e176d/7c1cd/woke-up.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 76.07361963190185%; position: relative; bottom: 0; left: 0; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/50f78fcef7e51e161521722d404e176d/0cbef/woke-up.avif 163w,
/static/50f78fcef7e51e161521722d404e176d/bffb7/woke-up.avif 325w,
/static/50f78fcef7e51e161521722d404e176d/4e9f5/woke-up.avif 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/50f78fcef7e51e161521722d404e176d/94563/woke-up.webp 163w,
/static/50f78fcef7e51e161521722d404e176d/647a8/woke-up.webp 325w,
/static/50f78fcef7e51e161521722d404e176d/f6aeb/woke-up.webp 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/50f78fcef7e51e161521722d404e176d/222b7/woke-up.png 163w,
/static/50f78fcef7e51e161521722d404e176d/ff46a/woke-up.png 325w,
/static/50f78fcef7e51e161521722d404e176d/7c1cd/woke-up.png 582w&quot;
            sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/50f78fcef7e51e161521722d404e176d/7c1cd/woke-up.png&quot;
            alt=&quot;Woke up&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Woke up&lt;/figcaption&gt;
  &lt;/figure&gt;
Remote work 4 hours behind clearly stands out here. Not a morning lark, am I?&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 582px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/52dc609968f2afa00404c684783de723/7c1cd/woke-week.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 93.25153374233128%; position: relative; bottom: 0; left: 0; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/52dc609968f2afa00404c684783de723/0cbef/woke-week.avif 163w,
/static/52dc609968f2afa00404c684783de723/bffb7/woke-week.avif 325w,
/static/52dc609968f2afa00404c684783de723/4e9f5/woke-week.avif 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/52dc609968f2afa00404c684783de723/94563/woke-week.webp 163w,
/static/52dc609968f2afa00404c684783de723/647a8/woke-week.webp 325w,
/static/52dc609968f2afa00404c684783de723/f6aeb/woke-week.webp 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/52dc609968f2afa00404c684783de723/222b7/woke-week.png 163w,
/static/52dc609968f2afa00404c684783de723/ff46a/woke-week.png 325w,
/static/52dc609968f2afa00404c684783de723/7c1cd/woke-week.png 582w&quot;
            sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/52dc609968f2afa00404c684783de723/7c1cd/woke-week.png&quot;
            alt=&quot;Wake time during the week&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Wake time during the week&lt;/figcaption&gt;
  &lt;/figure&gt;
Workdays are evident.&lt;/p&gt;
&lt;h2 id=&quot;efficiency&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#efficiency&quot; aria-label=&quot;efficiency permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Efficiency&lt;/h2&gt;
&lt;p&gt;“Sleep efficiency is an important measure of the quality of your sleep. It represents the percentage of time spent asleep during the time you were in bed. For example, if you spent 8 hours in bed and slept for 7 hours, your sleep efficiency would be 87.5%. A high sleep efficiency score indicates that you are spending most of your time in bed asleep, which is important for feeling well-rested and alert during the day. On the other hand, a low sleep efficiency score may indicate that you are experiencing difficulties falling asleep or staying asleep throughout the night. Monitoring your sleep efficiency over time can help you identify patterns and make adjustments to your sleep habits that can improve your overall sleep quality. The Sleep Cycle app provides tools to track your sleep efficiency and offers insights and recommendations to help you optimize your sleep.”&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 582px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/745841275ceebe9125161cb5d60816ad/7c1cd/efficiency.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 76.07361963190185%; position: relative; bottom: 0; left: 0; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/745841275ceebe9125161cb5d60816ad/0cbef/efficiency.avif 163w,
/static/745841275ceebe9125161cb5d60816ad/bffb7/efficiency.avif 325w,
/static/745841275ceebe9125161cb5d60816ad/4e9f5/efficiency.avif 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/745841275ceebe9125161cb5d60816ad/94563/efficiency.webp 163w,
/static/745841275ceebe9125161cb5d60816ad/647a8/efficiency.webp 325w,
/static/745841275ceebe9125161cb5d60816ad/f6aeb/efficiency.webp 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/745841275ceebe9125161cb5d60816ad/222b7/efficiency.png 163w,
/static/745841275ceebe9125161cb5d60816ad/ff46a/efficiency.png 325w,
/static/745841275ceebe9125161cb5d60816ad/7c1cd/efficiency.png 582w&quot;
            sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/745841275ceebe9125161cb5d60816ad/7c1cd/efficiency.png&quot;
            alt=&quot;Efficiency&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Efficiency&lt;/figcaption&gt;
  &lt;/figure&gt;
This is different. It shows I am spending less time asleep in bed. Now I am at near all time lows, albeit a difference of ~5 points between min and max. I attribute this to late-night finance newsletter reading.&lt;/p&gt;
&lt;h2 id=&quot;asleep&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#asleep&quot; aria-label=&quot;asleep permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Asleep&lt;/h2&gt;
&lt;p&gt;“Time Asleep is where the real action is. This is where Sleep Cycle says you&apos;re not just in bed, but actually sleeping as well. While time isn&apos;t the sole factor to get a good night&apos;s sleep, it&apos;s so important that ignoring it, will influence everything, such as deep sleep, movements and REM sessions. If you don&apos;t clock the hours, you have less chance to recover, even if you&apos;re an expert sleeper. If you want to tweak just one thing, start here. Putting in the time to get the sleep you deserve, will help. We promise.”&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 582px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/d3c0c04db299ac81ebf807937f32e5f8/7c1cd/asleep.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 76.07361963190185%; position: relative; bottom: 0; left: 0; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/d3c0c04db299ac81ebf807937f32e5f8/0cbef/asleep.avif 163w,
/static/d3c0c04db299ac81ebf807937f32e5f8/bffb7/asleep.avif 325w,
/static/d3c0c04db299ac81ebf807937f32e5f8/4e9f5/asleep.avif 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/d3c0c04db299ac81ebf807937f32e5f8/94563/asleep.webp 163w,
/static/d3c0c04db299ac81ebf807937f32e5f8/647a8/asleep.webp 325w,
/static/d3c0c04db299ac81ebf807937f32e5f8/f6aeb/asleep.webp 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/d3c0c04db299ac81ebf807937f32e5f8/222b7/asleep.png 163w,
/static/d3c0c04db299ac81ebf807937f32e5f8/ff46a/asleep.png 325w,
/static/d3c0c04db299ac81ebf807937f32e5f8/7c1cd/asleep.png 582w&quot;
            sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/d3c0c04db299ac81ebf807937f32e5f8/7c1cd/asleep.png&quot;
            alt=&quot;Asleep&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Asleep&lt;/figcaption&gt;
  &lt;/figure&gt;
This is a shame, in historic standards. 5 hours is really bad If I consider the lessons of the book I just wrote about. I don’t feel bad though, and I have to say, I snooze the app a lot, so perhaps I get more sleep than recorded here. I would love to improve this.&lt;/p&gt;
&lt;p&gt;&lt;figure class=&quot;gatsby-resp-image-figure&quot; style=&quot;&quot;&gt;
    &lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 582px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/f3d1e2b5eb8778dcd1873431bd4cdb10/7c1cd/asleep-after.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 76.07361963190185%; position: relative; bottom: 0; left: 0; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/f3d1e2b5eb8778dcd1873431bd4cdb10/0cbef/asleep-after.avif 163w,
/static/f3d1e2b5eb8778dcd1873431bd4cdb10/bffb7/asleep-after.avif 325w,
/static/f3d1e2b5eb8778dcd1873431bd4cdb10/4e9f5/asleep-after.avif 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/f3d1e2b5eb8778dcd1873431bd4cdb10/94563/asleep-after.webp 163w,
/static/f3d1e2b5eb8778dcd1873431bd4cdb10/647a8/asleep-after.webp 325w,
/static/f3d1e2b5eb8778dcd1873431bd4cdb10/f6aeb/asleep-after.webp 582w&quot;
              sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/f3d1e2b5eb8778dcd1873431bd4cdb10/222b7/asleep-after.png 163w,
/static/f3d1e2b5eb8778dcd1873431bd4cdb10/ff46a/asleep-after.png 325w,
/static/f3d1e2b5eb8778dcd1873431bd4cdb10/7c1cd/asleep-after.png 582w&quot;
            sizes=&quot;(max-width: 582px) 100vw, 582px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/f3d1e2b5eb8778dcd1873431bd4cdb10/7c1cd/asleep-after.png&quot;
            alt=&quot;Asleep after&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;
    &lt;figcaption class=&quot;gatsby-resp-image-figcaption&quot;&gt;Asleep after&lt;/figcaption&gt;
  &lt;/figure&gt;
Also a worse picture here. It takes me double the time to fall asleep than 3 years ago. I should really pay attention to iOS’s Bedtime reminder.&lt;/p&gt;
&lt;h1 id=&quot;farewell&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#farewell&quot; aria-label=&quot;farewell permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Farewell&lt;/h1&gt;
&lt;p&gt;Thank you for reaching the end! I hope this inspired you to improve your sleep, and to think  how essential it is to our life, no matter your age or habits.&lt;/p&gt;
&lt;p&gt;Let us never forget what it feels like to be truly awake during the day.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Examining the Bitcoin Whitepaper - Part 3/3]]></title><description><![CDATA[A post to understand key concepts behind the famous Bitcoin whitepaper. Part 3/3]]></description><link>https://www.j1nma.com/bitcoin-whitepaper-overview-part-3/</link><guid isPermaLink="false">https://www.j1nma.com/bitcoin-whitepaper-overview-part-3/</guid><pubDate>Sun, 03 Jul 2022 00:00:00 GMT</pubDate><content:encoded>&lt;h4 id=&quot;whats-this-post-about&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#whats-this-post-about&quot; aria-label=&quot;whats this post about permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;em&gt;What’s this post about?&lt;/em&gt;&lt;/h4&gt;
&lt;p&gt;This is a three part post where I explain concepts included in the famous white-paper that are not introduced nor described beforehand, and are important to have a better grasp of the problems tackled by Bitcoin. They are divided into the same sections of the paper.&lt;/p&gt;
&lt;p&gt;This is not a one-stop-shop for Bitcoin or crypto, but a good catch-most of the under-explained concepts in the original whitepaper. Also, this is not financial advise, nor am I trying to evangelize this to you. :)&lt;/p&gt;
&lt;h4 id=&quot;how-to-make-the-best-out-of-this-post&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-to-make-the-best-out-of-this-post&quot; aria-label=&quot;how to make the best out of this post permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;em&gt;How to make the best out of this post&lt;/em&gt;&lt;/h4&gt;
&lt;p&gt;I believe the best way to understand the original paper is to have this post by your side, stop here for the tricky and technological concepts,
and return to reading the paper. There is no specific order, and you can skip any section (specially the mathy ones).&lt;/p&gt;
&lt;p&gt;This is Part 3. Check Part 1 &lt;a href=&quot;https://www.j1nma.com/bitcoin-whitepaper-overview&quot;&gt;here&lt;/a&gt;, and Part 2 &lt;a href=&quot;https://www.j1nma.com/bitcoin-whitepaper-overview-part-2&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;table-of-contents&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#table-of-contents&quot; aria-label=&quot;table of contents permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Table of Contents&lt;/h2&gt;
&lt;!-- TOC --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#table-of-contents&quot;&gt;Table of Contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#combining-and-splitting-value&quot;&gt;Combining and Splitting Value&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#fan-out&quot;&gt;Fan-out&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#privacy&quot;&gt;Privacy&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#unavoidable-linking&quot;&gt;Unavoidable linking&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#calculations&quot;&gt;Calculations&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#what-is-a-binomial-random-walk&quot;&gt;What is a Binomial Random Walk?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#why-is-qp-the-probability-the-attacker-catches-up-from-1-block-behind&quot;&gt;Why is q/p the probability the attacker catches up from 1 block behind?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- /TOC --&gt;
&lt;h2 id=&quot;combining-and-splitting-value&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#combining-and-splitting-value&quot; aria-label=&quot;combining and splitting value permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Combining and Splitting Value&lt;/h2&gt;
&lt;h3 id=&quot;fan-out&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#fan-out&quot; aria-label=&quot;fan out permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Fan-out&lt;/h3&gt;
&lt;p&gt;Why is there never the need to extract a complete standalone copy of a transaction’s history?&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/b9f71be2dce99db9c9117d125c3adaaa/97bfd/fanout.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 16.56441717791411%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAYAAACTWi8uAAAACXBIWXMAACE4AAAhOAFFljFgAAAAp0lEQVR42i2NQRaCMAxEuf85XLjRp6gn8A4uoaUtZVOB0gIPWsZQWfw3SSaTZNu2IcaIEMKhEXEdEMOAdbXoe41pMjS3WJaedlwiBHfUtBunlNtvZV3XgTEGzjmqioNxCfk5oy5PUPqFpnmSd00IcU9onaOuH1TfKHOh/o2y5GjbLzIpJYqiIFMkVUpBSUHQYdLd3x8aY+C9TzjnMI5j0j8e1lrM84wfZrjgRrHI9r4AAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/b9f71be2dce99db9c9117d125c3adaaa/0cbef/fanout.avif 163w,
/static/b9f71be2dce99db9c9117d125c3adaaa/bffb7/fanout.avif 325w,
/static/b9f71be2dce99db9c9117d125c3adaaa/69c29/fanout.avif 650w,
/static/b9f71be2dce99db9c9117d125c3adaaa/6d24a/fanout.avif 975w,
/static/b9f71be2dce99db9c9117d125c3adaaa/006c2/fanout.avif 1078w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/b9f71be2dce99db9c9117d125c3adaaa/94563/fanout.webp 163w,
/static/b9f71be2dce99db9c9117d125c3adaaa/647a8/fanout.webp 325w,
/static/b9f71be2dce99db9c9117d125c3adaaa/c1dc5/fanout.webp 650w,
/static/b9f71be2dce99db9c9117d125c3adaaa/1e975/fanout.webp 975w,
/static/b9f71be2dce99db9c9117d125c3adaaa/cff29/fanout.webp 1078w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/b9f71be2dce99db9c9117d125c3adaaa/222b7/fanout.png 163w,
/static/b9f71be2dce99db9c9117d125c3adaaa/ff46a/fanout.png 325w,
/static/b9f71be2dce99db9c9117d125c3adaaa/a6d36/fanout.png 650w,
/static/b9f71be2dce99db9c9117d125c3adaaa/e548f/fanout.png 975w,
/static/b9f71be2dce99db9c9117d125c3adaaa/97bfd/fanout.png 1078w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/b9f71be2dce99db9c9117d125c3adaaa/a6d36/fanout.png&quot;
            alt=&quot;fanout&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;First of all, the BTC blockchain does not have a “balance” at any point.&lt;/p&gt;
&lt;p&gt;If A sends a transaction to B, A creates an output for a certain amount of bitcoins. For A to spend those funds, an output script defines a condition to allow such event to occur: to spend the transaction, the spender (A in this case) must sign the transaction’s hash with the private key from A’s address. In this way, A can actually spend it, because A owns that unspent transaction.
L&lt;/p&gt;
&lt;p&gt;There are other possible scripts, not limited to 1 private key but multiple keys too, forcing other address to participate in the transaction.&lt;/p&gt;
&lt;p&gt;So what is the balance I see on my wallet? Well, your wallet is actually showing you all &lt;em&gt;unspent transaction outputs&lt;/em&gt; that you are able to spend with your private keys.  These individual unspent outputs come from other transactions that are A’s right to spend. Let’s think of an example.&lt;/p&gt;
&lt;p&gt;If you have 35 USD in your wallet, you must have a combination of bills for there is no 35 USD bill. For example, one 5 USD bill, one 20 USD bill and one 10 USD bill. Each of these individual bills are unspent outputs. They are values in your favour that you can spend and that you received from previous transactions that are in your wallet.&lt;/p&gt;
&lt;p&gt;Let’s say now you want to spend 21 USD on a buffala pizza. You are going to give 1 or more of your unspent outputs to the cashier. So to cover the pizza, you have to give, say, the 20 USD bill and the 5 USD bill. The cashier then gives you 4 USD in change (say coins). This change is, yes, an unspent output, that goes back to your wallet with the rest of the outputs.&lt;/p&gt;
&lt;p&gt;The key here is that the totality of the output must match the input. So in our example, you gave the cashier 25 USD, and then 25 USD in total were redistributed accordingly; 21 USD for the pizza place, and 4 USD back to you in change.&lt;/p&gt;
&lt;p&gt;Note that, in the real world, if the total output amount is less than the total input amount, the difference is considered the transaction fee and this will go to the miner of the block your transaction will appear in.&lt;/p&gt;
&lt;p&gt;If, on the other hand, the output is greater than the input, then the transaction is completely invalid. The difference would be created from thin air. You could give someone value it receive the same amount right back; the “double spend” Satoshi wants to avoid!&lt;/p&gt;
&lt;p&gt;All in all, it is not possible to do a thing like “subtract the amount from person A’s balance and add it to person B’s balance”. When making transactions, you basically &lt;em&gt;destroy&lt;/em&gt; some outputs to generate new ones.&lt;/p&gt;
&lt;p&gt;So, if you didn&apos;t have to spend an output entirely, like in an account/balance system, you would need to check every other transaction that also includes that output and make sure the sum wasn&apos;t more than it contained, adding a lot of complexity to the validation and development.&lt;/p&gt;
&lt;h2 id=&quot;privacy&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#privacy&quot; aria-label=&quot;privacy permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Privacy&lt;/h2&gt;
&lt;h3 id=&quot;unavoidable-linking&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#unavoidable-linking&quot; aria-label=&quot;unavoidable linking permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Unavoidable linking&lt;/h3&gt;
&lt;p&gt;Why is some linking still unavoidable with multi-input transactions, which necessarily reveal that their inputs were owned by the same owner?&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/73ee33cbfa42b47ca7db902853ac0f89/105d8/tx.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 113.49693251533743%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAXCAYAAAALHW+jAAAACXBIWXMAACE4AAAhOAFFljFgAAAC+ElEQVR42qVVaW/aQBD1//9F7ZeqUnqlFQVCAgF8X9jGsc3le/d1dnFcSCCN1EGj2cM8z3szu1aKsoK/WsPzQxzyAsKqtsZNMMEHZ4CPzm988kYUB/jsj7Fvjs9wvLYkSaBwzlHVNcqqRsuY3Gh4i2lm4S7RcfekY9z5Q2oib8sOkH4dKu8GPeDzQm80ZS3rnZ+ML9kZoKC5CuIz0LppcD9dYEI+navSZwsNpu0RkwpN00JIVZIzxlEUJZq2RZZlUAQAe5FhQ4CqbkM3HDjeCkvVRBCuEcWJBHVcWtMsWDTe7vYympaL/SE/Av7LXknSrV1aV65tiAIxcpFtXR9dzEVsiZ5wMRb0xf8FZRGVnPhbbiBT7ynT5lI1JC3NsDFf6JKmqltSWxGFDGJPNx0k6QajySME1rsov8dY13KKqJAfrGXFerqUoXiz7fhUlIAaP5Ju0fy5+YVKvZ9qKJAPh0JqcSp4URQoi5xelKOqStTkVVn0mVwzRfaU6KMTQNG/aXH0mKRNc474wOV4W3C4CUO45VhlHBFFN+XyGQlY0ZGL1klPRZ7lusWdtsZwEeHnNMCvWYhb8l+LFF9UBuuJQYsYjJjBS49z8QJB/2JRGkrR9GJY3lMfnVUCN9rBp6x2lGXZAIeKI6+BDc2LusvwxRGWVtYME3OHob7Fj8cUA22L7/MNvs73uFm2uPdaDG1i4TLMA0ZzBjt5I0NR5SAIEUYRXNeF5/mI12vE6Vbqdu36epXhOw7hXyh+GVR5Pl5nTcqP1cxyYEftuRdO1+Cm5NhUYp1L3VKqvHjuqGEHKC7WbLM7uwSqhmGobXBLun2bkYbLFCNjh4maYTL2MY84ZqsWD36LBWm4DJlsn6uUa+pJyw3h+hHmmgPNdGHTOA5jNFGIklq27rwiciK7hr2hYdVwTN0SE7vA0CgwsgrcqjkGeo4pZT6yG1nlkcPwSBmOKZrxm33YwqCzrMvbxKYPWACDLtCAqt2YOjjjfUH4/1X5vNb8vO4S8A9fivM1Jl9nhgAAAABJRU5ErkJggg==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/73ee33cbfa42b47ca7db902853ac0f89/0cbef/tx.avif 163w,
/static/73ee33cbfa42b47ca7db902853ac0f89/bffb7/tx.avif 325w,
/static/73ee33cbfa42b47ca7db902853ac0f89/69c29/tx.avif 650w,
/static/73ee33cbfa42b47ca7db902853ac0f89/6d24a/tx.avif 975w,
/static/73ee33cbfa42b47ca7db902853ac0f89/ad008/tx.avif 1170w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/73ee33cbfa42b47ca7db902853ac0f89/94563/tx.webp 163w,
/static/73ee33cbfa42b47ca7db902853ac0f89/647a8/tx.webp 325w,
/static/73ee33cbfa42b47ca7db902853ac0f89/c1dc5/tx.webp 650w,
/static/73ee33cbfa42b47ca7db902853ac0f89/1e975/tx.webp 975w,
/static/73ee33cbfa42b47ca7db902853ac0f89/446b5/tx.webp 1170w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/73ee33cbfa42b47ca7db902853ac0f89/222b7/tx.png 163w,
/static/73ee33cbfa42b47ca7db902853ac0f89/ff46a/tx.png 325w,
/static/73ee33cbfa42b47ca7db902853ac0f89/a6d36/tx.png 650w,
/static/73ee33cbfa42b47ca7db902853ac0f89/e548f/tx.png 975w,
/static/73ee33cbfa42b47ca7db902853ac0f89/105d8/tx.png 1170w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/73ee33cbfa42b47ca7db902853ac0f89/a6d36/tx.png&quot;
            alt=&quot;tx&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In the &lt;a href=&quot;https://blockchain.info/tx/4d3ec229677ec9f6bf2a85c57c691bc648e7f4911453d3167a2e8d2fed44dc94&quot;&gt;transaction&lt;/a&gt; from above, 1LS1h8UJ… is both an input and a change address.
Most of the transaction funds were sent to 187SRqCe…and the rest went back to 1LS1h8UJ…
with 0.01580432 BTC.&lt;/p&gt;
&lt;p&gt;This is a bad practice for privacy reasons. Someone watching can tell that the sender controls 1LS1h8UJ (used as input and change address).&lt;/p&gt;
&lt;p&gt;If no address reuse was present then someone could not tell which was the destination address and which was the change address.&lt;/p&gt;
&lt;p&gt;Always create new addresses for change.&lt;/p&gt;
&lt;h2 id=&quot;calculations&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#calculations&quot; aria-label=&quot;calculations permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Calculations&lt;/h2&gt;
&lt;h3 id=&quot;what-is-a-binomial-random-walk&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#what-is-a-binomial-random-walk&quot; aria-label=&quot;what is a binomial random walk permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;What is a Binomial Random Walk?&lt;/h3&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/2664fa37f283bcf27184a7a3e84931fc/eb4a1/binomial.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 16.56441717791411%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAYAAACTWi8uAAAACXBIWXMAACE4AAAhOAFFljFgAAAAtUlEQVR42h1OvQ6CMBjk/RfjMxgX44KDg4NoAfUNNIKlGBNoK6VU43peOlx6P813lxhzQ1Wt8HisUdcppNxC6wOcK/F+FxjHE7w/wVoRtffnmA1DCWMEOXObwV4XCK8dEq1THptBqTmaZsOjBdq2pC7p59RHQrD0ELmUOe73PTMRIWUBVWe4XpbopECiVIPn88XmiQtGwrM9UH/ZPnHZyDfQmyKs9ej7gctD9B3/OvJOO4TPD3/vGNfDBFgHswAAAABJRU5ErkJggg==&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/2664fa37f283bcf27184a7a3e84931fc/0cbef/binomial.avif 163w,
/static/2664fa37f283bcf27184a7a3e84931fc/bffb7/binomial.avif 325w,
/static/2664fa37f283bcf27184a7a3e84931fc/69c29/binomial.avif 650w,
/static/2664fa37f283bcf27184a7a3e84931fc/6d24a/binomial.avif 975w,
/static/2664fa37f283bcf27184a7a3e84931fc/a4458/binomial.avif 1083w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/2664fa37f283bcf27184a7a3e84931fc/94563/binomial.webp 163w,
/static/2664fa37f283bcf27184a7a3e84931fc/647a8/binomial.webp 325w,
/static/2664fa37f283bcf27184a7a3e84931fc/c1dc5/binomial.webp 650w,
/static/2664fa37f283bcf27184a7a3e84931fc/1e975/binomial.webp 975w,
/static/2664fa37f283bcf27184a7a3e84931fc/b671e/binomial.webp 1083w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/2664fa37f283bcf27184a7a3e84931fc/222b7/binomial.png 163w,
/static/2664fa37f283bcf27184a7a3e84931fc/ff46a/binomial.png 325w,
/static/2664fa37f283bcf27184a7a3e84931fc/a6d36/binomial.png 650w,
/static/2664fa37f283bcf27184a7a3e84931fc/e548f/binomial.png 975w,
/static/2664fa37f283bcf27184a7a3e84931fc/eb4a1/binomial.png 1083w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/2664fa37f283bcf27184a7a3e84931fc/a6d36/binomial.png&quot;
            alt=&quot;binomial&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;A random walk is sort of like the steps of a drunk person. One cannot figure out if the next step goes forward or backward (or left or right).&lt;/p&gt;
&lt;p&gt;Formally, in a random walk, we start at some starting position, usually 0. Then subsequent steps are taken by looking at the current value and adding some random value to it.&lt;/p&gt;
&lt;p&gt;In reality, steps look random, but are &lt;em&gt;heavily dependent on previous values&lt;/em&gt;, namely the most recent one.&lt;/p&gt;
&lt;h3 id=&quot;why-is-qp-the-probability-the-attacker-catches-up-from-1-block-behind&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#why-is-qp-the-probability-the-attacker-catches-up-from-1-block-behind&quot; aria-label=&quot;why is qp the probability the attacker catches up from 1 block behind permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Why is q/p the probability the attacker catches up from 1 block behind?&lt;/h3&gt;
&lt;p&gt;Nakamoto isn’t analyzing whether the economics work out: it may be that the attacker spends more on mining than is recovered from the double spent transaction; or it may be that the Coinbase reward from announcing a tremendous number of new blocks is worth more than the double spent transaction. Nakamoto’s goal is instead solely to analyze the worst-case scenario where the attacker spares no expense in running their existing mining power to win the Gambler’s Ruin.&lt;/p&gt;
&lt;p&gt;Let p be the mining power and probability that the honest miners find the next block, and let q be the attacker’s mining power. We define q + p = 1, since we assume either only the attacker or honest miners will win a block each round (and not some late comer or third-party).&lt;/p&gt;
&lt;p&gt;If the attacker has unlimited resources for mining and stops when he reaches z, then we can use Eq. 22 from the paper quoted previously.&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 433px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/a49a6cd194798fb3e2e64c3d366492b2/55fc0/qz.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 43.558282208588956%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAACE4AAAhOAFFljFgAAAA+0lEQVR42pVS14qEQBD0//9N8EFFTKgYMOccauk+5vBkl7trGBy1usL0SHhTx3Hgt7qui9dzL90BVPM8IwgCJhXf7nWeJ2M+iUuiUTRnWQbTNOG6LvZ9x1PQsiwoigLf9xGGIePTNOV3JtR1HUVRYFkWNE2DPM/heR6TkZs7ITkbxxFt2yKKIsas68o9tJhQlmUYhoG+71HXNSuSGgmQg6qqmETUNE0oy/I7rogsnhK5uEcmJU3T2AEJUXQiFy5t24aqqnwscRwjSRI+c8dxvgjvkxIOCEDORHTxn+Jt28YYSiPMDMOArut+Tvk5ybvr/5T0l/v27v59EnsB0aS8S7Xu/b0AAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/a49a6cd194798fb3e2e64c3d366492b2/0cbef/qz.avif 163w,
/static/a49a6cd194798fb3e2e64c3d366492b2/bffb7/qz.avif 325w,
/static/a49a6cd194798fb3e2e64c3d366492b2/608df/qz.avif 433w&quot;
              sizes=&quot;(max-width: 433px) 100vw, 433px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/a49a6cd194798fb3e2e64c3d366492b2/94563/qz.webp 163w,
/static/a49a6cd194798fb3e2e64c3d366492b2/647a8/qz.webp 325w,
/static/a49a6cd194798fb3e2e64c3d366492b2/aff3a/qz.webp 433w&quot;
              sizes=&quot;(max-width: 433px) 100vw, 433px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/a49a6cd194798fb3e2e64c3d366492b2/222b7/qz.png 163w,
/static/a49a6cd194798fb3e2e64c3d366492b2/ff46a/qz.png 325w,
/static/a49a6cd194798fb3e2e64c3d366492b2/55fc0/qz.png 433w&quot;
            sizes=&quot;(max-width: 433px) 100vw, 433px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/a49a6cd194798fb3e2e64c3d366492b2/55fc0/qz.png&quot;
            alt=&quot;qz&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;It’s worth noting an error by Nakamoto here. We aren’t interested in Qz, the probability that the attacker will simply catchup. Instead, Nakamoto should have calculated Qz+1, the probability of the attacker going one past the honest miners.&lt;/p&gt;
&lt;p&gt;There are a few limitations we need to be aware of. First of all, it’s a challenge for the merchant to determine the attacker’s mining power q. It’s always possible that a previously unknown miner or an existing one could dedicate new resources to double spend attacks. The Fischer, Lynch, and Paterson (FLP) impossibility result tells us that Satoshi’s algorithm can never reach consensus. At any point in time, the last block on the chain is only an estimate of what consensus will be in the future.&lt;/p&gt;
&lt;p&gt;Second, the model is a little strange in that the budget for the attacker is infinite for playing the Gambler’s Ruin; yet, the attacker has limited computational power. Satoshi was perhaps attempting to quantify the worst case for each value of q.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Examining the Bitcoin Whitepaper - Part 2/3]]></title><description><![CDATA[A post to understand key concepts behind the famous Bitcoin whitepaper. Part 2/3]]></description><link>https://www.j1nma.com/bitcoin-whitepaper-overview-part-2/</link><guid isPermaLink="false">https://www.j1nma.com/bitcoin-whitepaper-overview-part-2/</guid><pubDate>Sat, 02 Jul 2022 00:00:00 GMT</pubDate><content:encoded>&lt;h4 id=&quot;whats-this-post-about&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#whats-this-post-about&quot; aria-label=&quot;whats this post about permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;em&gt;What’s this post about?&lt;/em&gt;&lt;/h4&gt;
&lt;p&gt;This is a three part post where I explain concepts included in the famous white-paper that are not introduced nor described beforehand, and are important to have a better grasp of the problems tackled by Bitcoin. They are divided into the same sections of the paper.&lt;/p&gt;
&lt;p&gt;This is not a one-stop-shop for Bitcoin or crypto, but a good catch-most of the under-explained concepts in the original whitepaper. Also, this is not financial advise, nor am I trying to evangelize this to you. :)&lt;/p&gt;
&lt;h4 id=&quot;how-to-make-the-best-out-of-this-post&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-to-make-the-best-out-of-this-post&quot; aria-label=&quot;how to make the best out of this post permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;em&gt;How to make the best out of this post&lt;/em&gt;&lt;/h4&gt;
&lt;p&gt;I believe the best way to understand the original paper is to have this post by your side, stop here for the tricky and technological concepts,
and return to reading the paper. There is no specific order, and you can skip any section (specially the mathy ones).&lt;/p&gt;
&lt;p&gt;This is Part 2. Check Part 1 &lt;a href=&quot;https://www.j1nma.com/bitcoin-whitepaper-overview&quot;&gt;here&lt;/a&gt;, and Part 3 &lt;a href=&quot;https://www.j1nma.com/bitcoin-whitepaper-overview-part-3&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;table-of-contents&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#table-of-contents&quot; aria-label=&quot;table of contents permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Table of Contents&lt;/h2&gt;
&lt;!-- TOC --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#table-of-contents&quot;&gt;Table of Contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#network&quot;&gt;Network&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#how-does-a-node-realize-it-missed-one-block&quot;&gt;How does a node realize it missed one block?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#incentive&quot;&gt;Incentive&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#reclaiming-disk-space&quot;&gt;Reclaiming Disk Space&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#pruning&quot;&gt;Pruning&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#how-a-utxo-works&quot;&gt;How a UTXO Works&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#simplified-payment-verification&quot;&gt;Simplified Payment Verification&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#has-the-strategy-of-network-node-alerts-ever-worked&quot;&gt;Has the strategy of network node alerts ever worked?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- /TOC --&gt;
&lt;h2 id=&quot;network&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#network&quot; aria-label=&quot;network permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Network&lt;/h2&gt;
&lt;h3 id=&quot;how-does-a-node-realize-it-missed-one-block&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-does-a-node-realize-it-missed-one-block&quot; aria-label=&quot;how does a node realize it missed one block permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How does a node realize it missed one block?&lt;/h3&gt;
&lt;p&gt;In the Bitcoin network, each peer maintains a full copy of the ledger (blockchain).&lt;/p&gt;
&lt;p&gt;What would happen if a node lost one of in its blocks in the blockchain (e.g. another process on the peer accidentally wiped out the disk area that stores the block)?&lt;/p&gt;
&lt;p&gt;Will this peer be able to detect that this block is missing? If yes, how will the peer detect it and how is it going to repair?&lt;/p&gt;
&lt;p&gt;It depends on the implementation. For Bitcoin Core, the node maintains a database which has the locations of all blocks on disk.&lt;/p&gt;
&lt;p&gt;If a block is deleted, then it will notice that the location of a block either does not exist or contains garbage or invalid data.&lt;/p&gt;
&lt;p&gt;If it does notice that a block is missing (or something is corrupted), it will attempt to rebuild the database using the blocks stored on disk and then download the missing blocks from its peers.&lt;/p&gt;
&lt;p&gt;However, blocks can actually be deleted after they have been verified and the local database has updated so that the node knows the block it has just deleted was a valid block.&lt;/p&gt;
&lt;p&gt;This is called pruning, and with pruning, old, historical blocks can be deleted as they aren&apos;t used for anything in normal node operation (except helping new nodes sync).&lt;/p&gt;
&lt;h2 id=&quot;incentive&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#incentive&quot; aria-label=&quot;incentive permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Incentive&lt;/h2&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/09bea87a43ea78c058fe28629ab80946/c8e86/fees.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 23.926380368098158%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAACE4AAAhOAFFljFgAAABE0lEQVR42h1Qy27CMBDMN/baj6mqFkEfn9D/4NaKE5VagShxbMdPEogh3LlOJ3tY2Z7deayrEP7g/QbDYHA47NG2vzDmW+7HY4MQtrD2ByntcL0GOade39c4nTQuFwdXr9D5NXUMqmH4oMgjYnxB0zyRMCdhQaE5a0F8zsFnbDYP6Lo3ODcjtpBZa2dI+RXh6x5ldccAa1Q5BzYUH5mDLbSe3JNgXReRs4NSOwrsadailF7KGEVxjdY7hO0S+fMdrmXClDLqWnHlguneNFrKe8934loDyZZluInD7XajqaHRgetepKfqGlYr4hpVCFNCS+KJyXo5Y4wiOI4jkx+ZtGMaJ9j5fBajiVNKEVHvA78nSv0DwUhfGiMkpcgAAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/09bea87a43ea78c058fe28629ab80946/0cbef/fees.avif 163w,
/static/09bea87a43ea78c058fe28629ab80946/bffb7/fees.avif 325w,
/static/09bea87a43ea78c058fe28629ab80946/69c29/fees.avif 650w,
/static/09bea87a43ea78c058fe28629ab80946/9eff3/fees.avif 758w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/09bea87a43ea78c058fe28629ab80946/94563/fees.webp 163w,
/static/09bea87a43ea78c058fe28629ab80946/647a8/fees.webp 325w,
/static/09bea87a43ea78c058fe28629ab80946/c1dc5/fees.webp 650w,
/static/09bea87a43ea78c058fe28629ab80946/c4e8e/fees.webp 758w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/09bea87a43ea78c058fe28629ab80946/222b7/fees.png 163w,
/static/09bea87a43ea78c058fe28629ab80946/ff46a/fees.png 325w,
/static/09bea87a43ea78c058fe28629ab80946/a6d36/fees.png 650w,
/static/09bea87a43ea78c058fe28629ab80946/c8e86/fees.png 758w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/09bea87a43ea78c058fe28629ab80946/a6d36/fees.png&quot;
            alt=&quot;fees&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Because of the decreasing amount of BTC that is paid as a reward (due to the halving), the incentive for nodes to mine also decreases.&lt;/p&gt;
&lt;p&gt;To compensate for that, Nakamoto introduces a secondary incentive: &lt;em&gt;transaction fees&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;These fees should replace, at some point in the future, the mined block reward.&lt;/p&gt;
&lt;p&gt;At the beginning of 2022 block rewards still are greater than transaction fees, so miners still focus on them as their main source of income.&lt;/p&gt;
&lt;p&gt;Either the fees need to increase significantly (a problem currently for Ethereum), or the price of BTC itself should climb much higher. These are the only ways in which the transition can occur.&lt;/p&gt;
&lt;p&gt;If neither happens, miners will abandon the network, therefore lowering the security of the blockchain and entering a negative feedback loop.&lt;/p&gt;
&lt;h2 id=&quot;reclaiming-disk-space&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#reclaiming-disk-space&quot; aria-label=&quot;reclaiming disk space permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Reclaiming Disk Space&lt;/h2&gt;
&lt;h3 id=&quot;pruning&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#pruning&quot; aria-label=&quot;pruning permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Pruning&lt;/h3&gt;
&lt;p&gt;Pruning allows a node to free up storage space by removing transactions that are no longer needed to verify that the blockchain is in a consistent state (i.e. no bitcoins were created improperly).&lt;/p&gt;
&lt;p&gt;Estimates of needing to store only a portion of data versus the ~500 GB we are approaching reduces the cost required at least for mobile storage by about $10.&lt;/p&gt;
&lt;p&gt;As for growth, storage requirements for a pruned node scale more closely with how bitcoins are distributed in the unspent transaction set (a.k.a. UTXO). This means storage will grow O(the number of users) rather than with O(the number of transactions).&lt;/p&gt;
&lt;p&gt;At these levels it starts to be practical for a phone or tablet to run a pruned node. This is useful for those that want a greater level of trust with their mobile wallets as well as those who wish to help Bitcoin nodes with bandwidth and connectivity challenges to keep up to date.&lt;/p&gt;
&lt;p&gt;This development should help Bitcoin to extend its network reach and improve the trust level possible on commodity phones, tablets, and network equipment, be that mobile or otherwise.&lt;/p&gt;
&lt;h3 id=&quot;how-a-utxo-works&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-a-utxo-works&quot; aria-label=&quot;how a utxo works permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;How a UTXO Works&lt;/h3&gt;
&lt;p&gt;UTXO transactions sound complicated, but they really are fairly simple. UTXO or &lt;em&gt;unspent transaction outputs&lt;/em&gt; are used in cryptocurrency transactions.&lt;/p&gt;
&lt;p&gt;These are the transactions that are left unspent after someone completes a transaction, similar to the &lt;em&gt;change&lt;/em&gt; someone receives after conducting a cash transaction at the store.&lt;/p&gt;
&lt;p&gt;Here&apos;s how it works. A UTXO database is used to store change from cryptocurrency transactions. This database or ledger is initially set to empty or zero. As transactions occur, the database becomes populated with change records from various transactions.&lt;/p&gt;
&lt;p&gt;When a transaction is completed and there are outputs that aren&apos;t spent, they are deposited back into a database as inputs that can be used at a later date for a new transaction.&lt;/p&gt;
&lt;p&gt;Cryptocurrency transactions —such as those used for bitcoins— are similar to &lt;a href=&quot;https://www.investopedia.com/terms/c/cashierscheck.asp&quot;&gt;cashier checks&lt;/a&gt;. You cannot exchange them for custom amounts and must spend the entire amount stored in that data byte.&lt;/p&gt;
&lt;p&gt;But cryptocurrencies like bitcoin are also unique in that transactions can be conducted using fractions of the cryptocurrency. This means spending does not take place using a single data byte.&lt;/p&gt;
&lt;p&gt;Instead, multiple fractions of bitcoin are retrieved by the algorithm to fulfill a spending request.&lt;/p&gt;
&lt;p&gt;For example, a purchase worth 1 bitcoin may retrieve 0.6 BTC from one byte and 0.4 BTC from another. Change from each of these fractions is then sent to the UTXO database to be spent at a later date.&lt;/p&gt;
&lt;h2 id=&quot;simplified-payment-verification&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#simplified-payment-verification&quot; aria-label=&quot;simplified payment verification permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Simplified Payment Verification&lt;/h2&gt;
&lt;h3 id=&quot;has-the-strategy-of-network-node-alerts-ever-worked&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#has-the-strategy-of-network-node-alerts-ever-worked&quot; aria-label=&quot;has the strategy of network node alerts ever worked permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Has the strategy of network node alerts ever worked?&lt;/h3&gt;
&lt;p&gt;The network wide alert system was created by Satoshi Nakamoto as a means of informing Bitcoin users of any important information regarding Bitcoin.&lt;/p&gt;
&lt;p&gt;It has been used in the past to inform users about important network events such as accidental blockchain forks.&lt;/p&gt;
&lt;p&gt;However, the alert system also represents a large source of centralization in Bitcoin. The holders of the singular Alert Key can at any time send an alert which could affect the entire network.&lt;/p&gt;
&lt;p&gt;As more developers join, the alert key is given to others, but cannot be taken away from those who have left.&lt;/p&gt;
&lt;p&gt;This has led to the alert key potentially falling into the hands of malicious actors who could use it to disrupt the network.&lt;/p&gt;
&lt;p&gt;Because there is only one alert key, it is not possible to prevent former developers from sending an alert nor is it possible to identify who sent an alert.&lt;/p&gt;
&lt;p&gt;In addition, the alert system is primarily Bitcoin Core specific. Many other wallets have their own systems in place but still must have handling for the alert system because it is network wide. Something specific for one software should not be imposed on the entire network.&lt;/p&gt;
&lt;p&gt;The alert system has also lost its usefulness. It is no longer necessary to use it to inform users about problematic network events as users can easily get their information from any major Bitcoin news outlet.&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Examining the Bitcoin Whitepaper - Part 1/3]]></title><description><![CDATA[A post to understand key concepts behind the famous Bitcoin whitepaper. Part 1/3]]></description><link>https://www.j1nma.com/bitcoin-whitepaper-overview/</link><guid isPermaLink="false">https://www.j1nma.com/bitcoin-whitepaper-overview/</guid><pubDate>Fri, 01 Jul 2022 00:00:00 GMT</pubDate><content:encoded>&lt;h4 id=&quot;whats-this-post-about&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#whats-this-post-about&quot; aria-label=&quot;whats this post about permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;em&gt;What’s this post about?&lt;/em&gt;&lt;/h4&gt;
&lt;p&gt;This is a three part post where I explain concepts included in the famous white-paper that are not introduced nor described beforehand, and are important to have a better grasp of the problems tackled by Bitcoin. They are divided into the same sections of the paper.&lt;/p&gt;
&lt;p&gt;This is not a one-stop-shop for Bitcoin or crypto, but a good catch-most of the under-explained concepts in the original whitepaper. Also, this is not financial advise, nor am I trying to evangelize this to you. :)&lt;/p&gt;
&lt;h4 id=&quot;how-to-make-the-best-out-of-this-post&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#how-to-make-the-best-out-of-this-post&quot; aria-label=&quot;how to make the best out of this post permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;&lt;em&gt;How to make the best out of this post&lt;/em&gt;&lt;/h4&gt;
&lt;p&gt;I believe the best way to understand the original paper is to have this post by your side, stop here for the tricky and technological concepts,
and return to reading the paper. There is no specific order, and you can skip any section (specially the mathy ones).&lt;/p&gt;
&lt;p&gt;This is Part 1. Check Part 2 &lt;a href=&quot;https://www.j1nma.com/bitcoin-whitepaper-overview-part-2&quot;&gt;here&lt;/a&gt;, and Part 3 &lt;a href=&quot;https://www.j1nma.com/bitcoin-whitepaper-overview-part-3&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;table-of-contents&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#table-of-contents&quot; aria-label=&quot;table of contents permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Table of Contents&lt;/h2&gt;
&lt;!-- TOC --&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#table-of-contents&quot;&gt;Table of Contents&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#introduction&quot;&gt;Introduction&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#reversibility-of-transactions&quot;&gt;Reversibility of transactions&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#escrow-mechanisms&quot;&gt;Escrow mechanisms&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#double-spending-problem&quot;&gt;Double Spending Problem&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#peer-to-peer-network&quot;&gt;Peer-to-peer Network&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#p2p-distributed-timestamp-server&quot;&gt;P2P distributed timestamp server&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#cryptographic-hash&quot;&gt;Cryptographic Hash&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#transactions&quot;&gt;Transactions&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#mint&quot;&gt;Mint&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#proof-of-work-adam-backs-hashcash&quot;&gt;Proof of Work: Adam Back’s Hashcash&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;#rewards-for-your-work&quot;&gt;Rewards for your Work&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#nonce&quot;&gt;Nonce&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- /TOC --&gt;
&lt;h2 id=&quot;introduction&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#introduction&quot; aria-label=&quot;introduction permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Introduction&lt;/h2&gt;
&lt;p&gt;The paper starts with an introduction on the trust inherent to the commerce on the Internet, particularly on the costs of transactions. At one point, Nakamoto talks about the impossibility of &lt;em&gt;non-reversible&lt;/em&gt; transactions, and the cost of their mediation. Let’s stop here and dig deeper into what this means.&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/004353bf6711267cb5119684a0d2dc8c/cd7c1/intro.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 41.104294478527606%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAIAAAB2/0i6AAAACXBIWXMAAAsTAAALEwEAmpwYAAABWElEQVR42oWQT0/CQBDF+/2/AYnGCAQTIyFGhbM34xFaurP/Z7eULa20WDhAUnXE6NXJZvLbN5vsvBft9/uu65qmCSFsNpuiKAi22y2Jn/9V1Lbt6XSq6xoAOOdSSgKl1PF4pPHHubrf+uG/Hh0Oe2PosVyvc/rYe7daeepaqzzPrNXeo3OWDueQ5ytjNAGJxFHdvAM4o9dxrJKlSVNS35TKhMyE8FrnNKWuVE4jxrAsW8YcsbU+auoXwS+kHKbppRBXSl2X5UTwvtaDlF0oNdB6qHXfu5H3N/N5z9qhtaMk7kn5Sp5jIcYcHhkbCzGx5gnYeLG4rapnizOtHkhxboY45TBOkju0U87vuZiEIKKmaZdLA0CW3PJ7bSNlRqB0jhgQC2OCcwUtnCQaAMmCEI48Miai3W53zoBRPFVVUlQADNFYa0JYI1qaUoRZ5gFSulKoUnICRPwCocKmF9bhoBgAAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/004353bf6711267cb5119684a0d2dc8c/0cbef/intro.avif 163w,
/static/004353bf6711267cb5119684a0d2dc8c/bffb7/intro.avif 325w,
/static/004353bf6711267cb5119684a0d2dc8c/69c29/intro.avif 650w,
/static/004353bf6711267cb5119684a0d2dc8c/6d24a/intro.avif 975w,
/static/004353bf6711267cb5119684a0d2dc8c/a2baf/intro.avif 1300w,
/static/004353bf6711267cb5119684a0d2dc8c/95ec4/intro.avif 1547w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/004353bf6711267cb5119684a0d2dc8c/94563/intro.webp 163w,
/static/004353bf6711267cb5119684a0d2dc8c/647a8/intro.webp 325w,
/static/004353bf6711267cb5119684a0d2dc8c/c1dc5/intro.webp 650w,
/static/004353bf6711267cb5119684a0d2dc8c/1e975/intro.webp 975w,
/static/004353bf6711267cb5119684a0d2dc8c/063bf/intro.webp 1300w,
/static/004353bf6711267cb5119684a0d2dc8c/0dd1a/intro.webp 1547w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/004353bf6711267cb5119684a0d2dc8c/222b7/intro.png 163w,
/static/004353bf6711267cb5119684a0d2dc8c/ff46a/intro.png 325w,
/static/004353bf6711267cb5119684a0d2dc8c/a6d36/intro.png 650w,
/static/004353bf6711267cb5119684a0d2dc8c/e548f/intro.png 975w,
/static/004353bf6711267cb5119684a0d2dc8c/3c492/intro.png 1300w,
/static/004353bf6711267cb5119684a0d2dc8c/cd7c1/intro.png 1547w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/004353bf6711267cb5119684a0d2dc8c/a6d36/intro.png&quot;
            alt=&quot;intro&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Trusted third parties like financial institutions, banks and credit card issuers are responsible for resolving disagreements between parties. In order to resolve them, they need to do extra checks which have a cost. Consequently, any transaction whose value is lower than the cost of validating it is simply not profitable and won’t be done.&lt;/p&gt;
&lt;p&gt;So small transactions like buying a soda can or buying a digital copy of a song worth a couple of dollars are thus impossible, and the client is only left with more expensive options, like subscribing to a music service with a greater monthly cost.&lt;/p&gt;
&lt;h3 id=&quot;reversibility-of-transactions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#reversibility-of-transactions&quot; aria-label=&quot;reversibility of transactions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Reversibility of transactions&lt;/h3&gt;
&lt;p&gt;But money is not the only cost in this. On the one hand, in order to be able to make complaints and &lt;em&gt;reverse&lt;/em&gt; transactions, merchants/sellers first need information from their customers. On the other hand, if transactions were non-reversible they could be cleared without collecting any private information.&lt;/p&gt;
&lt;p&gt;The non-reversibility of payments proposes two things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;merchants are protected since buyers can’t cancel their payments&lt;/li&gt;
&lt;li&gt;buyers are protected through &lt;strong&gt;escrow&lt;/strong&gt; mechanisms (delaying payment until the goods or services have been received)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Bitcoin transactions are irreversible and can only be refunded by the receiving party—a key difference from credit card transactions that can be canceled, through mechanisms which add costs to transactions and set a minimum viable transaction value.&lt;/p&gt;
&lt;p&gt;The escrow mechanisms are not part of the solution proposed by the paper, but have been implemented by third parties, for a fee of course. Indeed, a middle man charging for escrow. Kind of contradictory, perhaps?&lt;/p&gt;
&lt;h3 id=&quot;escrow-mechanisms&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#escrow-mechanisms&quot; aria-label=&quot;escrow mechanisms permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Escrow mechanisms&lt;/h3&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/826b3b57bac2c33fb722871420e71f26/0faf1/escrow.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 10.429447852760736%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAACCAYAAABYBvyLAAAACXBIWXMAACE4AAAhOAFFljFgAAAAeklEQVR42i2MvQ6DMBCDef9nKQUEWzshaCU2NpJAfm5vojyB60QMlk/2d25SSlBKQSRQAq01nHvD+w4hTDiOB86zxXX1MKZlN1AjrB3IT+w63k/yL8T4Q5NzvkccQ18lshNamH35sHJsJTPX25jiC/tP7YtbW5iNgxF/hPmM5IOZYS8AAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/826b3b57bac2c33fb722871420e71f26/0cbef/escrow.avif 163w,
/static/826b3b57bac2c33fb722871420e71f26/bffb7/escrow.avif 325w,
/static/826b3b57bac2c33fb722871420e71f26/69c29/escrow.avif 650w,
/static/826b3b57bac2c33fb722871420e71f26/6d24a/escrow.avif 975w,
/static/826b3b57bac2c33fb722871420e71f26/a2baf/escrow.avif 1300w,
/static/826b3b57bac2c33fb722871420e71f26/0f59d/escrow.avif 1956w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/826b3b57bac2c33fb722871420e71f26/94563/escrow.webp 163w,
/static/826b3b57bac2c33fb722871420e71f26/647a8/escrow.webp 325w,
/static/826b3b57bac2c33fb722871420e71f26/c1dc5/escrow.webp 650w,
/static/826b3b57bac2c33fb722871420e71f26/1e975/escrow.webp 975w,
/static/826b3b57bac2c33fb722871420e71f26/063bf/escrow.webp 1300w,
/static/826b3b57bac2c33fb722871420e71f26/8488f/escrow.webp 1956w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/826b3b57bac2c33fb722871420e71f26/222b7/escrow.png 163w,
/static/826b3b57bac2c33fb722871420e71f26/ff46a/escrow.png 325w,
/static/826b3b57bac2c33fb722871420e71f26/a6d36/escrow.png 650w,
/static/826b3b57bac2c33fb722871420e71f26/e548f/escrow.png 975w,
/static/826b3b57bac2c33fb722871420e71f26/3c492/escrow.png 1300w,
/static/826b3b57bac2c33fb722871420e71f26/0faf1/escrow.png 1956w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/826b3b57bac2c33fb722871420e71f26/a6d36/escrow.png&quot;
            alt=&quot;escrow&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;An &lt;em&gt;escrow&lt;/em&gt; is a financial and legal agreement that protects both buyers and sellers in a transaction in exchange for a fee. This fee is paid to an independent third party that holds the payment until everyone carries out their responsibilities in the agreement.&lt;/p&gt;
&lt;p&gt;As an example, if buyer B wants to buy something from seller S, B is at risk of being scammed by S if the latter does not deliver the goods or services of the transaction. How can B recover the BTC spent, given the fact that bitcoin is non-refundable?&lt;/p&gt;
&lt;p&gt;Bitcoin escrow mechanisms exist for this purpose, most only accepting legal merchandise.&lt;/p&gt;
&lt;p&gt;For illegal activities, which I hope the reader is far from being involved in, some BTC escrows, such as the Dark Bitcoin Escrow, accept illegal goods and services (stolen credit cards, drugs, unregistered guns, fake currency).&lt;/p&gt;
&lt;p&gt;Naturally, these mechanisms are frequented by thieves and gang members who don&apos;t want to get scammed by other thieves and gang members.&lt;/p&gt;
&lt;h3 id=&quot;double-spending-problem&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#double-spending-problem&quot; aria-label=&quot;double spending problem permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Double Spending Problem&lt;/h3&gt;
&lt;p&gt;Later on, the authors propose a “solution to the double-spending problem using a peer-to-peer distributed timestamp server to generate computational proof of the chronological order of transactions.” There’s a lot to unpack here, so let’s go step by step.&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/169e3/doublespending.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 15.950920245398773%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAIAAAAcOLh5AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAnklEQVR42g3KywqDMBQEUP//NwpttZZ+SPGVmESMTW6eFtwUQV1FejfDmWGylBLApPXovcZclnmaBEJKHqNxTqGNmeZorP0ASDRCqWHft+xM23d+AeQhlDE+rSu8f1hbaH3DtLZU6mrM3Zgi+DKG0rkcDwCX44DsPJOUjJC675thoIRU48gorRjrELhTWnPecU6EoEKQtn1jZaxZ198fY8KZCHxWdMoAAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/0cbef/doublespending.avif 163w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/bffb7/doublespending.avif 325w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/69c29/doublespending.avif 650w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/6d24a/doublespending.avif 975w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/a2baf/doublespending.avif 1300w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/eb5ad/doublespending.avif 1682w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/94563/doublespending.webp 163w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/647a8/doublespending.webp 325w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/c1dc5/doublespending.webp 650w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/1e975/doublespending.webp 975w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/063bf/doublespending.webp 1300w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/9aab7/doublespending.webp 1682w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/222b7/doublespending.png 163w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/ff46a/doublespending.png 325w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/a6d36/doublespending.png 650w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/e548f/doublespending.png 975w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/3c492/doublespending.png 1300w,
/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/169e3/doublespending.png 1682w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/4d8f4a7b21ea1d3bb0ffe4179ed12ffc/a6d36/doublespending.png&quot;
            alt=&quot;doublespending&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Firstly, what’s the double-spending problem?&lt;/p&gt;
&lt;p&gt;My favorite Reddit subreddit, &lt;a href=&quot;https://www.reddit.com/r/explainlikeimfive/&quot;&gt;r/explainlikeimfive&lt;/a&gt;, opens up possibilities for many wise surfers of the web to describe this sort of concept in a very didactic manner. The following explanation is a digested extraction of this and &lt;a href=&quot;https://www.reddit.com/r/explainlikeimfive/comments/82y7u8/comment/dve152f/?utm_source=share&amp;#x26;utm_medium=web2x&amp;#x26;context=3&quot;&gt;this&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Double spending&lt;/em&gt; is essentially the version of counterfeit money for digital money. With a digital currency like bitcoin, your money exists as a file. So what is stopping you from copying that file (money) and using both copies to buy things? It’s like buying a chocolate bar with one dollar bill, and a pen with another bill, but the bills are actually identical.&lt;/p&gt;
&lt;p&gt;The blockchain comes to solve this. It is basically a history of all transactions of that digital currency. It works via agreement among all people who have copies of that blockchain. The key is that transactions on the blockchain are only considered valid if a &lt;strong&gt;majority&lt;/strong&gt; of the people have agreed to that specific blockchain.&lt;/p&gt;
&lt;p&gt;If you attempted to use a single unit of digital currency in two different transactions, it is possible that both transactions end up in different blockchains, but eventually one of them will be rejected and only the other one will be valid according to the majority of the network, so the one and only digital currency is &quot;spent&quot; and can&apos;t be used again.&lt;/p&gt;
&lt;p&gt;As you may have noticed, the double spending problem in a digital currency system is fundamentally about the &lt;em&gt;chronological order&lt;/em&gt; in which transactions happen. Let’s go over it once again with an example.&lt;/p&gt;
&lt;p&gt;If A has $100 in their account, and tries to send $100 to each of B and C, obviously only B or C would get the money. Which of them gets it first depends on the order in which the transactions happen. If A sends $100 to B first, and then tries to send $100 to C, B would get the money and the second transaction would be rejected.&lt;/p&gt;
&lt;p&gt;In a &lt;strong&gt;centralized&lt;/strong&gt; digital currency systems (e.g. e-banking), there is a single entity (the bank) tracking transactions, so the double spending problem is “easy” to stop. Whichever transaction that entity receives first goes through and others are rejected. The chronological order of transactions (and thus which one is &quot;first&quot;) is well-defined here since there is only a single entity responsible for tracking and ordering them.&lt;/p&gt;
&lt;p&gt;However, in a &lt;strong&gt;decentralized&lt;/strong&gt; digital current systems (e.g. Bitcoin), the order is &lt;em&gt;not&lt;/em&gt; well-defined. If A broadcasts both transactions near-simultaneously, one person (or a validator node in the network of the blockchain) may receive the transaction to B first, another person may receive the transaction to C first.&lt;/p&gt;
&lt;p&gt;Thus, Bitcoin ends up being the first successful system to solve the double spending problem with blockchain technology.&lt;/p&gt;
&lt;p&gt;The blockchain allows a decentralized crowd to record and order information (in this case, transaction data) that is extremely difficult to modify once recorded. This allows all Bitcoin nodes to agree as to which of the two conflicting transaction happened &quot;&lt;strong&gt;first&lt;/strong&gt;&quot;.&lt;/p&gt;
&lt;p&gt;Secondly, what’s a peer-to-peer network?&lt;/p&gt;
&lt;h3 id=&quot;peer-to-peer-network&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#peer-to-peer-network&quot; aria-label=&quot;peer to peer network permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Peer-to-peer Network&lt;/h3&gt;
&lt;p&gt;In a P2P network, every participant plays the same role; they are all peers. Each peer is both a client - requesting data, and a server - providing data. When you compare it to a regular website, this makes it a lot more robust.&lt;/p&gt;
&lt;p&gt;A peer is usually connected to several other peers and if one goes offline, everything still works as usual. This makes blockchain networks very robust.&lt;/p&gt;
&lt;p&gt;The nature of the network being P2P allows it to avoid any third party, any financial institution, and instead depend on the effort of each and everyone of the peers involved.&lt;/p&gt;
&lt;p&gt;Thirdly, what is a timestamp server?&lt;/p&gt;
&lt;h2 id=&quot;p2p-distributed-timestamp-server&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#p2p-distributed-timestamp-server&quot; aria-label=&quot;p2p distributed timestamp server permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;P2P distributed timestamp server&lt;/h2&gt;
&lt;p&gt;In Bitcoin’s P2P network, all the transactions are public to all the participants of the networks, namely, the nodes.&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/bedfd091a55f9381beffc592afda7b0c/99661/solution1.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 16.56441717791411%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAYAAACTWi8uAAAACXBIWXMAACE4AAAhOAFFljFgAAAArklEQVR42j2MzQqCUBSEff9VZdCyRWpRBD1E2xaBkP+oiRpXRAPNNJjmarQY5uPMnFGEuMOyLojjG4LAhO9fEYYnskHpsO0NPM8Y3XU1Sh9d5mG4Y6bxx6C2qCoTihBnmOYaUXTk6IHFPUsrFlQ4zpyskpccnI0sNd0X7Kq/fM5xA2WZQKnrJ8ciZFmOJEmQ5w8Op0hTgaKo8HoNaNseTfMm93+W3nUym3KpYfjgCzch1DvHkimUAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/bedfd091a55f9381beffc592afda7b0c/0cbef/solution1.avif 163w,
/static/bedfd091a55f9381beffc592afda7b0c/bffb7/solution1.avif 325w,
/static/bedfd091a55f9381beffc592afda7b0c/69c29/solution1.avif 650w,
/static/bedfd091a55f9381beffc592afda7b0c/6d24a/solution1.avif 975w,
/static/bedfd091a55f9381beffc592afda7b0c/2fdb2/solution1.avif 1098w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/bedfd091a55f9381beffc592afda7b0c/94563/solution1.webp 163w,
/static/bedfd091a55f9381beffc592afda7b0c/647a8/solution1.webp 325w,
/static/bedfd091a55f9381beffc592afda7b0c/c1dc5/solution1.webp 650w,
/static/bedfd091a55f9381beffc592afda7b0c/1e975/solution1.webp 975w,
/static/bedfd091a55f9381beffc592afda7b0c/4eac3/solution1.webp 1098w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/bedfd091a55f9381beffc592afda7b0c/222b7/solution1.png 163w,
/static/bedfd091a55f9381beffc592afda7b0c/ff46a/solution1.png 325w,
/static/bedfd091a55f9381beffc592afda7b0c/a6d36/solution1.png 650w,
/static/bedfd091a55f9381beffc592afda7b0c/e548f/solution1.png 975w,
/static/bedfd091a55f9381beffc592afda7b0c/99661/solution1.png 1098w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/bedfd091a55f9381beffc592afda7b0c/a6d36/solution1.png&quot;
            alt=&quot;solution1&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This public record attempts to solve the double spending problem. But enforcing all nodes to agree at all times about the single source of truth of the transactions is not a trivial task.&lt;/p&gt;
&lt;p&gt;The solution proposed includes making the nodes agree on the order of transactions. This means that if two transactions involve the same coin (double spending &lt;em&gt;it&lt;/em&gt;), then the one that is kept will be solved.&lt;/p&gt;
&lt;p&gt;So what is the criteria used to decide which one comes first? Nakamoto proposes a timestamp server.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A timestamp server works by taking a hash of a block of items to be timestamped and widely publishing the hash, such as in a newspaper or Usenet post [2–5]. The timestamp proves that the data must have existed at the time, obviously, in order to get into the hash. Each timestamp includes the previous timestamp in its hash, forming a chain, with each additional timestamp reinforcing the ones before it.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Firstly, a timestamp is just a string of characters that identify a specified date and time of day, often with seconds to add to the accuracy and a timezone indication. For example, “20/12/2021 12:00:00 -0400”.&lt;/p&gt;
&lt;p&gt;Generally, a timestamp is added to something else. In this case, a collection of transactions, a &lt;em&gt;block&lt;/em&gt;, will be timestamped. The transactions in it don’t compete with each other to be the last one standing in the chain, so grouping them together is more efficient than having each transaction hold one timestamp. The timezone of reference is London local time, UTC-0.]&lt;/p&gt;
&lt;p&gt;Secondly, the block of transaction or items is then &lt;em&gt;“hashed”&lt;/em&gt; and made public to the rest of the network. But what is a hash?&lt;/p&gt;
&lt;h3 id=&quot;cryptographic-hash&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#cryptographic-hash&quot; aria-label=&quot;cryptographic hash permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Cryptographic Hash&lt;/h3&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/fdc2c5ec7a83b32fbba0761aeb94de06/136a2/transactions.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 23.926380368098158%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAACE4AAAhOAFFljFgAAABC0lEQVR42nVR206DQBTk/39Aq4lVEz/AB1MjGhPjk4+lXApLwfal6U0K5bYsOw770PjiSYZZZs7ZnAGrrmssl9+IY4EkiSFEhCDwkecZhtK6H57/QmuNv2VlWYb9/ojDocRmc8RuV2C7zVEUDaTs0bY9qkqiaTqcTi3KskVdK6Kjr6k39Cv2tQaW54XcyobnXXOzW4ThGPP5GKvVA6bTETe/x2x2Rb6D44zo3ZAv6V0YLYq+qAn4vsfZEFYQhHDdD+KR5jPS9I3GhGwbTpIXwsZ6/WlYiAk/0Tv9V/Y/8VKH2oLzLs8xrDRNOLhgzB8ohXPMAVIq8z5AKU1NMWKPrtPnPik7E3X4F0PkX+7gcW7QZlcmAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/fdc2c5ec7a83b32fbba0761aeb94de06/0cbef/transactions.avif 163w,
/static/fdc2c5ec7a83b32fbba0761aeb94de06/bffb7/transactions.avif 325w,
/static/fdc2c5ec7a83b32fbba0761aeb94de06/69c29/transactions.avif 650w,
/static/fdc2c5ec7a83b32fbba0761aeb94de06/93034/transactions.avif 884w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/fdc2c5ec7a83b32fbba0761aeb94de06/94563/transactions.webp 163w,
/static/fdc2c5ec7a83b32fbba0761aeb94de06/647a8/transactions.webp 325w,
/static/fdc2c5ec7a83b32fbba0761aeb94de06/c1dc5/transactions.webp 650w,
/static/fdc2c5ec7a83b32fbba0761aeb94de06/8af20/transactions.webp 884w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/fdc2c5ec7a83b32fbba0761aeb94de06/222b7/transactions.png 163w,
/static/fdc2c5ec7a83b32fbba0761aeb94de06/ff46a/transactions.png 325w,
/static/fdc2c5ec7a83b32fbba0761aeb94de06/a6d36/transactions.png 650w,
/static/fdc2c5ec7a83b32fbba0761aeb94de06/136a2/transactions.png 884w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/fdc2c5ec7a83b32fbba0761aeb94de06/a6d36/transactions.png&quot;
            alt=&quot;transactions&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In plain terms, a hash is a function that receives an input A (of arbitrary length, and mostly an alphanumeric text) and returns an output B (often of a specific size, like 256 characters) in such a way that it is extremely hard to create an inverse function, that is, a function that takes B and outputs A.&lt;/p&gt;
&lt;p&gt;A ‘good’ hash:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Is easy to calculate for any input.&lt;/li&gt;
&lt;li&gt;Makes it  &lt;a href=&quot;https://simple.wikipedia.org/wiki/Computational_complexity_theory&quot;&gt;extremely computationally difficult&lt;/a&gt;  to calculate or find an input that has a given hash.&lt;/li&gt;
&lt;li&gt;Has an extremely low probability of having two different messages with the same hash.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So to put it shortly, a hash is a short string of charaters that can be computed easily, but cannot be reversed. It’s a small pseudo-random summary or fingerprint of the input. This fingerprint determines the exact moment in which the block of transactions was &lt;em&gt;mined&lt;/em&gt; and validated.&lt;/p&gt;
&lt;p&gt;In relation to the timestamp, the hash is made from it, among others things (previous block header hash, difficulty, &lt;a href=&quot;#nonce&quot;&gt;nonce&lt;/a&gt; and Merkle root). The moment the hash is published, the block’s data (including the timestamp that the hash sums up) guarantees that it must have existed at the time of creation.&lt;/p&gt;
&lt;p&gt;Thirdly, but most importantly, as new blocks of transactions are put together, each new hash is calculated with the previous block’s hash. If you trace the path from the latest block in the blockchain, jumping blocks one hash at a time backwards, you will eventually reach the &lt;em&gt;genesis&lt;/em&gt; block, the very first block that was produced.&lt;/p&gt;
&lt;p&gt;I will spare you the search of when this block’s timestamp: January 3rd 2009, 18:15:05h UTC.&lt;/p&gt;
&lt;p&gt;This traceability guarantees a linear order of blocks in which the entire network agrees upon. To mess with this chain, an attacker would have to brake the hash of the target block, and every single block after it; a practically impossible task (at least as of the time of writing). So if a block B’s hash was computed from a block A’s hash, this proves that the block A came before block B.&lt;/p&gt;
&lt;p&gt;As hard as it is to rewrite the chain’s history, it is computationally easy to verify a block’s hash: anyone can check that block B’s hash results from block A’s hash by recomputing it. This verification is key for network nodes to rest assured that any incoming blocks (and their transactions) have not been modified in any way.&lt;/p&gt;
&lt;h2 id=&quot;transactions&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#transactions&quot; aria-label=&quot;transactions permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Transactions&lt;/h2&gt;
&lt;p&gt;By introducing the chain of digital signatures, Nakamoto states that the payee can verify the signatures to verify the chain of ownership. But a problem is then posed. How can a payee verify that the received coin was not double-spent?&lt;/p&gt;
&lt;p&gt;A common solution is to introduce a trusted central authority, or mint.&lt;/p&gt;
&lt;h3 id=&quot;mint&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#mint&quot; aria-label=&quot;mint permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Mint&lt;/h3&gt;
&lt;p&gt;Investopedia defines mint concisely:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;A mint is a primary producer of a country&apos;s coin currency, and it has the consent of the government to manufacture coins to be used as legal tender.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Along with production, the mint is also responsible for the distribution of the currency, protection of the mint&apos;s assets, and overseeing its various production facilities.&lt;/p&gt;
&lt;h2 id=&quot;proof-of-work-adam-backs-hashcash&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#proof-of-work-adam-backs-hashcash&quot; aria-label=&quot;proof of work adam backs hashcash permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Proof of Work: Adam Back’s Hashcash&lt;/h2&gt;
&lt;p&gt;Now that we saw what a P2P distributed timestamp server is and how blocks of transactions are hashed, let&apos;s dive deep into how this all works together.&lt;/p&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/7e0502ce29ea845160fdcf6be83392ad/42de8/hashcash.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 27.607361963190186%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAACE4AAAhOAFFljFgAAABQUlEQVR42o2QS0/CQBDH+/304tXPIhFDMH4PT8STMTEKPlJFehGRWvpm+6AEwoEDUPru39mNMfHmJL/MzM5/Z2ZXqusanCRJUFUViqJAWZaI41ic8Zif/9ek9XotLsmyDFVVMRgMMBwO0e/3BYqiwHVdIeaD/1r9A369lCQZsqyijVJstwl2uxT7fSbyzSYm9pSnSNOCdKUgzzkVMqIoa+QF96BaDomxF2jaHXEP234EY6+YzRRMJl2BYfTgOM/Q9R7FDxiPb0XseW9wR1fwPztw3y/hfnRgmSok225QsYUoalOzJolPsFicw7JOiSbm8zaWywtMp2ci51pNa9DQFjz5GJPrAxg3h3C7R3CsJ0i6bpE4ILEjvOeFtOmUtmI0IKCYIQgihOGcGpn0zxp8PyStj9Uigu/oML5GYI5JLzDxDZS5sxA/IxSWAAAAAElFTkSuQmCC&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/7e0502ce29ea845160fdcf6be83392ad/0cbef/hashcash.avif 163w,
/static/7e0502ce29ea845160fdcf6be83392ad/bffb7/hashcash.avif 325w,
/static/7e0502ce29ea845160fdcf6be83392ad/69c29/hashcash.avif 650w,
/static/7e0502ce29ea845160fdcf6be83392ad/6d24a/hashcash.avif 975w,
/static/7e0502ce29ea845160fdcf6be83392ad/e8a68/hashcash.avif 1033w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/7e0502ce29ea845160fdcf6be83392ad/94563/hashcash.webp 163w,
/static/7e0502ce29ea845160fdcf6be83392ad/647a8/hashcash.webp 325w,
/static/7e0502ce29ea845160fdcf6be83392ad/c1dc5/hashcash.webp 650w,
/static/7e0502ce29ea845160fdcf6be83392ad/1e975/hashcash.webp 975w,
/static/7e0502ce29ea845160fdcf6be83392ad/de74f/hashcash.webp 1033w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/7e0502ce29ea845160fdcf6be83392ad/222b7/hashcash.png 163w,
/static/7e0502ce29ea845160fdcf6be83392ad/ff46a/hashcash.png 325w,
/static/7e0502ce29ea845160fdcf6be83392ad/a6d36/hashcash.png 650w,
/static/7e0502ce29ea845160fdcf6be83392ad/e548f/hashcash.png 975w,
/static/7e0502ce29ea845160fdcf6be83392ad/42de8/hashcash.png 1033w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/7e0502ce29ea845160fdcf6be83392ad/a6d36/hashcash.png&quot;
            alt=&quot;hashcash&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Hashcash&lt;/em&gt; uses a &lt;em&gt;proof-of-work&lt;/em&gt; technique to prove an email is not spam.
Bitcoin mining also uses a proof-of-work system, but in its case, to prove a block of transactions is valid. In order to implement a distributed timestamp server on a peer-to-peer basis, Satoshi mentions the need of a mechanism that validates transactions on the network.&lt;/p&gt;
&lt;p&gt;The idea behind Hashcash is pretty simple. In order to prove an email is not spam, the sending software must solve a small but CPU-intensive math problem. The answer to the math problem is included in the email header, which is read by the receiving email  software.&lt;/p&gt;
&lt;p&gt;This prevents spam because spammers send millions of emails each day. Having to solve a small (but CPU-intensive, aka, high electricity costs) math problem for each of those millions of emails would require a lot of very expensive hardware, which makes sending spam /unprofitable/.&lt;/p&gt;
&lt;h3 id=&quot;rewards-for-your-work&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#rewards-for-your-work&quot; aria-label=&quot;rewards for your work permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Rewards for your Work&lt;/h3&gt;
&lt;p&gt;The whole point of Bitcoin mining is verifying transactions. Mining doesn&apos;t solely exist to generate more coins. The coins that are generated are given to the miners as a &lt;em&gt;reward&lt;/em&gt; for verifying transactions. People will still have to mine even when there are no more coins to generate, because transactions still need to be verified forever and ever.&lt;/p&gt;
&lt;p&gt;A transaction occurs anytime someone sends Bitcoins to another person. Each transaction needs to be verified to ensure it&apos;s legit, e.g. ensuring the sender did in fact send the coins, and ensuring the sender had the coins to send.&lt;/p&gt;
&lt;p&gt;Without verifying transactions, people could create their &lt;em&gt;own fake coins&lt;/em&gt; and send them to themselves, or they could pull a &lt;em&gt;double spending&lt;/em&gt; attack, which, as we have seen, is sending the same coins to more than one person.&lt;/p&gt;
&lt;p&gt;So someone (or something) needs to verify each transaction. But Bitcoin is a distributed system without any central authority, so who/what exactly verifies transactions?&lt;/p&gt;
&lt;p&gt;The answer is the miner &lt;em&gt;who did the most work&lt;/em&gt; to prove the transaction. This is where proof-of-work comes into play. In order for a block of transactions to be verified and added to the blockchain, a miner must solve a very complicated math problem. A problem that is so complicated that miners need to buy restrictively expensive hardware, and it&apos;s impossible to predict &lt;em&gt;which&lt;/em&gt; miner will solve the problem.&lt;/p&gt;
&lt;p&gt;The verification process prevents double spending because the person trying to execute the double spend would have to verify their own fake transaction, which, because of proof-of-work, is impossible.&lt;/p&gt;
&lt;p&gt;It&apos;s impossible to verify your own transactions because of the complicated random nature of the math problem that needs to be solved. There are millions of other miners trying to verify the same transactions, and the chances of your miner verifying the transaction is practically zero. You are competing with /every other miner on the planet/ to find the next block. If you &quot;win&quot;, you get the block reward plus you get to choose which transactions are included in your block. If somebody else wins, you get no say in the matter. Unless you have a very large mining operation, the chance of you winning is so small that it&apos;s never going to happen.&lt;/p&gt;
&lt;p&gt;So miners verify transactions by solving complicated math problems, and as a reward the Bitcoin network &quot;rewards&quot; the miner who verified a block of transactions with a set number of coins.&lt;/p&gt;
&lt;p&gt;In fact, the miner who solved the problem creates the coins and gives them to themselves!&lt;/p&gt;
&lt;p&gt;When no more Bitcoins can be generated, miners will continue to mine to collect the fee attached to each transaction, paid by the sender.&lt;/p&gt;
&lt;h3 id=&quot;nonce&quot; style=&quot;position:relative;&quot;&gt;&lt;a href=&quot;#nonce&quot; aria-label=&quot;nonce permalink&quot; class=&quot;anchor before&quot;&gt;&lt;svg aria-hidden=&quot;true&quot; focusable=&quot;false&quot; height=&quot;16&quot; version=&quot;1.1&quot; viewBox=&quot;0 0 16 16&quot; width=&quot;16&quot;&gt;&lt;path fill-rule=&quot;evenodd&quot; d=&quot;M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/a&gt;Nonce&lt;/h3&gt;
&lt;p&gt;&lt;span
      class=&quot;gatsby-resp-image-wrapper&quot;
      style=&quot;position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 650px; &quot;
    &gt;
      &lt;a
    class=&quot;gatsby-resp-image-link&quot;
    href=&quot;/static/89c3c21b41f6d7f7dfa5e3ae7d18f475/c4b7c/nonce.png&quot;
    style=&quot;display: block&quot;
    target=&quot;_blank&quot;
    rel=&quot;noopener&quot;
  &gt;
    &lt;span
    class=&quot;gatsby-resp-image-background-image&quot;
    style=&quot;padding-bottom: 22.085889570552148%; position: relative; bottom: 0; left: 0; background-image: url(&apos;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAECAYAAACOXx+WAAAACXBIWXMAACE4AAAhOAFFljFgAAAA70lEQVR42j1Qy07DMBDM98M3lKogVHGA0lIRIYQQf8ClVhs7Jm6cxKFJiqOI6zD2gcNqPDve2UdirUVZOuR5haKoUVUd+QmHgyFv/mO/LyL2/QjnBjQh6g5d94O2G3HqPYJXkmUSdf0GrefY7WZQ6gZZtqDBFd/XkHJBPocQMxizxDS9wvsUw/CMfkjxe17Di0tM5RJ+9EikVCx85+cti7c0eqTBmhNvmN9w0hW1lNoTtQfGKupC3EN/vUCJO4iPC+jPW6hcIWnbsO4xruPcmSaWBi7ygFpXXOUUTxK4MXU8TchZ+40yYDPAHFs2lfgD6qwb+HT1EJ0AAAAASUVORK5CYII=&apos;); background-size: cover; display: block;&quot;
  &gt;&lt;/span&gt;
  &lt;picture&gt;
          &lt;source
              srcset=&quot;/static/89c3c21b41f6d7f7dfa5e3ae7d18f475/0cbef/nonce.avif 163w,
/static/89c3c21b41f6d7f7dfa5e3ae7d18f475/bffb7/nonce.avif 325w,
/static/89c3c21b41f6d7f7dfa5e3ae7d18f475/69c29/nonce.avif 650w,
/static/89c3c21b41f6d7f7dfa5e3ae7d18f475/158b1/nonce.avif 903w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/avif&quot;
            /&gt;&lt;source
              srcset=&quot;/static/89c3c21b41f6d7f7dfa5e3ae7d18f475/94563/nonce.webp 163w,
/static/89c3c21b41f6d7f7dfa5e3ae7d18f475/647a8/nonce.webp 325w,
/static/89c3c21b41f6d7f7dfa5e3ae7d18f475/c1dc5/nonce.webp 650w,
/static/89c3c21b41f6d7f7dfa5e3ae7d18f475/4673f/nonce.webp 903w&quot;
              sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
              type=&quot;image/webp&quot;
            /&gt;
          &lt;source
            srcset=&quot;/static/89c3c21b41f6d7f7dfa5e3ae7d18f475/222b7/nonce.png 163w,
/static/89c3c21b41f6d7f7dfa5e3ae7d18f475/ff46a/nonce.png 325w,
/static/89c3c21b41f6d7f7dfa5e3ae7d18f475/a6d36/nonce.png 650w,
/static/89c3c21b41f6d7f7dfa5e3ae7d18f475/c4b7c/nonce.png 903w&quot;
            sizes=&quot;(max-width: 650px) 100vw, 650px&quot;
            type=&quot;image/png&quot;
          /&gt;
          &lt;img
            class=&quot;gatsby-resp-image-image&quot;
            src=&quot;/static/89c3c21b41f6d7f7dfa5e3ae7d18f475/a6d36/nonce.png&quot;
            alt=&quot;nonce&quot;
            title=&quot;&quot;
            loading=&quot;lazy&quot;
            decoding=&quot;async&quot;
            style=&quot;width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;&quot;
          /&gt;
        &lt;/picture&gt;
  &lt;/a&gt;
    &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Nonce, or a &quot;number only used once,&quot; refers to the first number a blockchain miner needs to discover before solving for a block in the blockchain.&lt;/p&gt;
&lt;p&gt;Adding transactions to the blockchain requires substantial computer processing power. The individuals and companies who process blocks, the miners, are compensated only if they are the &lt;em&gt;first&lt;/em&gt; to create a hash that meets a certain set of requirements, called the target hash.&lt;/p&gt;
&lt;p&gt;The process of guessing the hash starts in the block header. It contains the block version number, a timestamp, the hash used in the previous block, the hash of the Merkle Root (a data structure with references to other hashes), the nonce, and the target hash.&lt;/p&gt;
&lt;p&gt;If the hash meets the requirements set forth in the target, then the block is added to the blockchain. Cycling through solutions in order to guess the nonce is the famous proof of work, and the miner who is able to find the value is awarded the block and paid in the cryptocurrency.&lt;/p&gt;</content:encoded></item></channel></rss>