<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Christos Alexiou</title>
    <description>The latest articles on Forem by Christos Alexiou (@christosalexiou).</description>
    <link>https://forem.com/christosalexiou</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F359651%2F4fb350a3-94b1-4f66-a6c2-f93808237d4d.jpg</url>
      <title>Forem: Christos Alexiou</title>
      <link>https://forem.com/christosalexiou</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/christosalexiou"/>
    <language>en</language>
    <item>
      <title>Using secrets stored in AWS Secrets Manager as environment variables for ECS container definitions. With Terraform.</title>
      <dc:creator>Christos Alexiou</dc:creator>
      <pubDate>Sat, 10 Dec 2022 14:25:15 +0000</pubDate>
      <link>https://forem.com/christosalexiou/using-secrets-stored-in-aws-secrets-manager-as-environment-variables-for-ecs-container-definitions-with-terraform-4cae</link>
      <guid>https://forem.com/christosalexiou/using-secrets-stored-in-aws-secrets-manager-as-environment-variables-for-ecs-container-definitions-with-terraform-4cae</guid>
      <description>&lt;p&gt;Hello readers. I hope this piece of writing finds you healthy, sitting in a comfortable sofa or desk chair, and enjoying the wintry weather of your country.&lt;/p&gt;

&lt;p&gt;Today, we are going to discuss environment variables in task definitions.&lt;/p&gt;

&lt;h3&gt;
  
  
  The scenario
&lt;/h3&gt;

&lt;p&gt;Given a managed cluster in AWS ECS, that was created using AWS Terraform provider, you are challenged to securely configure environment variables in the task definitions of each one of your cluster tasks, which you are also managing with Terraform - because Terraform all the things.&lt;/p&gt;

&lt;h3&gt;
  
  
  The manifesto
&lt;/h3&gt;

&lt;p&gt;There are countless ways of handling application secrets today, probably as many as the people who write software. I am not trying to preach on whether this is the right way to do it, or if it's the most secure or comfortable. But, I know for a fact that many people will end up in situations where this piece of writing will become a useful guide.&lt;/p&gt;

&lt;h3&gt;
  
  
  The implementation
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Directory structure
&lt;/h4&gt;

&lt;p&gt;I was either lucky or farsighted when I was deciding on the structure of my Terraform code. This wonderful occasion allowed me to have the resources for the tasks, the services, and all of the paraphernalia in the same module letting me make direct references between them without worrying about inheritance or inclusion.&lt;/p&gt;

&lt;p&gt;For this article, it is enough for the reader to be aware of the following directory structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;├── services.tf
├── task_env_vars.tf
└── tasks. tf
├── definitions
│   └── template.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Secrets in AWS Secrets Manager
&lt;/h4&gt;

&lt;p&gt;AWS Secrets Manager helps you manage, retrieve, and rotate database credentials, API keys, and other secrets throughout their lifecycles. They encrypt the keys using the AWS Key Management Service. I suppose it is secure enough. If you are working for VISA or MasterCard and you think that the level of security they provide is not enough, you probably ought not to read this piece of writing.&lt;/p&gt;

&lt;p&gt;I am not managing the secrets that are stored in AWS Secrets Manager with Terraform. I chose to manage those secrets using the AWS Console interface, and this is the path I've taken, although not ideal.&lt;/p&gt;

&lt;p&gt;If the reader wants to go the route of managing the secrets with Terraform, the &lt;a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret" rel="noopener noreferrer"&gt;required documentation is here&lt;/a&gt; and it's extremely straightforward.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft5o9yf7sqn3m6ioka61h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft5o9yf7sqn3m6ioka61h.png" alt="The AWS Console interface for the AWS Secrets Manager service. Showcasing one created secret called " width="800" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For us, plebes, I am going to continue writing with the standpoint that the secrets are created through the interface, as I did, for instance, for the secret values that I want to be used as environment variables in a service that I wrote that's responsible for mailing.&lt;/p&gt;

&lt;h5&gt;
  
  
  Creating a secret
&lt;/h5&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzci0okvwl7q8fhdb1nft.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzci0okvwl7q8fhdb1nft.png" alt="The interface of AWS Console for creating a new secret in AWS Secrets Manager, with the option of " width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When prompted by the wizard of the AWS Secrets Manager, we shall select the option &lt;strong&gt;"Other type of secret"&lt;/strong&gt;. This will enable us to store secrets in a key/value structure, that will prove particularly useful when handling this data for use with our task definitions.&lt;/p&gt;

&lt;p&gt;We can fill the text boxes with whatever we fancy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F75npoe1hy99q76pssvot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F75npoe1hy99q76pssvot.png" alt="Filling one of the key value text boxes with key=X_API_KEY and value=123abc" width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once we are done filling all the key/value pairs for the secret, we hit "Next" to finalize and name our secret, ignoring all the other options - at least for our case.&lt;/p&gt;

&lt;p&gt;Since I am planning to use this secret in a service that does mailing, I named it &lt;em&gt;mailing-env&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;Now, the secret is available to us through the AWS API and thus, the Terraform provider.&lt;/p&gt;

&lt;h4&gt;
  
  
  Retrieving the secret
&lt;/h4&gt;

&lt;p&gt;With the secret available in AWS Secrets Manager, we can use the data source &lt;a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/secretsmanager_secret_version" rel="noopener noreferrer"&gt;&lt;code&gt;aws_secretsmanager_secret_version&lt;/code&gt;&lt;/a&gt; to retrieve the secret.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;data "aws_secretsmanager_secret_version" "mailing" {
  secret_id = "mailing-env"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Formatting the secret's values for further use
&lt;/h4&gt;

