# Dataflow Programming

## Summary

Dataflow programming (DFP) is a programming paradigm where program execution is conceptualized as data flowing through a series of operations or transformations. Each operation may be represented as a node in a graph. Nodes are connected by directed arcs through which data flows. A node performs its operation when its input data are available. It sends out the result on the output arcs.

Due to social media (2000s) and IoT (2010s), there's a need to analyse data quickly and derive timely insights. There's also a need to explore and exploit parallel architectures. Dataflow programming aids parallelization without the added complexity that comes with traditional programming.

Dataflow programming includes two sub-fields: Flow-Based Programming (FBP) and Reactive Programming. Dataflow programs can be created in text or visually. There are many languages that support this paradigm.

## Discussion

### Could you explain dataflow programming with an example?

Consider the simple program shown in the figure. In a traditional von Neumann architecture, these statements would be executed sequentially. Thus, the program would execute in three units of time.

In dataflow programming, we represent the program as a dataflow graph that has three inputs (X, Y, 10), three operations (+, /, \*) and one output (C). This is a directed graph. Nodes represent instructions or operations. Arcs represent variables. Equivalently, arcs represent data dependencies between instructions. The value in Y is also duplicated since it's sent to two instructions.

In dataflow execution model, this program takes only two units of time. This is because the addition and division instructions can execute in parallel. For each of these instructions, their respective inputs are available at the start. They have no dependencies on each other and therefore can be parallelized.

A factory assembly line offers an analogy. Just as raw materials and semi-finished products move on a conveyor belt from one station to the next, data in DFP moves from one node to the next.

### What are the main benefits of dataflow programming?

With the rise multi-core architectures, there's a need to exploit these via parallel execution. Von Neumann architecture is not conducive to parallelism because of its reliance on a global program counter and global updatable memory. With DFP, each node uses local memory and executes when its inputs are ready.

DFP enables **parallel execution** without extra burden on the programmer. There's no need to deal with multiple threads, semaphores and deadlocks. Each node in the dataflow graph is independent of others and executes without side effects. A node executes as soon as its inputs are available. If multiple nodes are ready to execute, they can execute in parallel.

DFP has enabled many **visual programming languages** that provide a more user-friendly interface so that even non-technical users can write programs. Such languages are also suited for rapid prototyping.

DFP promotes **loose coupling** between software components that's well-suited for service-oriented architectures. Its functional style makes it easier to reason about system behaviour. Its simplicity is in its elegance.

DFP is **deterministic**. This enables mathematical analysis and proofs.

### What are the main characteristics of dataflow programming?

A program is defined by its nodes, I/O ports and links. A node can have multiple inputs and outputs. Links connect nodes. Links can be viewed as **buffers** if they need to hold multiple data packets. This is useful when sending and receiving nodes operate at different speeds. Buffers also enable **pipelining** whereby nodes can execute simultaneously.

A **data packet** can take primitive/compound, structured/unstructured values, and even include other data packets. When multiple links join, packets are merged or concatenated. For link splitting, packets are duplicated (shallow or deep copy). Equivalently, nodes can do the join and split.

Execution can be either a **push or pull model**. Push does eager evaluation and reacts to change. Pull does lazy evaluation and uses callbacks. Nodes in push model fire when inputs are available whereas nodes in pull model fire when output is requested.

Execution can be **synchronous or asynchronous**. With synchronous execution, each node take one "unit of time". Fast nodes will wait for slow nodes to complete before outputting the results. With asynchronous execution, outputs are never delayed and systems can run at full speed.

### What are some traits expected of dataflow languages?

Dataflow languages are expected to be free from side effects. There's locality of effect. Scheduling is determined from data dependencies. Variables may be seen as values since they're assigned once and never modified. Order of statements is not important.

An example of side effect is a function modifying variables in outer scope. Locality of effect means that instructions can have far-reaching data dependencies. This is easily possible in imperative languages by reusing the same variables or using `goto` statements. Neither of these should be allowed by dataflow languages. The language should be designed such that it's easy to identify data dependencies and generate graphs that expose parallelism.

To address these, we can prohibit global variables and call-by-reference. Arrays are not modified but created anew when changes are made. Thus, arrays are treated as values rather than objects. Even errors are handled by error values instead of setting global status flags and interrupting the program. Since variables are really values, the statement `S=X+Y` is seen as a definition, not an assignment. In fact, languages that do all processing by applying operators to values have been called **applicative languages**.

### Could you list some dataflow languages?

Dataflow programming is not limited to visual programming. Early languages were textual with no graphical representation. Visual languages enable end-user programming. Textual languages are faster to work with but need expert knowledge.

Textual languages of the early 1980s were VAL (MIT) and ID (Univ.Cal.Irvine). Lucid was developed for program verification but can also be used for dataflow computation. In the late 1980s, SISAL was invented. Based on VAL, it offered Pascal-like syntax and outperformed Fortran on some benchmarks. Other textual languages include CAL, COStream, Lustre, Joule, Oz, Swift (scripts), SIGNAL, SystemVerilog, and VHDL. The `make` software commonly used in UNIX systems is also an example of dataflow programming.

Among DFVPLs are Keysight VEE, KNIME, LabVIEW, Microsoft Visual Programming Language, Orange, Prograph, Pure Data, Quartz Composer, and Simulink. More examples include Node-RED, Max MSP, and Lego Mindstorms.

Even spreadsheets are considered examples of visual DFP. Each cell is a node. When a cell value is updated, it sends its new value to other cells that depend on it.

### What other programming paradigms are closely related to dataflow programming?

**Flow-Based Programming (FBP)** is a subclass of DFP. While DFP can be synchronous or asynchronous, FBP is always asynchronous. FBP allows multiple input ports, has bounded buffers and applies back pressure when buffers fill up. Java, C#, C++, Lua and JavaScript support FBP. DrawFBP and Slang are visual languages for FBP.

**Reactive Programming** is event-driven, asynchronous and non-blocking. It's usually supported by callbacks and functional composition (declarative style of programming). Like DFP, focus is on the flow of data rather than the flow of control. Programming abstractions that support this include futures/promises, reactive streams, and dataflow variables. Akka Streams, Ratpack, Reactor, RxJava, and Vert.x are libraries for JVM that support reactive programming. In JavaScript, there's Bacon.js.

Like DFP, **Functional Programming** is free from side effects, mostly determinate and has locality of effect. However, it's possible to have a convoluted functional program that can't be implemented as a dataflow graph. It's been said that dataflow languages are essentially functional but use an imperative syntax.

Carl Hewitt's **Actor Model** from the 1970s is relevant to DFP. Actors are equivalent to nodes. Many languages such as Scala support the actor model.

### What are some shortcomings or challenges with dataflow programming?

Visual dataflow languages can be cumbersome for large programs with many nodes. Iterations and conditions are hard to represent visually. Debugging is difficult since multiple operations happen concurrently. In general, better tooling is needed.

Many DFVPLs aim to make programming easier for end users. The original motivation to exploit parallelism has become secondary.

DFP's deterministic nature can be a problem. Some use cases (such as ticket booking or database access) are inherently non-deterministic. To solve this, DFP must allow for non-deterministic merging of multiple input streams.

Spreadsheets, when seen via the dataflow paradigm, have their limitations. Formulas are hard to inspect. They're not suited for refactoring and reuse. Deployment and scalability are practical issues. However, solutions have been proposed to address all of these.

Among modern languages, Clojure, Groovy, Scala, Ruby, F# and C# support DFP but offer no syntactic support for dataflow variables. Even simple dataflow examples in F# and C# require lot of boilerplate code.

## Milestones

1950

The idea of dataflow networking can be traced to the work of John von Neumann and other researchers in the 1940s and 1950s in the context of "neuron net" model of finite state automata. In the early 1960s, Carl Adam Petri introduces the *Petri Net* model for concurrent systems. A **dataflow network** is a network of computers connected by communication links. Nodes are activated by the arrival of messages on their links.

1966

Sutherland proposes a two-dimensional graphical method to define programs. He gives examples of written statements and their graphical equivalents. Where a symbol appears in two places, two equivalent connections appear in the graphical form. Intermediate values need not be named in the graph. Graphs are also explicit about multiple outputs. He uses the terms "flow input" and "flow output".

1973

Kosinski publishes a paper titled *A data flow language for operating systems programming*. Programs use function composition. Primitive notion of iteration, recursion, conditionals, and data replication/aggregation/selection are employed. Researchers look to create dataflow languages since they find that imperative languages can't be compiled easily for dataflow hardware.

1974

Davis creates the first visual dataflow language called **Data-Driven Nets (DDNs)**. Dataflow graphs become programming aids rather than simply representations of textual programs. Practical visual programming languages appear only in the early 1980s with Graphical Programming Language (GPL) and Function Graph Language (FGL). However, their development is hampered by graphical limitations of current hardware.

1975

Weng develops the **Textual Data-Flow Language (TDFL)**, one of the first purpose-built dataflow languages. Many other languages follow suit: LAU (1976), Lucid (1977), Id (1978), LAPSE (1978), VAL (1979), Cajole (1981), DL1 (1981), SISAL (1983) and Valid (1984).

1978

Denning notes that **dataflow languages** are being developed at MIT, at IBM T.J. Watson Research Center, at the University of California at Irvine, and at IRIA Laboratory in France. A compiler would translate language syntax into a dataflow graph to be executed on an interpreter. When an operator is ready to run because its operands are available on the input links, the interpreter sends them as a packet to an extractor network, which routes the packet to a function unit. Results are fed back through an insertion network.

1985

Though DFP was expected to eclipse von Neumann architecture, by mid-1980s it's clear that this hasn't happened. Researchers realize that this is probably because parallelism in dataflow architectures is too fine-grained. This starts a trend towards **hybrid architectures** and coarse-grained parallelism. Many dataflow instructions are grouped together and run in sequence, though obeying the rules of dataflow execution model.

1990

Due to computers with better graphics, this decade sees the rise of **Dataflow Visual Programming Languages (DFVPLs)**. LabView (1986) and NL (1993) are two well-known languages of the 1990s. The main motivation for DFVPLs is software engineering rather than parallelism. DFVPLs enable programmers to create programs by wiring dataflow graphs.

Dataflow Programming


# 5G NR Bandwidth Part

## Summary