&lt;p&gt;Because the received data are encoded and do not have the proper naming conventions for us to use right away in our task definitions, we have to do some local processing, to get them into an appropriate state.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;locals {
  mailing_secrets = jsondecode(data.aws_secretsmanager_secret_version.mailing.secret_string)

  mailing_secrets_list = [
    for name, value in local.mailing_secrets : {
      name  = name
      value = value
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are using the &lt;a href="https://developer.hashicorp.com/terraform/language/functions/jsondecode" rel="noopener noreferrer"&gt;&lt;code&gt;jsondecode&lt;/code&gt;&lt;/a&gt; function to get a representation of the result as Terraform language values.&lt;/p&gt;

&lt;p&gt;The next endeavor is creating a list of environment variables in a way that we benefit from.&lt;/p&gt;

&lt;p&gt;Since AWS expects the environment variables to be passed as &lt;a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/taskdef-envfiles.html" rel="noopener noreferrer"&gt;key/value pairs with &lt;code&gt;name&lt;/code&gt; - &lt;code&gt;value&lt;/code&gt; notation&lt;/a&gt;, we are using terraform's &lt;code&gt;for&lt;/code&gt; looping functionality to craft a list of objects.&lt;/p&gt;

&lt;h4&gt;
  
  
  Modelling the task definition with the help of templates
&lt;/h4&gt;

&lt;p&gt;To make life easier and code cleaner, I've abstracted the task definition to a separate template file and stored it in &lt;code&gt;definitions/template.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The bit that should be interesting to the reader of this essay is the following. The rest of the definition is boilerplate code that can be found in the &lt;a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition#example-using-container_definitions-and-inference_accelerator" rel="noopener noreferrer"&gt;appropriate documentation&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
    {
        "environment": ${jsonencode(environment)}
    }
]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To use the template, we are relying on Terraform's &lt;a href="https://developer.hashicorp.com/terraform/language/functions/templatefile" rel="noopener noreferrer"&gt;&lt;code&gt;templatefile&lt;/code&gt;&lt;/a&gt; which renders the template for us and contains it in a single variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;locals {
  mailing_definition = templatefile("${path.module}/definitions/template.json", {
    environment = local.mailing_secrets_list
  })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Using the task definition in a task resource
&lt;/h4&gt;

&lt;p&gt;The last step, although not strictly relevant to this article, is taking advantage of the task definition we created.&lt;/p&gt;

&lt;p&gt;Using &lt;a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition" rel="noopener noreferrer"&gt;&lt;code&gt;aws_ecs_task_definition&lt;/code&gt;&lt;/a&gt; we can assign the value of the &lt;code&gt;local.mailing_definition&lt;/code&gt; to the &lt;code&gt;container_definitions&lt;/code&gt; attribute.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "aws_ecs_task_definition" "mailing" {
   container_definitions = local.mailing_definition
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The gist
&lt;/h3&gt;

&lt;p&gt;The reason this article exists is that I didn't find a similar one. But, seldom is parthenogenesis in software, and this solution is no different.&lt;/p&gt;

&lt;p&gt;These are the resources that led me to this solution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackoverflow.com/questions/67913171/how-to-pass-a-list-in-template-file-var-section-instead-of-string-in-terraform" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/67913171/how-to-pass-a-list-in-template-file-var-section-instead-of-string-in-terraform&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/hashicorp/terraform-provider-aws/issues/6503" rel="noopener noreferrer"&gt;https://github.com/hashicorp/terraform-provider-aws/issues/6503&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>discuss</category>
    </item>
    <item>
      <title>The multiple faces of WebRTC N-peer calling: Mesh, MCU and SFU</title>
      <dc:creator>Christos Alexiou</dc:creator>
      <pubDate>Sun, 25 Sep 2022 21:39:42 +0000</pubDate>
      <link>https://forem.com/christosalexiou/the-multiple-faces-of-webrtc-n-peer-calling-mesh-mcu-and-sfu-39dg</link>
      <guid>https://forem.com/christosalexiou/the-multiple-faces-of-webrtc-n-peer-calling-mesh-mcu-and-sfu-39dg</guid>
      <description>&lt;p&gt;It was approximately 458BC when Aeschylus wrote the play &lt;em&gt;Agamemnon&lt;/em&gt;. The Greek commander has just returned from the long war in Troy, only to be murdered by his wife Clytemnestra. &lt;/p&gt;

&lt;p&gt;The play starts and ends in tragedy, but that's what it is after all. Don't fret though, reader, because the chorus suggests that nothing goes unpunished and that the gods may send Orestes, Agamemnon's son, to restore justice.&lt;/p&gt;

&lt;p&gt;Aeschylus will aid the gods with the completion of the scheme &lt;code&gt;Hubris, Ates, Nemesis, and eventually Tisis&lt;/code&gt; with the help of his masterful writing. While telling the story, he goes into the trouble of describing to the audience one of the ingenious ways the Greeks used to move information across really large geographical areas; &lt;em&gt;fryctories&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The system of &lt;em&gt;fryctories&lt;/em&gt; or άγγαρον πυρ (meaning, &lt;em&gt;the telling fire&lt;/em&gt;) consisted of Greek soldiers lighting fires on top of mountains and hills across a vast geographical region to transport a message. Unfortunately, the system was binary, so only a certain pre-agreed message could be communicated.&lt;/p&gt;

&lt;p&gt;One might say, it was one of the first peer-to-peer systems that relied on technology to transfer information that was used for communication purposes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flhjnjpinxhsadxw5reur.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flhjnjpinxhsadxw5reur.jpg" alt="Image description" width="520" height="371"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  WebRTC
&lt;/h2&gt;

&lt;p&gt;The need for communication, and especially peer-to-peer, didn't end with the Trojan war. Eventually, people would have to develop solutions that wouldn't rely on fire, weather conditions, and the terrain of a region. With these prerequisites in mind (or not) Justin Uberti and Peter Thatcher wrote a little piece of software that is called WebRTC.&lt;/p&gt;

&lt;p&gt;What it does, essentially, is allow direct peer-to-peer communication between parties, particularly for video and audio.&lt;/p&gt;

&lt;p&gt;The collection of codecs, encoders, and processing software is usually bundled in APIs that become available to programming languages through browsers or third-party libraries.&lt;/p&gt;

&lt;p&gt;As adoption grew for WebRTC (for example, all major video conferencing software in the world takes advantage of it - Zoom, Slack, etc) base level peer-to-peer communication became a bottleneck for developing features that would enable more complex software features to be written. So, the WebRTC community found alternative ways of utilizing it by setting up the topology differently.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9hru2gb221bf8wc3ynvy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9hru2gb221bf8wc3ynvy.png" alt="Image description" width="800" height="598"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Mesh
&lt;/h2&gt;

&lt;p&gt;Supposing a multiparty where you want to have a group call between the &lt;code&gt;n&lt;/code&gt; members. We will abstract the calculations in the end, but for now, let's assume that &lt;code&gt;n = 5&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The 5 participants of the group are trying to communicate with each other, sharing audio and video. The first and most naive approach to enable this communication is to use a mesh network.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fprpcb2ngkufkpmvz5r85.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fprpcb2ngkufkpmvz5r85.png" alt="Image description" width="637" height="635"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this topology, all participants are directly connected with peer-to-peer connections. So, in this case, we have 5 participants with each one having 4 connections to the rest with a total number of 10 connections. We assume that each connection that will be presented in this article, either upstream or downstream, will be a 1mbps connection. &lt;/p&gt;

&lt;p&gt;The total upstream in such a case will be the multiplication of 1 connection with the number of upstream connections we have. So, that would be &lt;code&gt;4 x 1 Mbps = 4mbps total upstream.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The downstream, in a similar fashion, will be &lt;code&gt;4 x 1 Mbps = 4mbps total downstream&lt;/code&gt;. The total bandwidth requirements are then &lt;code&gt;5 participants x 4 Mbps = 20mbps.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Taking a step back we can see that:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;total bandwidth required = number of participants x number connections x connection bandwidth&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or &lt;/p&gt;

&lt;p&gt;&lt;code&gt;TBR = n * (n-1) * abr&lt;/code&gt; where &lt;code&gt;abr&lt;/code&gt; is average bandwidth requirement&lt;/p&gt;

&lt;p&gt;Assuming an average connection bandwidth of 1mbps we can see that for 15 people (which is the average number of students in a school class in the country where the author resides) a typical COVID19-era class would need:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;TBR = 15 * 14 * 1 = 210 Mbps&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Since the user is picking the entire tab this is extremely impractical.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Participants&lt;/th&gt;
&lt;th&gt;Connections (Total)&lt;/th&gt;
&lt;th&gt;Downstream&lt;/th&gt;
&lt;th&gt;Upstream&lt;/th&gt;
&lt;th&gt;Total&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;4 (10)&lt;/td&gt;
&lt;td&gt;4mbps&lt;/td&gt;
&lt;td&gt;4mbps&lt;/td&gt;
&lt;td&gt;20mbps&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  MCU
&lt;/h2&gt;

&lt;p&gt;Assuming the same scenario as above, with a 5-member multiparty group call we can improve upon the naivety of the mesh topology by introducing a centralized composition system, or as engineers usually refer to them; media servers.&lt;/p&gt;

&lt;p&gt;One might refer to this topology as "the star" approach since the media server sits "in the middle" composing the upstream videos of each participant into a single stream that then sends to the participants who receive it downstream.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fur98ql15g6c19pd8kb62.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fur98ql15g6c19pd8kb62.png" alt="Image description" width="746" height="653"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This topology requires extra CPU as the media server controlled by the provider needs to provide a composite video to each of the participants. At least, it seems like this approach has a 1-1 match as each one of the members sends 1 upstream and receives 1 downstream in return.&lt;/p&gt;

&lt;p&gt;This means that each user is sending 1 Mbps of data while also receiving an equivalent amount back.&lt;/p&gt;

&lt;p&gt;In this case for the user of this topology:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;total bandwidth required = n x (average bandwidth requirement x 1 + average bandwidth requirement x 1)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or &lt;/p&gt;

&lt;p&gt;&lt;code&gt;TBR = n * (2 * abr)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Supposing the 15 people classroom example, a call between them would require:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;TBR = 15 * (2 * 1) = 30 Mbps&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The only concern is now CPU time, but that is something that we can mitigate either by scaling horizontally or vertically, provided that we can run the media servers in a distributed fashion.&lt;/p&gt;

&lt;p&gt;MCU seems promising both for the individual users and also for the network.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Participants&lt;/th&gt;
&lt;th&gt;Connections (Total)&lt;/th&gt;
&lt;th&gt;Downstream&lt;/th&gt;
&lt;th&gt;Upstream&lt;/th&gt;
&lt;th&gt;Total&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;1 (5)&lt;/td&gt;
&lt;td&gt;1 mbps&lt;/td&gt;
&lt;td&gt;1 mbps&lt;/td&gt;
&lt;td&gt;10 mbps&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  SFU
&lt;/h2&gt;

&lt;p&gt;The most modern approach to date is to use an SFU (Selective Forwarding Unit), something that could be resembled a routing service. With the SFU, each participant sends its upstream towards the SFU media server and then that will selectively route this to all other participants.&lt;/p&gt;

&lt;p&gt;How much information is going to send, what will that be, and to who depends on the specific way the SFU was programmed along with the network policy defined within the SFU.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F74beuqqxlwsazc5o77ol.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F74beuqqxlwsazc5o77ol.png" alt="Image description" width="711" height="644"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the case of 5 participants, there are going to be 5 connections for each one of them, which translates to 25 total connections across the network.&lt;/p&gt;

&lt;p&gt;Each participant has 1 upstream connection and 4 downstream connections, all originating from the SFU media server. Supposing we use the same Average Connection Bandwidth with the other topologies, the upstream bandwidth is 1 Mbps and the downstream is 4 Mbps.&lt;/p&gt;

&lt;p&gt;This makes the total bandwidth requirement across the network to be 25 Mbps.&lt;/p&gt;

&lt;p&gt;The approach is costlier for the user because while the upstream bandwidth remains at 1 Mbps, the downstream bandwidth is now in direct relationship with the number of participants that the call group will have.&lt;/p&gt;

&lt;p&gt;But, the CPU cost of the SFU architecture is far lesser than the equivalent cost required from the MCU architecture.&lt;/p&gt;

&lt;p&gt;Increasing the level of abstraction we can see that:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;total bandwidth required = number of participants x (upstream bandwidth + downstream bandwidth)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or &lt;/p&gt;

&lt;p&gt;&lt;code&gt;TBR = n * (abr * (n - 1) + abr * 1)&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;In the example of 15 students attending a video call, the total bandwidth requirement would be &lt;/p&gt;

&lt;p&gt;&lt;code&gt;TBR = 15 * (1 * 14 + 1 * 1) = 225 mbps&lt;/code&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Participants&lt;/th&gt;
&lt;th&gt;Connections (Total)&lt;/th&gt;
&lt;th&gt;Downstream&lt;/th&gt;
&lt;th&gt;Upstream&lt;/th&gt;
&lt;th&gt;Total&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;5 (25)&lt;/td&gt;
&lt;td&gt;4 mbps&lt;/td&gt;
&lt;td&gt;1 mbps&lt;/td&gt;
&lt;td&gt;25 mbps&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;There is &lt;em&gt;no one solution that fits all sizes&lt;/em&gt; in the case of multiparty video/audio streaming or calling. Depending on the specific application requirements the programmer can make decisions on how to architect the network topology so that she gets the most value out of the available resources, including virtual network bandwidth, CPU time, and user resources.&lt;/p&gt;

&lt;p&gt;Each topology has its benefits and drawbacks in different use cases. &lt;/p&gt;

&lt;p&gt;As a rule of thumb, it seems that the mesh network approach fits solutions that limit the number of participants and want to avoid centralized infrastructure costs but bearing in mind that users will have to pick up the network costs.&lt;/p&gt;

&lt;p&gt;The MCU is resource intensive and requires a centralized infrastructure that is responsible for compositing media. Encoding is an expensive process that will require increased resources if the solution needs to be scaled. On the bright side, the bandwidth requirements for the user are minimal.&lt;/p&gt;

&lt;p&gt;The middle ground is covered by the SFU architecture. Although still requiring centralized infrastructure, the SFU media server is essentially a byte shifter, forwarding media streams to each participant, making it way less CPU intensive than the MCU approach. This keeps the upstream bandwidth requirements for the user minimal but is increasing the downstream requirement.&lt;/p&gt;

&lt;p&gt;With some clever programming and the use of efficient codecs and compression, it's possible to decrease the upstream and downstream bandwidth requirements and eliminate some connections in certain cases. We won't get into details this time as it would be out of scope.&lt;/p&gt;

</description>
      <category>webrtc</category>
      <category>networking</category>
    </item>
    <item>
      <title>A streamlined view into data integrity and confidentiality in modern Linux environments</title>
      <dc:creator>Christos Alexiou</dc:creator>
      <pubDate>Wed, 29 Sep 2021 13:33:14 +0000</pubDate>
      <link>https://forem.com/christosalexiou/a-streamlined-view-into-data-integrity-and-confidentiality-in-modern-linux-environments-2fhd</link>
      <guid>https://forem.com/christosalexiou/a-streamlined-view-into-data-integrity-and-confidentiality-in-modern-linux-environments-2fhd</guid>
      <description>&lt;h2&gt;
  
  
  Current state of encryption on Generic Linux Distributions
&lt;/h2&gt;

&lt;p&gt;Linux has had support for &lt;em&gt;Full Disk Encryption&lt;/em&gt; and technologies such as &lt;em&gt;UEFI Secure Boot&lt;/em&gt; and &lt;em&gt;TPMs&lt;/em&gt; for a long time. They are usually set up suboptimally in distributions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Supported&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[x] Full Disk Encryption&lt;/li&gt;
&lt;li&gt;[x] UEFI SecureBoot&lt;/li&gt;
&lt;li&gt;[x] TPMs&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tools &amp;amp; Mechanisms
&lt;/h2&gt;

&lt;p&gt;We can separate the mechanisms and tools that we have to perform confidentiality and integrity operations in our systems in two large categories; &lt;em&gt;disk encryption&lt;/em&gt; and &lt;em&gt;data authentication&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;Before we dive into the direction of listing the technologies and tools that are available for each aformentioned category, it would be useful to explain the two concepts. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disk encryption&lt;/em&gt; translates into the process of transforming the data contained within a disk in such a way that reading them in clear-text form is only possible if you possess a secret of some form, usually a password/passphrase. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Data authentication&lt;/em&gt; means that there are mechanisms in place verifying that no one can make changes to the data on disk unless they have a secret of some sort.&lt;/p&gt;

&lt;p&gt;Technologies empowering &lt;em&gt;disk encryption&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LUKS/cryptsetup&lt;/li&gt;
&lt;li&gt;dm-crypt&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Technologies empowering &lt;em&gt;data authentication&lt;/em&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LUKS/cryptsetup&lt;/li&gt;
&lt;li&gt;dm-verity&lt;/li&gt;
&lt;li&gt;dm-integrity&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since we have stated that both &lt;em&gt;disk encryption&lt;/em&gt; and &lt;em&gt;data authentication&lt;/em&gt; require a secret of some form, we can talk about TPMs. We will focus on one facet of TPMs capabilities, that of protecting secrets. TPMs, in general, release the secret keys only if the code that booted the host can be authenticated. The whole process is roughly explained below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;every boot component is hashed with a cryptographic hash function before it is used&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;resulting hashes are written to TPM's Platform Configuration Registers, essentially a small volatile memory.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;each step of the process writes the hashes of the resources needed for the next boot step&lt;/li&gt;
&lt;li&gt;PCRs are not freely written. The hashes written are combined with what is already stored in PCRs and the result of that is written to PCRs.&lt;/li&gt;
&lt;li&gt;this process is called "measuring"&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;secrets are protected not only by these PCR hashes but are also encrypted using a "seed key" that is generated by the TPM chip itself.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TPMs will enforce a limit on unlock attempts per time ("anti-hammering")&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Distribution exploitation of these practices
&lt;/h2&gt;

&lt;p&gt;In order to understand how these technologies are used in practive in modern Linux distributions we can take a look at the typical boot process of a distribution today (we are assuming - wrongfully so - that every system at hand is UEFI powered): &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;the UEFI firmware invokes &lt;a href="https://github.com/rhboot/shim"&gt;"shim"&lt;/a&gt;, a trivial EFI application stored in the EFI System Partition that, when run, attempts to open and execute another application. The "shim" is signed with a Microsoft key, built into all PCs/laptops. The "shim" is measured by the TPM. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The "shim" then loads the boot loader (often Grub) that is signed by a private key owned by the vendor. The boot loader is stored in the ESP or even a separate boot partition. The components of the boot loader are measured by the TPM.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The boot loader calls the kernel and passes an initial ramdisk image (&lt;code&gt;initrd&lt;/code&gt;) which is the first userspace code encountered in the boot process. The kernel is also signed by the vendor and is validated via the "shim". The &lt;code&gt;initrd&lt;/code&gt; remains unvalidated. Sometimes, the kernel is also measured by the TPM. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The kernel unpacks the &lt;code&gt;initrd&lt;/code&gt; image and invokes what is contained in it. This is the first point that the system will interact with the user, asking him for a password for the encrypted root file system. The &lt;code&gt;initrd&lt;/code&gt; then uses that to setup the encrypted volume. No TPM measuring takes place at this stage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;initrd&lt;/code&gt; moves into the root file system. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The OS itself is up. It will ask the user for a username and a password. At this point no code authentication, no TPM measurements and no data decryption takes place. The username/password combination is only used for unlocking a certain account. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Encryption strategies
&lt;/h2&gt;

&lt;p&gt;Provided that we are seeking to enforce an &lt;em&gt;disk encryption&lt;/em&gt; and/or &lt;em&gt;data authentication&lt;/em&gt; policy we have three operating system areas to include into our encryption strategy. We can, of course, choose to only focus on a specific area rather every one of them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Authentication of OS binaries
&lt;/h3&gt;

&lt;p&gt;Most Linux distributions store system-related binaries under &lt;code&gt;/usr/&lt;/code&gt;. Given that it generally contains no secret data - anyone can download the binaries off the Internet anyway, and the sources too - by encrypting this you'll waste CPU cycles, but beyond that it doesn't hurt much. What you can do, although, is use some form of &lt;em&gt;data authentication&lt;/em&gt; to verify the integrity of the binary files that your operating system is using to perform tasks. This can be achieved by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;making &lt;code&gt;/usr/&lt;/code&gt; a &lt;code&gt;dm-verity&lt;/code&gt; volume. &lt;code&gt;dm-verity&lt;/code&gt; is a concept implemented in the Linux kernel that provides authenticity to read-only block devices: every read access is cryptographically verified against a top-level hash value. It makes the &lt;code&gt;/usr/&lt;/code&gt; tree entirely immutable in a very simple way. However, the traditional &lt;code&gt;rpm/apt&lt;/code&gt; based update logic cannot work in this mode.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;making &lt;code&gt;/usr/&lt;/code&gt; a &lt;code&gt;dm-integrity&lt;/code&gt; volume. &lt;code&gt;dm-integrity&lt;/code&gt; is a concept provided by the Linux kernel that offers integrity guarantees to writable block devices, i.e. in some ways it can be considered to be a bit like &lt;code&gt;dm-verity&lt;/code&gt; while permitting write access. There are multiple ways to use &lt;code&gt;dm-integrity&lt;/code&gt; but the one that's most interesting in this use case would be using it in "stand-alone" mode, but with a keyed hash function (e.g. HMAC). This provides authenticity without encryption: if you make changes to the disk without knowing the secret this will be noticed on the next read attempt of the data and result in IO errors.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Encryption/Authentication of OS configuration and state
&lt;/h3&gt;

&lt;p&gt;The OS state and configuration stores, a.k.a stuff in &lt;code&gt;/etc/&lt;/code&gt; and  &lt;code&gt;/var/&lt;/code&gt; can be considered as the root file system. The root file system should be both encrypted and authenticated since it might contain secret keys, user passwords, sensitive logs and similar. The encryption of choice here is &lt;code&gt;dm-crypt&lt;/code&gt; (LUKS) + &lt;code&gt;dm-integrity&lt;/code&gt;. This provides both authenticity and encryption. The secret key must be provided somehow, ideally by the TPM.&lt;/p&gt;

&lt;h3&gt;
  
  
  Encryption/Authentication of the User's Home Directory
&lt;/h3&gt;

&lt;p&gt;The data in the user's home directory should be encrypted as they usually contain personal and confidential information about the user. &lt;/p&gt;

&lt;p&gt;We've seen the boot process of a system in a previous chapter and we now know that during boot, the data in the disk are decrypted after the invocation of the &lt;code&gt;initrd&lt;/code&gt; image. In order for user specific encryption to make sense we need to get away from the concept of a system wide key and move to a per-user key. That will ensure that the user's password is what unlocks the user's data. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;systemd&lt;/code&gt; provides a service called &lt;code&gt;systemd-homed&lt;/code&gt; that implements this behavior in a safe way: each user gets its own LUKS volume stored in a loopback file in &lt;code&gt;/home/&lt;/code&gt;, and this is enough to synthesize a user account. The encryption password for this volume is the user's account password, thus it's really the password provided at login time that unlocks the user's data. &lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;So, what is the state of encryption in modern day Linux distributions anyway; it's definitely complicated and fragmented. &lt;/p&gt;

&lt;p&gt;And to be honest, I wouldn't expect it to be any other way. Vendors rarely agree on which package manager to ship, little could be done in the direction of a unified encryption strategy. It's up to the user, as is everything in the Linux way of doing things.&lt;/p&gt;

&lt;p&gt;Speaking of idealized systems, I believe that simplicity is the key so that vendors can find a unified pattern of empowering their users to encrypt their data. &lt;/p&gt;

&lt;p&gt;The ideal OS would be simpler without so many moving parts - especially during the boot process. Since UEFI is there and so is ESP, writing everything there would be the simplest solution. That would allow the firmware authenticate the boot &lt;code&gt;loader&lt;/code&gt;/&lt;code&gt;kernel&lt;/code&gt;/&lt;code&gt;initrd&lt;/code&gt; without any further component for this in place.&lt;/p&gt;

&lt;p&gt;In the end, the Linux ecosystem has always been that of a diasporic community and it is this dispersion that feeds creativity and diversity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DISCLAIMER ⚠️&lt;/strong&gt;&lt;br&gt;
This work is inspired by Lennart's Poettering publication on "Authenticated Boot and Disk Encryption on Linux". My goal was to streamline the information so that it is digestible and usable in fast-paced research.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>encryption</category>
      <category>security</category>
    </item>
    <item>
      <title>The Wooden Walls of Athens: the effect of perceived security</title>
      <dc:creator>Christos Alexiou</dc:creator>
      <pubDate>Sun, 03 Jan 2021 14:54:23 +0000</pubDate>
      <link>https://forem.com/christosalexiou/the-wooden-walls-of-athens-the-effect-of-perceived-security-42pb</link>
      <guid>https://forem.com/christosalexiou/the-wooden-walls-of-athens-the-effect-of-perceived-security-42pb</guid>
      <description>&lt;p&gt;In 492 BC &lt;strong&gt;the Persian empire marched against the Greek world&lt;/strong&gt;. Weeks before the first drop of blood would stain the Greek land, &lt;strong&gt;Athenians took the road to Delphi&lt;/strong&gt;, to consult Pythia about the upcoming battles. &lt;/p&gt;




&lt;p&gt;&lt;em&gt;Athena cannot appease Olympian Zeus&lt;br&gt;
With her pleading words and shrewd mêtis,&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Yet I speak this word, firm as adamant.&lt;br&gt;
Though all else within Attica’s border shall be taken&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Even the secret places on divine Mount Kithairon,&lt;br&gt;
Far-sighted Zeus will grant to Athena a wooden wall.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;It alone shall come through uncaptured: good fortune for you and your children.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;But do not wait for the host of foot and horse coming overland!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Do not remain still! Turn your back and retreat.&lt;br&gt;
Someday you will yet oppose them.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;O divine Salamis, you will destroy many women’s children&lt;br&gt;
When Demeter is scattered or gathered in.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fm3atr76m56zuf60h8b8d.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fm3atr76m56zuf60h8b8d.jpg" alt="Alt Text" width="800" height="532"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Back in Athens&lt;/strong&gt;, the words of the oracle were made public and an Assembly was convened to debate them.&lt;/p&gt;

&lt;p&gt;If the Athenians obeyed the oracle to the letter, they would flee their land, avoid all contact with Xerxes’ forces, and found a new city far away, at “the ends of the earth.” Some professional diviners and older citizens indeed urged the people to abandon hope and emigrate. According to their interpretation, the gods had promised to protect their own temples behind the thorny hedge that encircled the Acropolis. &lt;strong&gt;This, they claimed, was the Wooden Wall of the prophecy.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F44gkboy2pjay3ekc5md6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F44gkboy2pjay3ekc5md6.jpg" alt="Alt Text" width="800" height="564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nothing could have been more disastrous for Themistocles and his aggressive naval policy than a sudden Athenian resolution to “turn their backs” on the Persians. It would be up to Themistocles himself &lt;strong&gt;to bend the prophecy to his purpose.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And when the Assembly met to debate the oracle’s meaning, &lt;strong&gt;he did just that.&lt;/strong&gt; The Wooden Wall was not the palisade around the Acropolis, Themistocles said, &lt;strong&gt;but the navy&lt;/strong&gt;. Its triremes, by now numbering two hundred, would be &lt;strong&gt;a wooden bulwark for the people’s defense.&lt;/strong&gt; Apollo had revealed that this floating Wooden Wall would endure and bring benefits for generations to come. The Athenian citizens should man their ships, not to flee, &lt;strong&gt;but to face the Persians at sea.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fr8shym7qf9j5b7jh8c3q.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fr8shym7qf9j5b7jh8c3q.jpg" alt="Alt Text" width="800" height="508"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Themistocles marched and sailed&lt;/strong&gt;. In Salamis, &lt;strong&gt;the Persian fleet was destroyed&lt;/strong&gt;. Salamis is considered one of the battles that have shaped the modern world. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Had the Persians successfully invaded Greece in 490 BC, EMEA history would be different.&lt;/strong&gt; &lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Now,&lt;/strong&gt; I hear the people that clicked this post wanted to learn about security. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Allegories&lt;/strong&gt; were particularly favourable in Ancient Greece and I find myself charmed by the level of intricacy and witting that they require. I  practice their art from time to time and this post seemed like &lt;strong&gt;a good excuse for me to do so.&lt;/strong&gt; &lt;/p&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fc2d9swtfm9zz3kfjt3z6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fc2d9swtfm9zz3kfjt3z6.jpg" alt="Alt Text" width="800" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Security engineers in virtually every organisation train their colleagues on the importance of securing their secrets. &lt;strong&gt;Sec engineers are like the oracles of Delphi.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Trying to predict the attack vectors of a system, constantly evaluating the situation that the system will be operating at, trying to assess the security of the system while always trying to please the manager and not cause a lot of discomfort. &lt;/p&gt;

&lt;p&gt;Exactly like an oracle wants to please the priests while not causing a lot of discomfort to the king that came asking for a prophecy.  &lt;/p&gt;



&lt;p&gt;I have preached countless times on the importance of keeping one's secrets, well, secret. &lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fp9ibflpwtv51fl8fkjeb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fp9ibflpwtv51fl8fkjeb.jpg" alt="Alt Text" width="800" height="679"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Engineers listened. They implemented key stores. &lt;em&gt;Or at least, they thought they did.&lt;/em&gt; Just like Athenians thought they understood Pythia, and &lt;strong&gt;they almost caused the Western civilisation to collapse under the pressure of Eastern forces.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hadn't it been for Themistocles. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I want security engineers to stop acting like oracles and start working like Themistocles.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do not preach of security&lt;/strong&gt;, rather start working towards it. Make engineers &lt;strong&gt;understand how to implement security mechanisms&lt;/strong&gt; and get to the extent of teaching them. &lt;strong&gt;Do not be a contributor to the "perceived security" effect.&lt;/strong&gt;&lt;/p&gt;



&lt;p&gt;In addition to allegories I also enjoy &lt;strong&gt;parables&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Parables are literary creations that allow one to transfer a message to her audience with an expressive and figurative way.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's examine the parable of "the insecure key store."&lt;/strong&gt;&lt;/p&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffxju145a6phg4n0rieki.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffxju145a6phg4n0rieki.jpg" alt="Alt Text" width="520" height="346"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Software applications that implement cryptography &lt;strong&gt;need to create and store cryptographic keys and possibly certificates&lt;/strong&gt; to properly operate and service their clients. &lt;/p&gt;

&lt;p&gt;These keys and certificates might be &lt;strong&gt;stored in memory&lt;/strong&gt; while the application uses them or &lt;strong&gt;stored in a permanent store&lt;/strong&gt; for later use. &lt;/p&gt;

&lt;p&gt;In either case, developers must take the appropriate security measures to limit the access to this store also known as keystore. &lt;/p&gt;

&lt;p&gt;An insecure keystore bug allows an attacker to read cryptographic material such as keys and certificates from the keystore to use them during a cryptographic attack.&lt;/p&gt;



&lt;p&gt;Once, in the city of Sparta, there was an engineer who was &lt;strong&gt;responsible for crafting a saferoom&lt;/strong&gt;, so king Vrasidas can store all of his valuable pieces of information that his spies were collecting from all over Greece and Persia. &lt;/p&gt;

&lt;p&gt;The engineer worked day and night and in a week, he had made the most fancy saferoom that any king has ever seen. &lt;strong&gt;A door so big and tough&lt;/strong&gt; that it would take one thousand Persian horses ramming with their heads against it &lt;strong&gt;to even crack it&lt;/strong&gt;. And &lt;strong&gt;walls so thick and tight&lt;/strong&gt; that you couldn't even hear a thunder when you were inside the room. &lt;/p&gt;

&lt;p&gt;On the door of this masterpiece, &lt;strong&gt;a large golden lock was installed.&lt;/strong&gt; Crafted with the shinier gold which the engineer was able to find in all of Sparta.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fr2bgwmlubwr9szrn1jgf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fr2bgwmlubwr9szrn1jgf.jpg" alt="Alt Text" width="512" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The lock was created by the finest locksmith in the entire province of Lakonia. The key was so heavy that only a true king would be able to lift it and unlock the huge door of the saferoom. &lt;/p&gt;

&lt;p&gt;When king Vrasidas saw the saferoom he was amazed. &lt;strong&gt;He gave to the engineer so much gold that he could build a house out of it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The king went to his room for the night and he slept peacefully after all this time. &lt;strong&gt;He finally knew that his secrets were safe.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The next morning, a farmer walking by the side of the road passed by the saferoom, early in the morning. &lt;/p&gt;

&lt;p&gt;The huge door was open! He walked with cautiousness towards the building thinking that the king has woken up with the first light of the day to study his documents. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ft4r2jt8x5rlznq189ri4.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ft4r2jt8x5rlznq189ri4.jpeg" alt="Alt Text" width="274" height="184"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The saferoom was empty. Completely empty. Not even a single piece of parchment was on the floor or hanging in the walls. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;He started shouting&lt;/strong&gt; until the city guards heard him and urged him to the king. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;- "My king! The door! It was open. The saferoom. There was nothing inside, my king. My king, I know nothing more, please spare me!"&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Vrasidas was pale. He was ready to collapse at his throne. He whispered to the ear of the guard that was standing next to him to fetch the engineer. &lt;/p&gt;

&lt;p&gt;The engineer was sleeping in his house. Around him there were many &lt;em&gt;hetaire&lt;/em&gt;. The guards dragged him, naked as he was, in front of the king.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;- "What's the meaning of all this ?"&lt;/em&gt;, the engineer managed to spell, naked and disorianted as he were.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;- "I have lost all my parchments. Everything is GONE!"&lt;/em&gt;, yelled the Spartan king.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;- "That's impossible.",&lt;/em&gt; said the engineer. &lt;em&gt;"The walls, the door, the lock would be admired even by the gods, my king."&lt;/em&gt;, shouted the engineer trying to excuse himself.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;- "Do you have the key, my king ?",&lt;/em&gt; continued.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;- "I have bedded with the key, like it was my wife, you fool. I have kept it under my pillow, along with my knife so that anyone that came for it would meet my blade!"&lt;/em&gt; the king raged. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;- "May I see it, my King?"&lt;/em&gt; said the engineer. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbe6brlg0eb9o7lvblgwi.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fbe6brlg0eb9o7lvblgwi.jpg" alt="Alt Text" width="170" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;King Vrasidas reached for the key in the chest that one of the guards were carrying up to this moment. he opened it with care, and gave the key to the engineer to inspect. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;- "That's impossible. This can't have happened. Your saferoom can't be breached. This key is &lt;strong&gt;exactly like&lt;/strong&gt; the one Aristarchos, the Lakonian locksmith gave to the Athenian lords, and their saferoom has NEVER been breached".&lt;/em&gt; &lt;/p&gt;



&lt;p&gt;Now, modern engineers are no different species than the engineers of the past. They make mistakes and they can cause a lot of trouble. &lt;/p&gt;

&lt;p&gt;The ancient Spartan engineer thought that by acquiring the same key as his Athenian counterpart, the saferoom for King Vrasidas would be unbreakable. &lt;/p&gt;

&lt;p&gt;As this Java engineer thought that by creating a key store his secrets would be safe.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;KeyStore keyStore = KeyStore.getInstance("JKS");   
String fileName = System.getProperty("java.home") +    
"/lib/security/myKeyStore.jks";   
FileInputStream stream = new FileInputStream(new File(fileName));   
keyStore.load( stream, "storeit".toCharArray()); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;He also forgot that &lt;em&gt;java.home/lib/security&lt;/em&gt; may be readable by everyone. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mistakes are commonplace&lt;/strong&gt;. If you want to have a secure system, be like Themistocles. &lt;strong&gt;Act, before someone puts your city's defence under test.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>crypto</category>
      <category>security</category>
      <category>webdev</category>
      <category>watercooler</category>
    </item>
    <item>
      <title>A story on indexing and why it is important for modern applications</title>
      <dc:creator>Christos Alexiou</dc:creator>
      <pubDate>Sat, 04 Apr 2020 14:38:34 +0000</pubDate>
      <link>https://forem.com/christosalexiou/a-story-on-indexing-and-why-it-is-important-for-modern-applications-oe8</link>
      <guid>https://forem.com/christosalexiou/a-story-on-indexing-and-why-it-is-important-for-modern-applications-oe8</guid>
      <description>&lt;h4&gt;
  
  
  Modern web applications need performance
&lt;/h4&gt;

&lt;p&gt;The majority of modern web applications, if not all of them, are utilising &lt;strong&gt;some kind of data management&lt;/strong&gt; and &lt;strong&gt;storing solution&lt;/strong&gt;. Most of these applications are relying on modern database systems &lt;em&gt;such as MySQL or MongoDB&lt;/em&gt; to name a few.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5Ll-8SYV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://community-cdn-digitalocean-com.global.ssl.fastly.net/assets/tutorials/images/large/Database-Mostov_v4.1_twitter-_-facebook.png%3F1550071669" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5Ll-8SYV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://community-cdn-digitalocean-com.global.ssl.fastly.net/assets/tutorials/images/large/Database-Mostov_v4.1_twitter-_-facebook.png%3F1550071669" width="750" height="375"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As &lt;strong&gt;more and more&lt;/strong&gt; users are &lt;strong&gt;moving their workloads online&lt;/strong&gt;, either in the form of performing simple word processing and light image editing or in heavily CPU and data retrieval bound applications such as BPM solutions for large corporations, &lt;strong&gt;&lt;em&gt;"speed and power"&lt;/em&gt;&lt;/strong&gt; (sic) are indispensable. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n8a7Nf3s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/hO9dyio.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n8a7Nf3s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://i.imgur.com/hO9dyio.jpg" width="382" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Modern database solutions have &lt;strong&gt;a vast amount of perks&lt;/strong&gt; for even a seasoned web developer to utilize in order to make her &lt;strong&gt;application fly&lt;/strong&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  Utilizing indexes for faster data retrieval
&lt;/h4&gt;

&lt;p&gt;Indexing stuff &lt;strong&gt;for the sake of finding it faster&lt;/strong&gt; is not a new kid in the block. For example, &lt;em&gt;scholars in the great Library of Alexandria in Egypt&lt;/em&gt; have been &lt;strong&gt;using a lookup system&lt;/strong&gt; for quickly finding papers that were interesting to them as back as 280BC. That system was &lt;strong&gt;heavily relying on indexing&lt;/strong&gt; and was designed by Calimachus, a poet, critic and scholar of the time. The name of the system was &lt;strong&gt;"Pinakes"&lt;/strong&gt;, translating in English as "Tables". &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gjaKIZsJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s1.dmcdn.net/v/MiLjC1Q797KywoQ5k/x1080" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gjaKIZsJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://s1.dmcdn.net/v/MiLjC1Q797KywoQ5k/x1080" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Is indexing still relevant today ?
&lt;/h5&gt;

&lt;p&gt;Let's start &lt;strong&gt;our short journey&lt;/strong&gt; in indexing by explaining &lt;em&gt;what indexing actually is&lt;/em&gt; in a context &lt;strong&gt;that may actually be useful for modern day data retrieval solutions developers&lt;/strong&gt; and not for ancient Alexandria scholars. &lt;/p&gt;

&lt;p&gt;Typical database systems are storing data on slow disks where I/O bottlenecks are almost innevitable. Even with modern solid state drives the speed of retrieving raw data out of the disk has not given us yet &lt;em&gt;that "whoosh" moment&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Hwe6eQry--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://image.shutterstock.com/image-vector/cartoon-comic-book-sonic-boom-260nw-412369423.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Hwe6eQry--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://image.shutterstock.com/image-vector/cartoon-comic-book-sonic-boom-260nw-412369423.jpg" width="437" height="280"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In-memory database solutions are becoming a thing today with Redis and other caching mechanisms and message brokers but they are still &lt;strong&gt;a long way for being a fully fledged database system&lt;/strong&gt; that we can actually store all of our data - largely due to hardware limitations and cost. &lt;/p&gt;

&lt;p&gt;Even if we utilize such caching solutions like Redis, there is a certainty that on some occassions the application will have to query the database and then, the database retrieve data that they are stored on disk. So, I/O lag &lt;strong&gt;is a thing&lt;/strong&gt; and we have to make up for that by &lt;strong&gt;making our database searches more performant&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;Indexes are an &lt;strong&gt;incredibly powerful feature of relational databases.&lt;/strong&gt; In fact, using indexes properly can often improve the performance of your queries &lt;strong&gt;by an order of magnitude.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Indexes allow you to “ask questions” &lt;strong&gt;without having to search the entire table on disk.&lt;/strong&gt; They’re really useful for answering “needle in a haystack” type of questions, where you’d &lt;strong&gt;otherwise have to look through many rows&lt;/strong&gt; to pick out only the one that you actually need.&lt;/p&gt;

&lt;p&gt;An index is a data structure that’s stored persistently on disk, and is typically implemented as either:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"B-Tree" -- fast for all sorts of comparisons (&amp;gt;, &amp;lt;, ==)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZPP5aOPm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1600/1%2ApE4SEz7CprzFd7Zww-axfQ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZPP5aOPm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1600/1%2ApE4SEz7CprzFd7Zww-axfQ.jpeg" width="701" height="231"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"Hash Table" -- fast only for equality comparison (==) &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YzHGtePs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://lh3.googleusercontent.com/proxy/vq_qcab7UQqWetwEtMMNbFFiWZNKKWBg6uC50HFTf8KYbMVfxH4s3_4mFt4somQRL6cK0H-P994uEjoCFlijhrtctvy2Ujeore50BYqRYhKFBqfyjnIwtXi6kHx1y5tHT1jLS6lAD-xx9xNFLa1VQtJ3AfQV9DU0-VU" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YzHGtePs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://lh3.googleusercontent.com/proxy/vq_qcab7UQqWetwEtMMNbFFiWZNKKWBg6uC50HFTf8KYbMVfxH4s3_4mFt4somQRL6cK0H-P994uEjoCFlijhrtctvy2Ujeore50BYqRYhKFBqfyjnIwtXi6kHx1y5tHT1jLS6lAD-xx9xNFLa1VQtJ3AfQV9DU0-VU" width="512" height="340"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Without an index&lt;/strong&gt;, performing a SELECT ... FROM table WHERE ...; statement requires &lt;strong&gt;the DBMS to search through every single row&lt;/strong&gt; in the table to see if it matches that exact WHERE clause. If you have more than a few hundreds rows in a table - &lt;em&gt;and most modern web applications have millions if not billions&lt;/em&gt; - this takes a non-negligible amount of time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hlsAh9Wy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://d2r55xnwy6nx47.cloudfront.net/uploads/2018/09/Hay_1300Lede.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hlsAh9Wy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://d2r55xnwy6nx47.cloudfront.net/uploads/2018/09/Hay_1300Lede.jpg" width="800" height="518"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But&lt;/strong&gt; by &lt;strong&gt;adding an index to a column that you frequently run lookups on&lt;/strong&gt;, you can decrease this amount of time required. Instead of having to scan n rows (where n is the total number of rows in the database), the database can return your query by looking at either log(n) rows (if indexes are implemented as a b-tree) or &lt;strong&gt;simply one row (if indexes are implemented as a hash table).&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Once you’ve set an index on a particular column, &lt;strong&gt;you don’t need to do anything to make subsequent queries use it.&lt;/strong&gt; The query planner in the DBMS will use that index if it needs to.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7bFwOQ3J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://media.makeameme.org/created/yeah-baby-yeah-nse0oq.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7bFwOQ3J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://media.makeameme.org/created/yeah-baby-yeah-nse0oq.jpg" width="500" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Is it all that sugary and sweet ?
&lt;/h5&gt;

&lt;p&gt;What was mentioned above are the stellar reasons of using indexes in your relational database. &lt;strong&gt;But&lt;/strong&gt;, &lt;em&gt;as with everything in this world&lt;/em&gt;, there are a few downsides to be aware of. Since the index is stored as a separate data structure, building too many indexes will result in additional space on disk.&lt;/p&gt;

&lt;p&gt;One other thing to keep in mind when using indexes is &lt;strong&gt;the overhead of index creation and maintenance.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Whenever a new row is added to the table, &lt;strong&gt;the index’s data structure must also be updated&lt;/strong&gt; so that the index remains accurate.&lt;/p&gt;

&lt;p&gt;Sacrificing a bit of performance on writes to get much better performance on reads seems a good deal for me.&lt;/p&gt;

&lt;p&gt;Thanks for your time,&lt;br&gt;
stay safe and &lt;strong&gt;sane&lt;/strong&gt;. &lt;/p&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