In 4G/LTE, UEs support the maximum possible bandwidth of 20MHz. In 5G, transmission can go up to 400MHz per carrier. It's impractical to expect every UE to support such a high bandwidth. Therefore by design, it's possible for a 5G UE to communicate on a bandwidth smaller than the cell's channel bandwidth. This smaller portion is what's called **Bandwidth Part (BWP)**.

Via RRC signalling, a UE is configured with multiple BWPs, in downlink and uplink. At PHY layer, the network dynamically activates a BWP for transmission or reception. Through such dynamic adaptation, BWPs allow a 5G system to use radio resources optimally to suit current needs.

In 4G and 5G, carrier aggregation is possible, which allows UEs to aggregate bandwidth across carriers. This article is concerned with only bandwidth parts configured on a single carrier.

## Discussion

### What are the benefits of having bandwidth parts in 5G NR?

Bandwidth Part allows us to design chipsets and UEs of a lower bandwidth capability. Mandating a UE to always use a high bandwidth also leads to higher energy usage.

Compare 20MHz of LTE versus 100MHz (FR1) of 5G. Apart from the higher bandwidth, 5G's higher sub-carrier spacing translates to lower symbol duration, higher clock speeds and therefore higher power consumption. In FR2 mmWave spectrum, power consumption increases further due to antenna arrays and other RF components. At lower data rates, 5G at 100MHz has a lower power efficiency compared to 4G. The use of BWPs overcomes this.

Allocating a single bandwidth to a UE is also not the best use of radio resources. Bandwidth Part allows for **dynamic adaptation**. For example, consider three service requirements: eMBB/100Mbps/1ms, eMBB/15Mbps/0.5ms, URLLC/7Mbps/0.25ms. To meet these, a UE is configured with three BWPs, each with a different numerology, MIMO configuration, modulation, and so on. For example, B1 has more resource blocks and bandwidth to achieve 100Mbps; B3 has smaller bandwidth but gives lower latency due to a higher numerology.

### What are some allocation scenarios of BWPs?

A BWP is a contiguous set of Resource Blocks (RBs). It starts at a common RB and spans a specified number of RBs. Numerology, which determines sub-carrier spacing and cyclic prefix, is also an essential BWP configuration.

Some allocation scenarios are illustrated in the figure. In the simplest case of (a), a reduced BWP is configured for a UE of a lower bandwidth capability. Scenario (b) is useful for a UE having bursty traffic. When more data is to be sent, BWP2 is used. Note that even if BWP1 and BWP2 overlap, only one of them active at a time.

Scenario (c) shows two BWPs with different numerology, each meeting different service requirements. While Physical Resource Blocks (PRBs) of a BWP are all contiguous, there's no requirement that two BWPs have to be contiguous. This is apparent in scenario (d) where other services can be introduced between BWP1 and BWP2, although this option is not part of Release 15.

### What are some technical details about BWP?

A UE can be configured with a maximum of four BWPs in downlink and another four in uplink. This is in addition to the initial BWPs configured via SIB1. Like UL, there's also Supplementary Uplink (SUL). UE can have four BWPs in SUL.

Even with multiple configured BWPs, only one is active at any one time; that is, UE transmits and receives within its active BWP and nowhere else. DL PDSCH/PDCCH/CSI-RS are received only within the active DL BWP but UE can use measurement gaps to perform measurements outside the active BWP. UL PUSCH/PUCCH are sent by UE only with the active UL BWP.

**BWP switching** means deactivating the currently active BWP and activating another configured BWP. In TDD, DL and UL BWPs differ only by the transmission bandwidth and numerology; and they're switched together.

There's also **default BWP** configured for DL and UL. If not configured, initial BWP is used as default. Default is used when there's not much to send/receive to/from the UE. It's activated when an inactivity timer expires.

### How does a UE use BWP in RRC idle mode and RRC connected mode?

A UE's access to the network starts with acquiring the Synchronization Signal Block (SSB) that consists of PSS, SSS and PBCH. This spans 4 OFDM symbols and 20 RBs. It contains the MIB.

MIB contains CORESET#0 configuration. This is used by UE to infer the **initial DL BWP**. UE receives and decodes the CORESET#0, which contains SIB1. SIB1 sets the initial BWP for both DL and UL. Initial BWP is named BWP#0. DL BWP#0 is configured such that it encompasses CORESET#0.

RACH access happens with UL BWP#0. Network responds with DL BWP#0 until RRC connection happens. Once RRC connection happens, UE can be configured with **UE-specific BWPs**.

The figure shows BWP#0 (24 RBs), BWP#1 (270 RBs) and default DL BWP#2 (52 RBs). This is an FDD example: DL switches to BWP#2 but UL stays at BWP#1. In TDD, BWP switching happens together for both DL and UL.

### How does BWP adaptation or switching happen?

When a UE moves from idle mode to RRC connected mode, **RRC signalling** can configure UE-specific BWPs. RRC configuration or reconfiguration message may specify one of these to be activated. If so, the UE will do BWP switching. Due to RRC processing delay, this can be in the order of tens of milliseconds.

Once UE is configured with multiple BWPs, network can command UE to switch BWP using **Downlink Control Information (DCI) in PDCCH**. DCI format 1\_1 for downlink assignment and format 0\_1 for uplink grant are used. These formats contain the BWP indicator that can take 1 or 2 bits. If more than 2 BWPs are configured, 2-bit indicator is used.

The third way of switching is when **BWP inactivity timer** expires, which triggers a switch to default BWP. The timer ranges from 2-2560ms. It's maximum value relates to DRX inactivity timer.

### What's CORESET and how is it relevant to BWP?

Control Resource Set (CORESET) is where the UE searches for downlink control signals. Like BWP, it's smaller than the carrier bandwidth. A CORESET can be anywhere but a UE is expected to process only CORESETs that are within its active BWPs. CORESETs are configured at cell level so that the configuration can be reused for any applicable BWP.

CORESET is where UE searches for PDCCH, though the network doesn't necessarily transmits PDCCH on every CORESET. Whereas in LTE, control region spans the entire carrier bandwidth, 5G NR optimizes this via CORESET.

LTE control region can vary and is specified by PCFICH. In 5G NR, CORESET size is configured via RRC signalling. CORESET spans up to three OFDM symbols. CORESET at the start of the slot facilitates scheduling decisions. CORESET at other places may be useful to reduce latency. In the frequency domain, CORESET is in multiple of six RBs.

A BWP can have up to three CORESETs. CORESETs are common or UE specific. Configured via MIB, CORESET#0 is used for SIB1 scheduling. After RRC connection, UE-specific CORESETs may be configured.

## Milestones

Mar
2016

3GPP completes the standardization of LTE Advanced Pro (Release 13). While previous LTE releases required a UE to support full carrier bandwidth, Release 13 introduces eMTC (enhanced Machine Type Communication). This defines **LTE Cat-M1** UE that can operate on a bandwidth of 1.08MHz (6 PRBs) within a normal LTE deployment or 1.4MHz in standalone deployment. Thus, LTE recognizes the need that some UE devices may have lower bandwidth requirement or capability and therefore need not receive on the full carrier bandwidth.

Dec
2017

3GPP publishes Release 15 "early drop". In this release, the term **Carrier Bandwidth Part** is used.

Jun
2018

3GPP publishes Release 15 "main drop". In this release, the term **Bandwidth Part (BWP)** is used. This change in name occurred in March 2018. In principle, if the UE is able to support it, multiple bandwidth parts with different numerology can be active at the same time. But in Release 15, only one BWP (in each direction) can be active at a time.

Jul
2020

3GPP publishes Release 16 specifications. There's no change to BWP. A UE can have only one active BWP in each direction.

5G NR Bandwidth Part


# DevOps

## Summary

DevOps is the coming together of both development and operations teams into a coordinated workflow such that collaboration and productivity are improved to meet shared business goals. Building on Agile and Lean, DevOps enables the business to respond to changes and meet customer needs faster. Tools and automation are necessary enablers. Practices such as Continuous Integration and Continuous Delivery are often followed.

Traditionally, products were monolithic in nature and release cycles were long. While developers focused on creating working software, it was operations who (manually) ensured that it could run in a production environment. Dev was all about adding new features. Ops was about stability and availability. Between these two were the testers. DevOps brings these teams closer so that releases can happen as quickly as necessary.

DevOps has been described variously as a culture, a mindset, a framework and a movement.

## Discussion

### How did DevOps come about?

Until early 2000s, software release cycles were typically long. Even if developers could churn out features quickly, business folks would be wary of changes since software was considered brittle and deployments risky. At the same time, user expectations and competition forced vendors to consider shorter release cycles. Agile and Lean methods were used to do this. Even then, making frequent releases on a monolithic product was a challenge.

What really changed the scene was the arrival of cloud computing, SaaS and microservices. Products were delivered as web services and later as a bunch of microservices. This enabled vendors to make faster releases at the microservice level. But deploying a networked service is the work of operations, who were mostly ignored by the Agile and Lean movements. The result was that software that was ready would not go to customers until weeks or months later, waiting for operations to ensure it works properly in production environment. Also, operations now had to worry about security, virtual machines, containers, scaling, and more. It was no longer plain system administration for operations. DevOps has come to address these challenges.

### Can you define DevOps?

There's no single definition of DevOps:

    + DevOps is a cultural, professional movement focused on how we build and operate high-velocity organizations, born from the experiences of its practitioners.
    + DevOps is largely founded in an organization’s skillful collaboration and communication, and the culture that results.
    + DevOps is the practice of operations and development engineers participating together in the entire service lifecycle, from design through the development process to production support.
    + DevOps is ops who think like devs and devs who think like ops.
    + The point of dev-ops is that developers need to learn how to create high-quality, production-ready software, and ops needs to learn that Agile techniques are actually powerful tools to enable effective, low-risk change management. Ultimately, we’re all trying to achieve the same thing – creating business value through software.
    + The Devops movement is characterized by people with a multidisciplinary skill set - people who are comfortable with infrastructure and configuration, but also happy to roll up their sleeves, write tests, debug, and ship features.

### Could you dispel the common misconceptions or myths about DevOps?

DevOps is not just about using tools or automating processes, although these are important. DevOps is not just about people, culture or processes. DevOps requires all of these to work together.

DevOps goes beyond just developers and operations. It requires support and alignment from sales, marketing and even executives.

Having someone attend a DevOps conference or bringing a DevOps "expert" into your team doesn't make a project "DevOps compliant". For that matter, DevOps is neither a standard nor a specification. There's no certification to recognize DevOps experts. DevOps is really driven by practitioners and could be considered a knowledge-based movement. It's always evolving.

DevOps is not limited to using open source software. It does not eliminate IT operations (NoOps) or replace Agile.

Continuous integration/delivery are not goals themselves. They're simply necessary steps in achieving DevOps goals. Neither is there a goal to make multiple releases per day or week. DevOps aims to release as often as necessary.

DevOps is not just for web companies delivering SaaS products or companies working at scale. DevOps is for everyone.

### Can you list some best practices for getting DevOps right?

Although DevOps is not a set of practices, the following may help newbies get into the DevOps movement:

    + DevOps is about People, Process and Tools, in that order. Starting with tools will be the wrong way to do it.
    + John Willis gives us the CAMS formula: Culture, Automation, Measurement, Sharing. Again, culture is critical to successful DevOps. Everything needs to be automated and measured. For measurements, establish KPIs. Mean time to recovery is an example KPI.
    + Empathy is important to understand needs, break down silos and bring various teams together.
    + Start small on something strategic and then apply it on a large scale across the organization.
    + Invest in tools that give real-time visibility. Tool integration is essential. Multiple tools that don't work well together will hamper collaboration.
    + Increase the speed of deployment. To achieve this, invest in automation and practise Agile techniques.
    + Participate in community events and online channels to share and learn.
    + Improve feedback at every step, whether it's build, deploy, recovery or notifications.

### Can you describe some common DevOps terms?

Here are some terms often used in the DevOps world:

    + Feature switch: Ability to turn on/off features at code level and thereby facilitate Continuous Delivery.
    + Trunk-based development: A version control practice in which all changes go into trunk rather than isolated branches.
    + Container: An isolated environment at OS level where microservices and applications can be deployed and executed more reliably.
    + Shift left: Automated testing is built into the software methodology from the outset. The same can be done with deployment.
    + Orchestration: Method to manage and deploy applications and containers.
    + Staging: An environment that mimics production environment so that updates can be tested before going into production.
    + Deployment pipeline: An automated pipeline to get software quickly from version control to users.
    + Serverless: An architecture in which resources are allocated on demand without explicit server management.
    + Microservices: Smaller manageable pieces of an application accessed via standard interfaces.
    + Immutable infrastructure: Infrastructure that can't be changed once initialized for better robustness and reliability.
    + Infrastructure-as-Code: Describes automated provisioning, configuring and monitoring of infrastructure.

### What tools can facilitate DevOps implementation?

There are dozens of tools out there to automate every aspect of DevOps. These are commercial or open source. As of July 2017, some tools were considered indispensable: Ansible, Docket, Chet, Puppet, JIRA, Jenkins, New Relic, Visual Studio, etc. XebiaLabs curated a list of 100+ tools arranged as a "periodic table". They also published a list of open source tools.

Since tool integration requires effort, some vendors offer suites of integrated tools. This can cause problems. Errors in them will propagate through the entire lifecycle. For example, throwing generic errors, tighly coupling pipeline stages to environments, showing ambiguous status or using terminology in the wrong sense can all be problems for a DevOps culture. Instead, adopt single-purpose, focused tools that use open standardized API.

### How is DevOps related to Agile and Lean?

It's been said that to deliver quality products we need all three: Lean concepts, Agile practices, and DevOps mindset. DevOps is an extension/adoption of Agile because what Agile does for development and testing, DevOps does for operations as well. Agile is a powerful tool that operations can use. Agile was about automating build, test and delivery. DevOps extends automation to deployment.

Lean focuses on end-to-end flow to address bottlenecks and wastages. Lean is also about early product validation via customer feedback. Agile on the other hand employs various techniques to build products faster. DevOps uses Agile practices but also talks about how to integrate, test and deliver the product into the hands of users.

Just grafting operations to an existing Agile development process is not DevOps. Having a DevOps team separate from the development team creates silos and this goes against the spirit of DevOps. The Agile process has to be rethought to include operations from the outset. Theresa Neate put it nicely,

> When you have a #DevOps team, you are not doing devops.

### Are there any specializations of DevOps?

**DevSecOps** attempts to bring security aspects into DevOps. With the growing importance of data analytics, especially in real time, **DataOps** attempts to apply DevOps to analytics and enable better data-driven decisions. While DevOps has been proven for individual applications, will it work for enterprises that use hundreds of diverse applications across private/public clouds and on-premises? This is being addressed by **BizDevOps** that's more operations focused and has less tolerance for risk taking. When it comes to collaboration, **ChatOps** is a model based on conversations to bring together tools, bots and people for transparent workflows. **NetOps** tries to achieve agility in operations without sacrificing availability. When IT operations are completely automated, though not eliminated, we have **NoOps**. Cloud providers offering PaaS ease so much of day-to-day operations for their users that they tend to use the term NoOps as augmenting DevOps.

## Milestones

2006

Even before the term DevOps is coined, some companies start practising it. In an interview, Amazon's Werner Vogels states that their developers are also looking after day-to-day operations, interfacing with customers and collecting direct feedback. The goal is to improve quality of service.

Aug
2008

At the Agile Conference in Toronto, Andrew Shafer calls for a session titled "Agile Infrastructure". Only one person, Patrick Debois, attends this. He later meets Andrew and they together form the "Agile Systems Administration Group".

Nov
2008

Eric Ries refers to Steve Blank's book titled "The Four Steps to Epiphany". The basic idea is to release early a minimum set of features to the customer, get feedback, validate product-market fit and iterate quickly. This was the start of the Lean movement and had an influence on DevOps.

Jun
2009

At the O'Reilly Velocity conference John Allspaw and Paul Hammond present 10+ Deploys a Day: Dev and Ops Cooperation at Flickr. Debois watches this from Belgium. Inspired by this, Patrick Debois organizes DevOpsDays in Ghent, Belgium in October. By the time the event ends, twitter hastag *#DevOps* becomes commonly used, giving the movement its current name.

2010

DevOpsDays is organized in Sydney, California, Hamburg and Sao Paulo. This is also the year when Jez Humble publishes his well-known book titled "Continuous Delivery".

2014

Enterprises start adopting DevOps.

DevOps


# Fingerprinting Algorithms

## Summary

Human fingerprints are defined by tiny ridges, spirals and valley patterns on the tip of each finger. They are unique: no two people have the same ones.

Similarly, a fingerprinting algorithm in computer science is one that maps large data (such as documents or images) to a much shorter sequence of bytes. Such a sequence may be called the data's fingerprint. In essence, large data is more tersely represented by its fingerprint. This fingerprint uniquely identifies the original data, just as human fingerprints uniquely identify individual people. Fingerprinting can be applied to different types of inputs: documents, images, audio, video, or any arbitrary data.

While fingerprints may identify the original data, they're not a compression technique. This means that original data cannot be derived from its fingerprint. Fingerprints help in quickly checking the integrity of data or retrieving documents from large filesystems.

## Discussion

### What are the characteristics of a good fingerprinting algorithm?

Like any other algorithm, fingerprinting algorithms must balance speed, memory usage and code size. In addition, they must guarantee **virtual uniqueness**. No two files, even if they differ by a single bit, should end up with the same fingerprint. When two files generate the same fingerprint, we call it a **collision**. A good algorithm guarantees that the probability of collision is extremely small.

Conversely, when two files differ even slightly, their fingerprints must be significantly different. This property is called **avalanche effect**. In the world of cryptography, this is also called **diffusion**.

For some applications, algorithms must support **compounding**, which is about fingerprinting a composite file from the fingerprints of its constituent parts. Computer files are often combined in various ways, such as concatenation (archive files) or symbolic inclusion (C preprocessor's `#include` directive). Compounding property may be useful in some applications, such as detecting when a program needs to be recompiled.

### What are some use cases of fingerprinting algorithms?

When we need to **search** large filesystems or databases, fingerprints are used to speed up data retrieval. Rather than compare large amounts of content, it's sufficient to compare their fingerprints. When we upload files, cloud providers use fingerprints to do **deduplication** so that multiple copies of the same file are avoided. When users upload content to public sites, fingerprints can tell if it's **banned or copyrighted content**. In companies, fingerprints can prevent employees from emailing sensitive content such as patent documents.

When fingerprints of a file don't match we can say that **data integrity** is compromised, that is, the file's been tampered. In other applications where file changes need to be synchronized over a network, fingerprints help in **bandwidth reduction**. Rather than transfer whole files, fingerprints can tell what parts of the file have changed and transfer only those. Likewise, **public-key fingerprints** are used instead of long public keys. In **distributed systems** where unique names must be maintained, fingerprints are used.

For **identification**, audio fingerprinting is used to identify songs; image fingerprinting to identify cameras, or pornographic content.

### Could you describe some fingerprinting algorithms?

**Hash functions**, also called fingerprinting functions, are often used to reduce arbitrary length of data to a fixed length of bytes. The output is called a hash or a fingerprint. Some hash algorithms have cryptographic properties and hence called *cryptographic hash functions*. With these, it's difficult for two different inputs to have the same hash. Cryptographic hashing algorithms include MD5 and SHA-1.

**Rabin's algorithm** uses polynomials over a finite field to generate hashes. It's able to give us a precise calculation of the probability of collision. They're also faster than cryptographic hash algorithms. However, they're said to be insecure against malicious attacks. This is a *rolling hash*. Others include TTTD, FBC and what's used in `rsync`.

**ML algorithms** for fingerprinting are trained on deterministic data and then used for prediction. However, these require lots of training data.

### Are there special considerations for audio/video fingerprinting?

Normally, fingerprints must be unique even if the original content changes slightly. However, audio and video are often subject to noise, distortions or variations in encoding. Thus, it's not useful to fingerprint them directly. Algorithms must be robust; that is, even in the presence of noise or distortion, fingerprints must be similar, if not same.

Content that are *perceptually different*, must produce different fingerprints. For audio, perceptual traits such as zero crossing rate, frequency spectrum and tempo can be used. For video, colour histogram, mean luminance, motion detection, ordinal intensity signature, and spatial distribution of colour or objects in a frame are some features to consider.

Even in text processing, sometimes we want to know if two documents are similar. In this case, we don't want to minimize probability of collision. Instead, we need to maximize it. Thus, we have **Locality-sensitive hashing (LSH)** or **MinHash** algorithms. As an example, 5 word n-grams are used to find out if two documents are similar.

### Could you name some applications or products that use fingerprinting?

**LBFS** is a low-bandwidth networked filesystem that uses SHA-1 hashing to determine if a data chunk needs to be transferred over the network. **Venti**, an archival storage system, uses SHA-1 hashing of a data block. Blocks are addressed by their hashes. Therefore, block content cannot be changed without changing the address. Thus, Venti enforces write-once policy and deduplication. **Pcompress** does compression and deduplication for data archives. For deduplication, it uses fingerprinting at chunk level and rolling hash computations.

Since 2007, YouTube's been using a system called **Content ID** to flag content that infringe copyrights. It uses both audio and visual fingerprinting, and more recently enhanced with machine learning. **Shazam** identifies songs based on audio fingerprinting. **Audible Magic** employs its audio/video fingerprinting technology for content providers who wish to protect their copyrighted content.

By computing a hash of hashes, **Surety** offers a timestamped data integrity service. In **blockchain technology**, each block is hashed and these hashes influence those of future blocks. These hashes serve to identify and verify the integrity of blocks.

### How's digital fingerprinting related to fingerprinting algorithms?

Digital fingerprinting is a broader concept and fingerprinting algorithms may be treated as a specific case.

The common interpretation is that digital fingerprinting is used to track or profile individuals based on the tools they use or how they interact online. For example, users can be tracked based on their browsers, browser settings, screen resolution, operating system, location, language settings, etc. The term **browser fingerprinting** has been used to describe this approach. Similarly, there's **canvas fingerprinting** that's based on GPU and graphics drivers.  At device level, MAC address, IP address or TCP/IP configuration could be used.

The purpose is to identify criminals based on their fingerprints or combat online piracy. Another use is to build a general profile of individuals that can be attractive to advertisers to serve personalized ads. Digital fingerprinting therefore brings up the issue of privacy. Users have been tracked across browsers with an accuracy of 99.2%.

### How's a fingerprinting algorithm different from watermarking?

Watermarking is typically employed for documents, images and video. It's a visible marking that serves to discourage content piracy. There's also invisible watermarking that can be used to track the source of a file because each file is stamped with a unique watermark.

With fingerprinting, we don't have to modify the original file. It's more about prevention than tracking. A file's fingerprint is compared against a database to flag copyrighted content or simply to identify the file.

## Milestones

1981

Michael O. Rabin publishes *Fingerprinting By Random Polynomials*. It introduces the concept of rolling hashes based on a sliding window. Instead of having fixed-size data chunks, variable-sized chunks give better performance in data deduplication applications.

1991

Ronald Rivest proposes **MD5**, a cryptographic hash function. It's offered without licensing. Weaknesses are identified in the following years. In 2004, enhanced differential attacks are discovered. By 2009, this attack is optimized so that MD5 collisions can be discovered in milliseconds.

1993

National Institute for Standards and Technology (NIST), USA, proposes **Secure Hash Algorithm (SHA)**. In 1995, this is replaced with **SHA-1** due to a flaw in the original algorithm. SHA-1 produces 160-bit hashes. SHA-1 itself is attacked in 2005. Google publishes full details of another attack in 2017.

1999

Shazam is founded based on the idea of using audio fingerprinting to identify music, movies, ads and shows. In 2018, it was acquired by Apple.

2002

NIST proposes **SHA-2** as a replacement of SHA-1. SHA-2 produces longer hashes of 224, 256, 384 or 512 bits.

2007

Google introduces beta version of **YouTube Video Identification** to help copyright owners manage their content on YouTube, particularly when uploaded by others. The service uses video fingerprinting as the technique and later evolves into **Content ID**.

Fingerprinting Algorithms


# DPDK

## Summary

Switches, routers, firewalls and other networking devices typically need to process large volumes of packets in real time. Traditionally, efficient packet processing was done using specialized and expensive hardware. Data Plane Development Kit (DPDK) enables us to do this on low-cost commodity hardware. By using commodity hardware, we can also move networking functions to the cloud and run them within virtualized environments. DPDK enables innovation around multi-core CPUs, edge computing, real-time security, NFV/SDN, low-latency applications and more.

DPDK was originally started at Intel. Later it was open sourced and subsequently brought under the guidance of the Linux Foundation. It uses BSD-3-Clause licensing.

DPDK is not without its challenges. Not all NICs are supported. Support for Windows is limited. Being a low-level framework, it requires developers with relevant expertise. Debugging is harder.

## Discussion

### How did vendors achieve efficient packet processing before DPDK?

Before DPDK, specialized hardware did efficient packet processing. Such hardware might use custom ASICs, programmable FPGAs or Network Processing Units (NPUs). Sometimes low-level hardware-specific microcode or custom firmware could be present. Packet classification, flow control, TCP/IP processing, encryption/decryption, VLAN tagging, and checksum calculation example tasks that these specialized hardware did in an optimized manner.

However, such hardware were expensive to buy and maintain. Upgrades and security patches were time-consuming to apply and needed a full-time network administrator. One solution was move from specialized hardware to Commercial Off-the-Shelf (COTS) hardware. While this was more cost effective and easier to maintain, performance suffered. Packets moved from Network Interface Cards (NICs) to the operating system (OS), where they were processed via the OS kernel stack.

Even with fast NICs, the kernel stack proved a bottleneck. System calls, interrupts, context switches, packet copying and per-packet processing brought down performance.

DPDK solves the performance problem on COTS hardware. We get efficient packet processing without requiring expensive customized hardware.

### How does DPDK improve packet processing?

DPDK **bypasses the kernel** and enables fast packet processing in userspace. It's essentially a set of network drivers and libraries. Environment Abstraction Layer (EAL) abstracts hardware-specific operations from applications. The figure shows how traditional processing with POSIX calls goes through the kernel space before packets reach the application. DPDK short-circuits this path and moves packets directly between NIC and userspace applications.

Traditional processing is interrupt driven where the NIC interrupts the kernel when a packet arrives. DPDK uses **polling** instead and avoids the overhead associated with interrupts. This is performed by a Poll Mode Driver (PMD).

Another important optimization is **zero copy**. In traditional networking, packets are copied from socket buffers in kernel space to user space. DPDK avoids this.

For developers, DPDK's userspace approach is attractive since kernel need not be modified. Any network stack based on DPDK can be optimized for specific applications.

### What's the packet processing model adopted by DPDK?

There are broadly two processing models:

    + **Run-to-Completion**: A CPU core handles receive, processing and transmit of a packet. Multiple cores can be used with each core associated with a dedicated port. However, with Receive Side Scaling (RSS), traffic arriving at a single port can be distributed to multiple cores.
    + **Pipeline**: Each core is dedicated to a specific workload. For example, one core might handle receive/transmit of packets while other cores handle application processing. Packets are passed between cores via memory rings.For single-core multi-CPU deployments, one CPU is assigned to the OS and the other to the DPDK-based application. A less performant variant is when packets are accessed via the QPI interface. For multi-core deployments, we can assign more than one core to each port with or without hyperthreading.

Deciding which model to use is not trivial. Some things to consider are cycles needed to process each packet, extent of data exchange across software modules, specific optimization at some cores, code maintainability, etc. Intel VTune Profiler can be used to analyze the efficiency of the pipeline model.

### What other techniques does DPDK use to improve performance?

Apart from kernel bypass, polling and zero copy, there are a few more techniques used by DPDK:

    + **Processor Affinity**: Ties specific processing to specific cores.
    + **Huge Pages**: Reduces TLB cache misses.
    + **Lockless Sync**: Queues are managed with the ring library. Enqueue and dequeue operations are lockless.
    + **I/O Batch**: Process a batch of packets rather than one at a time. This amortizes overheads in accessing the NIC.
    + **NUMA Aware**: Utilizes NUMA memory for better performance.
    + **Cache Alignment**: Align structures to 64-byte cache lines.These features are used by DPDK components such as EAL, memory manager, buffer manager, queue manager, flow classification, etc.

### What are some metrics used to evaluate DPDK performance?

**Throughput** is the most common metric. Often this is quoted in Mbps, Gbps or Mega Packets Per Second (MPPS). When MPPS is used, packet size must be mentioned. At a low packet size of 64 bytes, throughput will be limited by MPPS rather than Mbps. The figure above shows throughput at L2.

In 2015, per core L3 performance on Linux was 1.1 MPPS. On Intel DPDK, this was 28.5 MPPS. In 2010, DPDK could achieve L3 performance of 55 MPPS with 64-byte packets on an Intel Xeon-based system. This was improved to 255 MPPS (2014) and 347 MPPS (2016).

**Latency** is important for low-latency applications. The figure above shows that DPDK reduces latency by a factor of ten on 64-byte packets. Likewise, for real-time applications, **jitter** is important. One study showed that DPDK reduces jitter from 10μs to 2μs.

### Does DPDK need a TCP/IP stack to work?

DPDK doesn't include a TCP/IP stack. If an application requires a userspace networking stack, it can use F-Stack, mTCP, TLDK, Seastar and Accelerated Network Stack (ANS). These typically provide both blocking and non-blocking socket APIs. Some of these are based on FreeBSD implementation.

By omitting a networking stack, DPDK doesn't have the inefficiency of a generic implementation. Applications can include networking modules optimized for their use cases. There might also be some use cases where no higher layer (above L2) processing is needed.

### Who in industry is using DPDK?

Load balancing, flow classification, routing, access control (firewall), and traffic policing are typical uses of DPDK. There's a misconception that DPDK is only for the telecom industry. However, DPDK has been used in cloud environments and enterprises alike. Traffic generators (TRex) and storage applications (SPDK) use DPDK. The figure above lists open-source projects powered by DPDK.

Network Function Virtualization (NFV) and Software Defined Networking (SDN) are two technologies that leverage DPDK. Open vSwitch (OVS) when ported to DPDK has shown 7x performance improvement.

In IoT applications, packets are tiny. DPDK reduces latency and allows more such packets to be processed per second.

In 5G, the User Plane Function (UPF) processes user data packets. Delay, jitter and bandwidth are key performance metrics that need to be met. Some researchers have proposed DPDK for 5G UPF implementation.  For deploying UPF at edge networks, DPDK APIs can be used to interface the UPF application (UPF-C) and SmartNICs (UPF-U).

### What are the challenges with DPDK?

DPDK requires low-level expertise. Developers should learn DPDK's programming model. They should know how to manage memories, pass packets without copying, and work with multi-core architectures.

For example, PID namespace can cause problems with managing *fbarray*. Processes using *mmap* without specifying addresses can cause problems. Called *thread or core affinity*, threads must be assigned correctly to CPU cores for consistent performance. DPDK libraries offer developers many implementation choices. Getting these choices wrong can impact performance.

Since kernel is bypassed, we lose all the protection, utilities (`ifconfig`, `tcpdump`) and protocols (ARP, IPSec) that the Linux kernel provides. Debugging and identifying root causes for networking problems are challenges. However, DPDK's tracing library and *LLTng* may help. A poor implementation can cause other processes/programs to fail.

Finally, since polling is used instead of interrupts, DPDK causes 100% CPU usage even when only a few packets are being processed.

### What are some alternatives to DPDK?

Faster packet processing via kernel bypass is possible using Snabbswitch, Netmap or StackMap. Like DPDK, these process packets in the userspace. Packets completely bypass the kernel stack. Snabbswitch is written in Lua while DPDK is in C.  PacketShader does kernel bypass for GPU-based hardware.

An alternative approach is to modify the Linux kernel. Examples include eXpress Data Path (XDP) and network stacks based on Remote Direct Memory Access (RDMA). Other efficient tools include packet\_mmap (but doesn't bypass the kernel) and PF\_RING (with ZC drivers).

Cloud providers may not wish to dedicate an entire NIC for a single offloaded application. Solarflare uses OpenOnload that uses the *EF\_VI* proprietary library. It creates a "hidden queue" at the NIC that userspace processes can access. This approach is sometimes called **bifurcated driver** or **queue splitting**. A similar approach exists in the virtualization world to avoid the overhead of passing packets from host to VM. Fake virtual interfaces allow packets to reach the VM directly. In general, modern NICs can bifurcate traffic to use or skip kernel stack. SR-IOV and VFIO technologies enable this.

## Milestones

Sep
2010

Intel creates **DPDK** and releases it under a permissive license. It uses the *3-Clause BSD License*. This allows developers to modify the source code without requiring them to open source those modifications. Intel's Venky Venkatesan is often called the "Father of DPDK".

Sep
2012

**DPDK v1.2.3r0** is released. On DPDK Git archives, this is the earliest version available. Release notes are available since v1.8 (December 2014).

Oct
2012

ETSI's white paper on NFV is published. This paper mentions DPDK as an enabling technology for NFV and cloud computing. This is attributed to DPDK's poll-mode Ethernet drivers that avoid interrupt-driven processing.

2013

Website *DPDK.org* is launched and an **open source community** is formed.

Sep
2014

The first **DPDK Summit** is organized in San Francisco. Similar summits are organized regularly over the following years. Meanwhile in 2014, DPDK comes with **multi-vendor** CPU and NIC support. This support grows rapidly through 2015.

Apr
2015

Since DPDK doesn't offer a built-in TCP/IP stack, other open source projects attempt to provide this on top of DPDK. Examples of this include mTCP (v2 in Apr 2015), ANS (v16.08 in Aug 2016), and F-Stack (v1.11 in Nov 2017).

Oct
2015

DPDK releases new project **logos**, licensed under CC BY-IND 4.0.

Apr
2017

DPDK becomes a project under the guidance of **the Linux Foundation**, which provides a network platform for the growth of DPDK. By now, many open source projects have already adopted DPDK including MoonGen, mTCP, Ostinato, Lagopus, Fast Data (FD.io), Open vSwitch, OPNFV, and OpenStack.

May
2019

DPDK v19.05 is released with **support for Windows OS**. Only a "Hello World" sample application is supported. However, even four years later, the v23.07.0 documentation notes that DPDK for Windows is "a work in progress" and some source files may not compile.

Nov
2020

**DPDK v20.11** is released. It's claimed to be the biggest and most robust release. It's an LTS release that will be supported for two years. The two biggest contributors for this release are Intel and Nvidia, followed by Huawei and Broadcom.

Dec
2022

Intel publishes a technology guide explaining its *Data Streaming Accelerator (DSA)*. While DPDK aims to avoid data copying, sometimes this is unavoidable. Such copying operations can be offloaded to Direct Memory Access (DMA) accelerators such as DSA. DPDK library that enables this is `dmadev`, available since DPDK v21.11 (November 2021).

Mar
2023

Belkhiri et al. propose instrumenting DPDK libraries and collecting trace information. These traces can be used to debug performance issues and identify root causes. They claim that their approach is better than what existing tools VTune Amplifier (closed source), FlowWatcher-DPDK and DPDKStat are capable of.

Sep
2023

DPDK website shows that the current gold members include AMD, ARM, Ericsson, Intel, Marvell, Microsoft, Nvidia, Red Hat and ZTE. Silver members include 6Wind, Broadcom, Huawei, NXP, and more.

DPDK


# Multicloud

## Summary

**Multicloud** (multi-cloud or multi cloud) is a cloud computing strategy. It involves utilizing multiple cloud platforms and services from different vendors within a single IT architecture. The primary purpose of this approach is to enhance cloud infrastructure capabilities, increase flexibility, and optimize costs. Multicloud describes how cloud resources, such as software, applications, and data, are distributed across various cloud hosting environments, which may include public, private, or hybrid clouds..

Multicloud combines two or more cloud platforms. The mulicloud architecture usually has minimum two independent public cloud platforms. These platforms are either public or private.

Multicloud deployment has various benefits. For example, using multiple IaaS, PaaS, and SaaS vendors, including different cloud vendors for different services, excess and system backup.

## Discussion

### How can we understand multicloud with an example?

Let's understand multicloud with an example:

Imagine a medium-sized e-commerce company, "TechMart," that wants to leverage cloud computing to enhance its online store and customer experience. To achieve their goals, they decide to adopt a multicloud strategy. Here's how they use multicloud:

**Web Application Hosting:** TechMart chooses to host its web application on AWS (Amazon Web Services) due to its robust and scalable infrastructure. AWS provides excellent support for web hosting, allowing TechMart to handle fluctuating traffic during peak shopping seasons efficiently.

**Data Storage and Analytics:** TechMart deals with a large volume of customer and transaction data. To optimize data storage costs and performance, they decide to use Microsoft Azure's cloud data services. Azure offers a wide range of data storage options and advanced analytics tools that suit their needs.

**Email and Communication Services:** For seamless email communication with customers and employees, TechMart selects Google Cloud Platform (GCP) for its reliable and feature-rich email services.

**Disaster Recovery:** To ensure business continuity and data redundancy, TechMart also maintains a private cloud in their on-premises data center. This private cloud acts as a disaster recovery environment, replicating critical data from the public cloud providers.

### What are the benefits of multicloud approach?

A multicloud approach gives multiple options to a company. Some advantages of multicloud are:

Stakeholders can choose the most effective solution. They can distribute resources among cloud providers. They need to pay only for their usage based on business needs.  Enterprises gain better computing resources and higher cloud security. They have reduced outages and vendor lock-in risks. SLAs between various service providers secure customers from failures or downtime. Multicloud aids enterprises to optimize service, price, and resources. It also improves data security and interaction flexibly.

Multicloud allows selecting suitable components and cloud services. they can be selected from various vendors based on business needs. It is based on factors like cost, performance, security, compliance, and location preferences. It provides quick adoption of new technologies from any vendor. Businesses need a strong strategy and governance framework for a successful multicloud implementation.

### What is the difference between multicloud, hybrid cloud and polycloud?

**Multicloud** refers to the practice of using services and resources from more than one cloud companies. In a multicloud setup, an company would possibly use one cloud provider for positive workloads or packages and every other cloud issuer for exclusive tasks. The intention is to leverage the strengths of every cloud issuer even as avoiding supplier lock-in and ensuring redundancy.

**Hybrid cloud**, uses both on-premises hardware and cloud hosting. It could lead to a shift to a public cloud. A hybrid cloud lets businesses connect their existing infrastructure. And also, the employees' skill sets to a more cloud-centered future.

**Polycloud** is a general term that encompasses any cloud computing infrastructure that uses multiple clouds. It can be public, private, or hybrid. This term includes both multicloud and hybrid cloud environments. The key difference is that multicloud does not specify the exact combination of clouds used, whereas multicloud and hybrid cloud are more specific about their configurations

### What are the some of the use cases for multicloud?

Businesses use a variety of cloud platforms and services. This helps with their digital transformation.

Companies are choosing to deploy apps on public, private, and edge clouds. This best serves their business goals and application requirements. Cloud Smart has taken the position of Cloud First.

Data backup and storage are dependable. They are simpler and less expensive. Concerns about cloud spending, data control, vendor dependence, and lock-in are increasing. Hence, businesses will keep spreading their estate across various surroundings.

Applications need to be closer to physical objects and users. So, they need to be deployed to the edge. This improves automation, efficiency, and consumer experiences. The sectors include logistics, retail, and manufacturing.

The hybrid workforce problem is growing. It's challenging to secure, manage, and enable workers, and their devices. So that, they can be productive everywhre.

### What type of challenges can occur in case of multicloud?

IT businesses are adopting multicloud environments. The challenges in achieving their objectives are becoming more visible as:

Different workflow and management tools can be expensive. They can cause excess storage and more infrastructure-complexity. Operating multiple clouds requires expertise. They need more time and human resources. Vendors may employ various strategies or tactics to manage challenges. So, simple processes like providing resource become complicated. They have unique portals, APIs, and processes. They need to be controlled.

A company would be more exposed to potential threats and weaknesses. Thus, more work is required for effective security, governance, and consent. Businesses keep introducing new multi-platform tools. Hence, IT leaders need to retrain workers frequently. Companies struggle to recruit employees with the necessary multicloud expertise. It's challenging to adapt quickly to new innovations. The provider maturity levels and API, vary. Multicloud can make these tasks challenging.

## Milestones

2011

The hybrid cloud concept is introduced. It requires an interaction between a private and public cloud. It needs the ability to shift workloads between the two clouds.

2012

Multicloud appears when businesses begin to use SaaS providers. These include human resources, customer relations management, and supply chain management.

2013

Multi-cloud trend starts gaining popularity.

2018

The analyst firm Forrester conducts a survey on behalf of Virtustream. It includes cloud strategy and application management decision makers in the US, EMEA, and APAC. The majority of them characterize their organizations' cloud strategy as "multicloud." There are 727 respondents to the survey. 86% of them use multiple public and private clouds for different application workloads.

Multicloud


# Logistic Regression

## Summary

Suppose we're asked to classify emails into two categories: spam or not spam. Compare this with another application that attempts to predict product sales given recent advertising expense. Unlike the second example in which the target variable is continuous, email classification predicts a **categorical variable**.

**Logistic regression** is a statistical method used for classifying a target variable that is categorical in nature. It is an extension of a linear regression model. It uses a logistic function to estimate the probability of a target variable belonging to a particular class or category.

## Discussion

### Could you explain logistic regression with an example?

Consider email classification as an example. To be able to predict if an email is spam or not, we will extract relevant information from the emails such as:

    + Sender of the email
    + Number of typos in the email
    + Occurrence of words or phrases such as "offer", "prize", "free gift", etc.The above information is converted into a vector of numerical features. These numerical features are linearly combined and then transformed using a logistic function to give a score in the range 0 to 1. This score is the probability of an email being either spam or not. If the probability is higher than 50%, then the email will be classified as spam.

### What are different types of logistic regression?

There are three types of logistic regression:

    + **Binary or binomial**: where the dependent variable can have only two outcomes. Examples: spam/not-spam, dead/alive, pass/fail.
    + **Multiclass or multinomial**: where the dependent variable is classified into three or more categories and these categories are not ordered. Examples: types of cuisines (Italian, Mediterranean, Chinese).
    + **Ordinal**: where the dependent variable is classified into three or more categories and these categories are ordered. Examples: movie rating (1-5).

### Why can't I use linear regression for predicting classes?

In classification problems, we are predicting the probability that the outcome variable belongs to a particular class. If linear regression is used for classification, it will **treat the classes or categories as numbers**. It will fit the best line that minimises the distance between the data points and the line. The linear regression equation would just give scores that lie along the best fit line. These scores cannot be interpreted as probabilities. A meaningful threshold cannot be set to distinguish the classes.

Also, the linear regression model fits a straight line that can extrapolate. **Values can go out of range**, such as below 0 or above 1 (-∞ to ∞). Since probability lies in a fixed range between 0 to 1, in logistic regression, a logistic function is applied so that the dependent variable only takes values between 0 and 1.

### What is the logistic function?

**Logistic function** also known as **sigmoid function** is **an S-shaped curve** that can take any real-valued number and transforms it into a number between 0 and 1 using the following equation:

$$f(x)= \frac{1}{1+e^{-x}}$$

In the above image as x approaches ∞, then, f(x) becomes 1 and as x approaches -∞, then, f(x) becomes 0.

$$f(x) = \frac{1}{1+e^{-∞}} = 1, \qquad e^{-∞}\to 0$$

$$f(x) = \frac{1}{1+e^{-(-∞)}} = \frac{1}{1+ e^∞} = 0, \qquad 1/∞ \to 0$$

### What are GLMs and how are they relevant to logistic regression?

**Generalized Linear Models** (GLMs) are a class of **non-linear regression models** that can be used in certain cases where linear models do not fit well. They're applicable when the outcome variable follows a non-linear distribution such as binomial, exponential, poisson, etc.

A GLM is represented by the following equation:

$$\large{g(E(y))=\beta\_0+\beta\_1{}x\_{1}+\ldots{}\beta\_p{}x\_{p}}$$

Where,

    + \(E(y)\) is the mean value or the expected value of the outcome variable that follows an assumed distribution
    + \(\beta\_0+\beta\_1{}x\_{1}+\ldots{}\beta\_p{}x\_{p}\) is the linear predictor i.e. the weighted sum of features where \(\beta\) is the weight and x is the explanatory variable.
    + \(g\) is the link function that mathematically links the expected value of the outcome variable and the linear predictor.GLM is a generalised form of linear regression and logistic regression is a specific type of GLM. For logistic regression, we can derive a specific link function \(g\) called the **logit function**.

### What is the logistic regression equation and the logit function?

Let's start with the linear regression equation:

$$y=\beta\_0+\beta\_1{}x\_{1}\qquad(1)$$

We derive the link function for logistic regression. In linear regression, \(y\) is a continuous variable. Since we want a probability for logistic regression, we will wrap the linear predictor in a logistic function so that the values do not go below 0 or beyond 1. We will denote this as probability with \(p\):

$$p=\frac{1}{1+e^{-(\beta\_0+\beta\_1{}x\_{1})}}\qquad(2)$$

The figure shows the probability that a person, given his/her age, will die within the next five years. We note that changing \(\beta\_0\) shifts the curve while changing \(\beta\_1\) affects steepness.

Using (1) we can rewrite (2) as:

$$p=\frac{1}{1+e^{-y}}=\frac{e^y}{1+ e^y}\qquad(3)$$

If \(p\) is the probability that an email is spam, then the probability of a non-spam email can be written as:

$$q=1-p=1-\frac{1}{1+e^{-y}}=\frac{1}{1+e^y}\qquad(4)$$

Dividing (3) by (4) we get,

$$\frac{p}{1-p}=e^y$$

Taking natural logarithm on both sides and substituting the value of y we get the **logistic regression equation**,

$$\ln(\frac{p}{1-p})=\beta\_0+\beta\_1{}x\_{1}$$

\(p/(1-p)\) is the **odds ratio**. \(\ln(p/(1-p))\) is the **link function** or **logit function**. The output values from this function are called **logits**.

### What is the cost function for logistic regression?

A **cost function** quantifies the error between the predicted value and the expected value. The weights of features in the model are estimated by minimising or maximising this cost function.

The cost function used in logistic regression is known as **Log Loss** or **Negative Log-Likelihood (NLL)** equation. It is the negative average of the log of correctly predicted probabilities for each instance in the training data.

$$-\frac{1}{N}\sum\_{i =1}^Ny\_i\cdot\ln(p(y\_i))+(1-y\_i)\cdot\ln(1-p(y\_i))$$

Where,

    + \(N\) is the number of training samples
    + \(y\_i\) is actual value of i'th sample
    + \(p(y\_i)\) is the predicted probability of the i'th sampleWe simplify this equation for the two possible outcomes for a single training sample:

    + True output y=1 (positive): \(-(1\cdot\ln(p) + (1–1)\cdot\ln(1-p)) = -ln(p)\)
    + True output y=0 (negative): \(-(0\cdot\ln(p) + (1–0)\cdot\ln(1-p)) = -ln(1-p)\)Also in the above graph we can see that since the scale is logarithmic the loss decreases slowly as the predicted probability gets closer to the true label. But, as the predicted probability diverges from the true label the loss increases rapidly. This has the effect of heavily penalising incorrect predictions.

## Milestones

1838

The logistic function is introduced in a series of three papers by Pierre François Verhulst between 1838 and 1847. He uses it as a model of population growth by adjusting the exponential growth model, under the guidance of Adolphe Quetelet.

1889

The term *regression* is coined by Francis Galton to describe a biological phenomenon. He observes that the heights of descendants of tall ancestors tend to regress down towards a normal average, a phenomenon also known as *regression toward the mean*.

1943

Wilson and Worcester use logistic model in bioassay which is the first known application of its kind.

1966

Cox introduces **multinomial logit model**. This is a step up for logistic regression applications with the logit model.

1973

Daniel McFadden links the multinomial logit to the **theory of discrete choice**, specifically Luce's choice axiom, showing that the multinomial logit follows from the assumption of independence of irrelevant alternatives and interpreting odds of alternatives as relative preferences. This gives a theoretical foundation for the logistic regression. In 2000, McFadden is awarded Nobel Prize for this contribution.

Logistic Regression


# 5G NR Hybrid ARQ

## Summary

5G NR supports Hybrid ARQ, which is a combination of retransmissions and error correction. Where possible, errors are corrected. Where correction is not possible, errors are detected and packet retransmission is requested. The receiver attempts to decode the packet based on current and previous transmissions.

In 5G NR, HARQ operates at both MAC and PHY layers. Retransmissions occur at the MAC layer. PHY layer at the receiver combines one or more transmissions to increase the chances of correct decoding.

The use of HARQ in 5G NR benefits URLLC and eMBB use cases. HARQ typically achieves a residual error rate of 0.1-1%. Better performance can be achieved but at the cost of increased feedback signalling, higher power or lower spectral efficiency.

## Discussion

### Why do we need HARQ in 5G when RLC and PDCP do retransmissions?

Retransmissions in 5G NR are possible at three layers: MAC, RLC and PDCP. RLC and PDCP being higher layers, the feedback signalling is slower. HARQ retransmissions at MAC react faster to channel conditions and improve performance for delay-sensitive applications. Applications requiring 100Mbps may need highly reliable connections to avoid triggering TCP congestion-avoidance mechanism. A combination of HARQ's fast retransmissions and RLC's reliable packet delivery achieves this.

RLC retransmissions are limited to logical channels in Acknowledged Mode (AM). HARQ offers retransmission capability for RLC UM and TM. Moreover, RLC transmissions can potentially happen on a different component carrier or cell but HARQ retransmissions happen on the same cell as the original transmission.

PDCP retransmissions are useful during inter-gNB handovers. Undelivered packets are forwarded at the PDCP layer from old to new gNB. RLC retransmissions won't work since new RLC entities are established in the new gNB. HARQ retransmissions won't work since HARQ buffers are flushed during handover.

### What are some technical details of 5G NR HARQ?

5G NR HARQ is **asynchronous**. Transmissions and retransmissions are explicitly signalled. They can be flexibly scheduled. They're not pre-determined according to some fixed pattern. Asynchronous HARQ is also more suited for unlicensed bands.

5G NR HARQ is **adaptive**. Retransmissions can use different coding rates and redundancy bits. Receiver doesn't discard erroneous packets but stores them in its buffer. All versions are used to improve decoding. The method employed to combine different versions of the packet is called **Incremental Redundancy**.

HARQ is a stop-and-wait protocol. Another packet is not sent while waiting for feedback on the current packet. Due to the round trip time, this results in underutilization of radio resources. 5G NR HARQ solves this by allowing **multiple concurrent HARQ processes**. Each process can have one packet pending an ACK. In both downlink and uplink, UE supports up to 16 HARQ processes per cell.

HARQ applies to transmissions on PDSCH and PUSCH. Feedback for PDSCH comes on either PUCCH or PUSCH. Feedback for PUSCH is via uplink grants since receiver and scheduler are in gNB.

### Could you share more details of Incremental Redundancy as specified in 5G NR?

5G NR HARQ doesn't discard erroneous packets. They're stored in a buffer and combined with retransmitted packets that will be received later. This is called **Hybrid ARQ with Soft-Combining**. With Incremental Redundancy, retransmitted packets related to the same information bits although each packet carries a different subset of information and parity bits. Exactly what goes into each transmission is determined by 5G NR's rate matching functionality. Each transmission is called a **Redundancy Version (RV)**.

The error-correcting code used in 5G NR is Low Density Parity Check (LDPC) code. For LDPC, the order in which RVs are received matters because some RVs can't be decoded on their own. The default order is 0, 2, 3 and 1. RV0 and RV3 are self-decodable. The first transmission RV0 includes all information bits (aka systematic bits).

HARQ's implicit link adaptation can be superior to explicit link adaptation since additional RVs are sent only when needed. Explicit link adaptation is still relevant for delay-sensitive applications.

### What's the role of PHY and MAC layers for HARQ operation?

There's one MAC entity (and therefore one HARQ entity) for each serving cell. Each HARQ entity handles many HARQ processes. HARQ entity distributes the traffic among its processes. Each process handles one TB at a time but if downlink spatial multiplexing is configured, two TBs are possible. In downlink, HARQ processes are also used for slot aggregation, also called TTI bundling. In this case, a TB is retransmitted without waiting for ACK.

At MAC, New Data Indicator (NDI) is used to determine if a received TB is a new transmission or a retransmission. When NDI is toggled in DCI, it implies new downlink data. Toggling NDI in uplink grant informs UE to send new data.

When a retransmitted TB is received, MAC informs PHY to combine current and previous transmissions of the TB. Thus, PHY layer is responsible for soft combining and decoding. However, from a 5G specification perspective, CBG retransmissions are specified at PHY though they could have been specified at MAC.

### What's the difference between TB vs CBG retransmissions?

Exactly one MAC PDU goes into one Transport Block (TB). MAC does TB retransmissions but the problem in 5G NR is that a TB can be as big as 1,277,992 bits. Retransmitting the entire TB when only a few bits are in error wastes spectral resources. It's for this reason that 5G NR has the concept of Code Block (CB) and Code Block Group (CBG).

A TB along with its CRC is broken up into smaller units called Code Blocks. A CB has a maximum size of 8448 bits. Each CB is protected with its own CRC. However, sending ACK/NACK for each code block can result in excessive signalling. For this reason, 2/4/6/8 code blocks are grouped into a Code Block Group. Only CBGs are retransmitted, not the entire TB. Even the feedback signalling is based on CBGs and not on CBs.

A TB can have only one CBG, which in turn may have one or more CBs. It's also possible for a TB to have multiple CBGs with only one CB per CBG.

### Could you share details of HARQ codebooks?

A UE can acknowledge multiple CBGs or TBs together, including the case of Carrier Aggregation (CA) where multiple TBs are received per TTI. How many ACK/NACK bits to send and how to package these bits is defined as a **codebook**.

5G NR defines four codebooks:

    + **CBG-Based HARQ-ACK Codebook**: RRC configures the UE with maximum CBGs per TB and CBGFI. If a TB has fewer CBGs, UE shall send NACKs for the remaining bits.
    + **Type-1 HARQ-ACK Codebook**: A *semi-static* codebook. The number of bits to send in an ACK/NACK report is fixed and could be potentially large. If many component carriers are configured but only a few are scheduled, this is inefficient.
    + **Type-2 HARQ-ACK Codebook**: A *dynamic* codebook or *enhanced dynamic* codebook (Release 16 onwards). This is more optimized since UE sends feedback only for the scheduled carriers. However, in poor channel conditions, UE may wrongly infer the number of carriers that were scheduled. To solve this problem, 5G NR specifies Downlink Assignment Index (DAI) as part of DCI.
    + **Type-3 HARQ-ACK Codebook**: Applicable for *OneShotFeedback*. UE sends ACK/NACK report for all HARQ processes and all CCs configured in the PUCCH group.

### Between data reception and its ACK/NACK, how is the timing offset determined?

The offset between DCI slot and start of PDSCH reception is determined by \(K\_0\) and the different numerologies of PDCCH and PDSCH. Likewise, parameter \(K\_2\) specifies the offset between DCI slot and PUSCH transmission. Both these are configured by RRC.

Specific to HARQ is the parameter \(K\_1\). This specifies the timing between PDSCH and the ACK/NACK on PUCCH. In DCI formats 1\_0, 1\_1 and 1\_2, this is called **PDSCH-to-HARQ Feedback Timing Indicator**. This indicator references an RRC-configured table for PDSCH. Timing is indicated dynamically via DCI or semi-statically via RRC configuration.

In the above figure, three PDSCH transmissions happen but in each transmission a different timing offset is specified. The gNB has scheduled this in such a way that the feedback for all three transmissions arrive together. We may say a single HARQ codebook acknowledges all three transmissions.

If ACK/NACK is sent on PUCCH, UE uses the PUCCH resources allocated to it.

### What are the main Release 16 changes pertaining to HARQ?

To support URLLC use case, some changes are introduced in Release 16. Out-of-order feedback is possible so that feedback for URLLC can be prioritized over eMBB. In Release 15, a slot has only one PUCCH carrying HARQ feedback. Release 16 allows multiple PUCCHs within a slot. Moreover, a UE can have two HARQ-ACK codebooks to support both URLLC and eMBB services.

Before sending HARQ feedback in NR-U, the UE has to gain access to the channel via Listen Before Talk (LBT) with exponential backoff. This can be avoided if feedback comes in the same Channel Occupancy (CO) as the downlink data. If CO changes, a Release 16 gNB asks the UE to send HARQ feedback for specific HARQ processes and these could come via an enhanced dynamic codebook.

In Non-Terrestrial Networks (NTNs), HARQ operation is a challenge due to RTTs in the order of hundreds of milliseconds. Release 16 has chosen to semi-statically disable HARQ and rely only on ARQ.

### What control information are specified for 5G NR HARQ operation?

Downlink Control Information (DCI) carries PDSCH and PUSCH scheduling information. DCI comes in many formats. Formats 0\_0, 0\_1 and 0\_2 schedule PUSCH in a cell. Formats 1\_0, 1\_1 and 1\_2 schedule PDSCH in a cell. Other formats are not relevant to HARQ.

If multiple PUSCH are scheduled, 2-8 bits are possible for NDI and RV in 0\_1. For PUSCH scheduling, DAI can indicate semi-static codebook (1 bit), dynamic codebook (2 bits) or enhanced dynamic codebook (4 bits). Second DAI can be 0/2/4 bits.

If second TB is scheduled for PDSCH, NDI and RV are included per TB. DAI length for PDSCH scheduling in 1\_1 depends on number of DL serving cells and other configurations. Length of PDSCH-to-HARQ feedback timing field is derived from higher layer configuration.

Fields Code Block Group Transmission Information (CBGTI) and Code Block Group Flush Indicator (CBGFI) are relevant only if retransmissions are based on CBG. What NDI does for TB-level soft-combining, CBGFI does for CBG-level soft-combining.

### How is 5G NR HARQ different from 4G/LTE HARQ?

In LTE and 5G NR, retransmissions can be adaptive in uplink and downlink.

The use of code blocks is common to LTE and 5G NR but 5G NR has introduced CBG-based retransmissions.

In 5G NR, HARQ is asynchronous in downlink and uplink. In 4G/LTE, HARQ is asynchronous in downlink and synchronous in the uplink. However, Release 13 introduced asynchronous UL HARQ that's used by License-Assisted Access (LAA). Synchronous HARQ is not suitable in 5G NR due to dynamic TDD and operation in unlicensed spectra.

In LTE synchronous UL HARQ, the same process ID is used every eighth subframe. An LTE UE responds with HARQ ACK 3ms after receiving the downlink data. 5G NR has more flexibility to respond faster for URLLC use cases. In fact, first transmission and its retransmission can happen within 1ms.

In LTE, Physical HARQ Indicator Channel (PHICH) is a dedicated downlink channel to carry HARQ ACK/NACK for uplink traffic carried on PUSCH. Such a channel is not required in 5G NR since HARQ is asynchronous.

In LTE, the number of HARQ processes was limited to 8 but this is increased to 16 in 5G NR.

## Milestones

1960

At the Fourth London Symposium on Information Theory, Wozencraft and Horstein propose HARQ, although they don't use the term "HARQ". In a subsequent MIT Technical Report, they state, "The system is somewhat similar to human communication, in that typical errors are corrected, while grievous ones initiate a request for retransmission."

Sep
2002

3GPP publishes Release 5 of 3G/UMTS specification. High Speed Downlink Packet Access (HSDPA) is one of the important additions in this release. At the air interface, this includes HARQ with soft combining (chase combining or incremental redundancy) in the downlink with up to 8 HARQ processes. It complements ARQ at the RLC layer. HARQ operation happens in a new sublayer called MAC-hs in the UE and NodeB.

Sep
2005

3GPP publishes Release 6 of 3G/UMTS specification. High Speed Uplink Packet Access (HSUPA) is one of the important additions in this release. At the air interface, this includes HARQ with soft combining (chase combining or incremental redundancy) in the uplink with up to 8 HARQ processes. HARQ operation happens in a new sublayer called MAC-e in the UE and NodeB. During a soft handover and due to parallel HARQ processes, RNC might receive duplicate packets and out-of-order packets. MAC-es sublayer in the RNC handles these.

Mar
2009

3GPP publishes the first 4G/LTE specification, named Release 8. This includes asynchronous HARQ in downlink and synchronous HARQ in uplink. Each direction can have up to 8 HARQ processes. Retransmissions can be adaptive or non-adaptive. Although a TB is segmented into code blocks, retransmissions happen at the level of TB.

Mar
2016

3GPP publishes Release 13 of 4G/LTE specification. Uplink HARQ operation can now be asynchronous, a change introduced to support License-Assisted Access (LAA). This is because in unlicensed spectrum it's not possible to guarantee resources for synchronous transmission.

Dec
2017

3GPP approves the first specifications for 5G, called "early drop" of Release 15. The basics of 5G NR HARQ are defined in this early release: HARQ processes, RV, PDSCH-to-HARQ feedback timing indicator, DAI, NDI, CBGTI, CBGFI, and semi-static and dynamic codebooks.

Jul
2020

3GPP publishes Release 16 specifications. Enhanced dynamic HARQ-ACK codebook is introduced. DCI formats 0\_2 and 1\_2 are added for PUSCH or PDSCH scheduling in one cell respectively. One-shot HARQ-ACK request is added to DCI format 1\_1. Other fields added to DCI format 1\_1 and relevant for enhanced dynamic codebook are number of requested PDSCH groups, PDSCH group index, and New Feedback Indicator (NFI).  For operation with shared spectrum channel access, enhanced dynamic codebook and one-shot triggering are useful.

5G NR Hybrid ARQ


# CSS Box Model

## Summary

CSS is used to style HTML documents. An important insight is that,

> Every element in web design is a rectangular box

No matter how complex the design, at the level of elements, it's just a bunch of boxes. The "box" is an underlying representation. We don't actually see a box unless the designer chooses to show it's border.

Each box has width and height. It's border may or may not be visible. Content resides within the box. Content maybe surrounded by extra spacing. Each box is separated from its neighbouring boxes by defined distances. The CSS Box Model formalizes these ideas in terms of CSS properties and the values they can accept.

Understanding the box model is essential for any web designer or developer. Browsers have built-in tools that enable developers visualize these boxes during development and debugging.

## Discussion

### Which are the essential elements of the CSS Box Model?

Suppose there's a text element `<div>Hello World!</div>`. Let's assume that content begins at the left edge of the box and flows to the right. Content "Hello World!" is placed within the box. The box has a size defined by **height** and **width**. These dimensions are calculated from the size of the parent element, size of the content or defined explicitly for the element.

The edge of the box is called the **border**. Border can be invisible, thin (few pixels) or thick (many pixels). It can be a solid line, a dotted line, and so on. It can be in a chosen colour.

If we include extra spacing within the box along its edges, this is called **padding**. An element usually appears next to other elements (parent or siblings). The separation from one element to the next is defined by **margin**.

Border, padding and margin can all have different values for each side of the box. Some border properties are inherited by default. Padding and margin are not inherited by default unless declared explicitly.

### How is margin different from padding?

Margin occurs outside the box to separate elements. Padding occurs within the box to add spacing between box edge and content. To put it differently, margin controls rendering of an element and its neighbours, whereas padding controls rendering of an element and its children.

Because padding area is within the box, CSS properties applied to the box affect the padding area as well. For example, if the element has green background colour, the padding area will have green background but the margin background colour is not affected. In fact, the margin background colour will be determined by that of the parent element.

Non-zero padding increases the overall dimensions of the element. Margin adds spacing outside the box. Adding a margin is like shifting the entire box whereas adding padding is like shifting the content within the box.

Padding can't be negative but margin can be negative. With a negative margin, an element can "jump out" of its parent or overlap with another element.

### How are width and height of a box determined?

Total width of an element is calculated as `margin-right + border-right + padding-right + width + padding-left + border-left + margin-left`, where `width` is the box width. The calculation for height is similar, using top and bottom rather than right and left.

If element has CSS declaration `box-sizing: border-box;` then total width changes to `margin-right + width + margin-left`. Padding and border sizes don't affect total box dimensions. Content area shrinks.

Box width and height can be specified in CSS, for example `width: 50%` and `height: 100px`. Values are either absolute (pixels, points, inches, etc) or relative (percentage of parent, percentage of viewport, fraction of font size, etc).

If width and height are not specified, they're determined by the content. For block elements, width is 100% of the parent by default. It's better to specify them if the element size is essential to the overall layout.

If width and height are specified, but if the content requires more space than available, rendering behaviour is controlled by `overflow` property, which can take values `visible`, `hidden`, `scroll` and `auto`.

### How do I use display CSS property?

CSS `display` property is important since it affects how the box is rendered. Common values for `display` include:

    + `none`: Element is not displayed. Unlike `visibility:hidden` that hides an element but leaves an empty space, `display:none` leaves no empty space.
    + `inline`: Element is displayed on the same line as adjacent elements. Height and width are determined by the content and can't be set explicitly. This is the default for span, a, img, em, strong, i, small, etc. Only left and right margins are applicable. Padding is applicable on all four sides but top and bottom padding may bleed into lines above and below.
    + `inline-block`: Similar to inline but height and width can be set. Box model properties are applicable here. The problem of vertical bleeding seen in inline is solved with inline-block.
    + `block`: Element is displayed on a separate line and takes up 100% width of the parent. This is the default for div, h1, p, li, section, etc.

### What are some variants of the box model?

While the box model is often displayed as inline, inline-block or block, there are other variants. A specialization of the box model is `display:table`. This obeys block flow. Cells flow into rows and columns. Table box has margins but not padding. Cells have padding but not margins. Properties `border-collapse` and `table-layout` are applicable.

Another variation is `display:list-item`, equivalent to using `<li>` tag. Property `list-style-type` is applicable.

It's possible to take out an element from normal flow and put it in a separate layer. This is achieved with property `position`. Common values include `absolute` (relative to closest ancestor), `relative` (relative to itself in normal flow) and `fixed` (relative to viewport, unaffected by scrolling). Such boxes don't affect the position of other boxes. These boxes can overlap freely. Property `z-index` controls how they overlap, with larger values coming on top.

Another way to take out an element from normal flow is with `float`. Common values include `left`, `right`, `inline-start` and `inline-end`. Unlike `position`, boxes affect adjacent content in the flow. For example, a box floated left will indent adjacent content to the right.

### What is margin collapsing?

Consider two sibling elements, each set with margin of 20px. With inline-block display, elements are separated by 40px since margins are additive. However, if we change to block display, adjacent margins collapse into a single margin of 20px. Note that padding is not subject to collapsing.

Collapsed margin size is the largest of the individual margins. If there are negative margins involved, collapsed margin is the most positive or the most negative margin. When all margins are negative, it collapses to the most negative margin.

Margin collapsing happens for adjacent siblings; when there's no content separating parent and descendants; for empty blocks; and more complex scenarios when these conditions are combined.

It's been said that margin collapsing is one of design mistakes in CSS. There are rules to when margins can collapse but there are also many exceptions to the rules. This makes it difficult and confusing for a web developer. One way to overcome this complexity is to consistently set right and bottom margins and zero out top and left margins, such as, `margin: 0 40px 40px 0;`.

### Could you share some tips for working with CSS Box Model?

Here are some useful tips for beginners:

    + If width is not set, it defaults to 100%. Padding and border will push inwards. If width is explicitly set to 100%, padding and border will push outwards as normal.
    + Left and right margins can take the value `auto` to center the element horizontally. This is not possible with padding. For centering vertically, use `display: table-cell; vertical-align: middle;` for the element and `display: table` for its parent. CSS Flexbox offers a simpler approach.
    + To inherit only right margin and fix other margins, use `margin: 10px 0 20px 15px; margin-right: inherit;`.
    + Use `box-shadow` with `rgba` values to improve design quality.
    + To fit images to a certain width without exceeding the original width or distorting it, use `max-width: 100%; height: auto;`.
    + Element height depends on content height and remains unaffected by `height: 100%`. Height can be controlled using padding, such as `height: 0; padding-bottom: 100%;`.
    + Columns with different content can be made to have the same height using large padding and negative margin. Suppose bottom padding is 10px, we can use `margin-bottom: -99999px; padding-bottom: 100009px;`. CSS Flexbox offers a simpler approach.

### Which are some CSS modules that are relevant to the CSS Box Model?

**CSS Intrinsic & Extrinsic Sizing** is the module that talks about `box-sizing` property that's directly relevant to the box model. This property can take values `content-box` (default) and `border-box`.

The box model relates to only one element. When designing layout, the use of CSS properties `margin`, `display` and `float` are helpful. However, there are CSS3 modules that work with the box model and simplify layout design:

    + **CSS Flexbox**: Children of a container can adjust their sizes to fit the container. This can happen in one dimension, either horizontally or vertically. By nesting, two-dimensional layouts can be achieved.
    + **CSS Grid**: A two-dimensional layout system that's easier to work with than Flexbox. This is a modern alternative to the `<table>` tag from the early days of HTML.
    + **CSS Multi-column**: Content flows into multiple columns with gap and rule between columns.Another useful module is **CSS Box Alignment** that works with layout modules to align elements within their container parent. Elements can be positioned within the parent, spaces between elements can be controlled, and containers can be configured to align the elements within.

## Milestones

Dec
1996

W3C publishes *Cascading Style Sheets, level 1*, simply called **CSS1**, to express styling of HTML documents. It borrows from desktop publishing terminology. It states that each formatted element is treated as a rectangular box surrounded by optional padding, border and margin areas. Top and bottom margins can collapse.

Aug
2001

Microsoft releases Internet Explorer 6, which conforms to the W3C CSS box model. Earlier releases of IE implemented a modified box model that ignored border and padding when computing the total width or height of an element: `total width = margin-left + width + margin-right`. Effectively, earlier versions of IE reduced content size to make room for border and padding. This behaviour is possible in CSS3 via `box-sizing: border-box;`.

Aug
2002

First draft of **CSS2.1** is published, which is a revision of CSS2 from 1997. CSS2.1 becomes a W3C Recommendation in June 2011. For clarify, it adds the terms border edge and padding edge. Inner edge is also called content edge. Outer edge is also called margin edge. Unlike in CSS1, margin, padding and border properties can be **inherited**.

Oct
2002

W3C publishes the first working draft of *CSS Box Model Module Level 3*. Subsequent revisions of this draft appear in 2007, 2018 and 2020. The main change is to bring clarity for **vertical writing modes**.

2011

Bowers et al. publish the book *Pro HTML5 and CSS3 Design Patterns*. They note that to speak of the box model as a single model is an oversimplification. They identify six types of the box model: inline, inline-block, block, table, absolute and floated.

Apr
2020

W3C publishes the first public working draft of *CSS Box Model Module Level 4*. Property `margin-trim` is introduced with three possible values: `none`, `in-flow` and `all`. Often we include margins between siblings but we wish to avoid margins before/after first/last sibling since they border the parent container. This property when used on an element trims margins of children that border the container's edges.

CSS Box Model