DSA 👨🏻‍💻, Callback & Promises, Event Loop ⟳, Database indexes ⛁

By Prajwal Haniya

Techletter #53 | December 31, 2023

Why DSA matters?

DSA matters for the following reasons:

I have taken the below excerpt from zerotosoftwarearchitect.com

Programmers at the big tech companies, who continually come up with innovative products, are expected to write software from the bare bones, with or without frameworks. LinkedIn developed Kafka, the most used message queue in the industry, to deal with the trillions of messages that were being sent across the users on the platform.

Quoting from the article “The total number of messages handled by LinkedIn’s Kafka deployments recently surpassed 7 trillion per day.”

The scale at which data was generated on the platform, the existing solutions failed to address the needs. Thus they had to develop the stream processing platform, which they later open-sourced. Besides message processing, Kafka is also used to facilitate activity tracking, collecting application metrics and logs, and more at LinkedIn.

Similarly, all the big tech write innovative products and features from the bare bones to address their unique requirements. Facebook & Google came up with the concept of single-page applications to deal with the spaghetti JavaScript code. They open-sourced React and Angular, respectively. Kubernetes came out of Google. Facebook developed Cassandra for inbox search. These are a few examples of the software written in-house at the big tech; you can visit the GitHub repos of the respective companies to find more tools and open source projects they actively work on.

So, to develop solutions like these, a programmer is expected to have knowledge of computer science fundamentals, primarily data structures and algorithms. If you look at the job interview requirements of these companies, they prefer to focus on the fundamentals as opposed to a specific technology.

Explain callback & callback hell

A callback is a function that you pass to another function, and the original function calls your callback function when it finishes its own task. A callback hell arises when you start nesting multiple callbacks inside each other. The pyramid structure indicates the callback hell.

To avoid callback hell we can use async/await, promises, event listeners

What is the difference between callback, promises & async/await?

Callback: A callback is a function that is passed as an argument to another function and is executed after the completion of a particular task.

Promises: A promise is an object representing the eventual completion or failure of an asynchronous operation. It provides a cleaner and more structured way to handle asynchronous tasks compared to callbacks.

Async/await: Async/await is a syntactic sugar built on top of promises, making asynchronous code look and behave more like synchronous code. The async keyword is used to define a function that returns a promise, and the await keyword is used to pause the execution of the function until the promise is resolved.

Working of an event loop

Notes From the book Operating System Concepts

A computer system can be divided roughly into four components: the hardware, the operating system, the application programs, and a user.

An operating system is similar to a government. Like a government, it performs no useful function by itself. It simply provides an environment within which other programs can do useful work.

we can view an operating system as a resource allocator. A computer system has many resources that may be required to solve a problem: CPU time, memory space, storage space, I/O devices, and so on. The operating system acts as the manager of these resources. It’s also a control program. A control program manages the execution of user programs to prevent errors and improper use of the computer. It is especially concerned with the operation and control of I/O devices.

The operating system is the one program running at all times on the computer, usually called the kernel. Along with the kernel, there are two other types of programs:

System programs: which are associated with the operating system but are not necessarily part of the kernel.

Application programs: which include all programs not associated with the operation of the system.

The operating system includes the always running kernel, middleware frameworks that ease application development and provide features, and system programs that aid in managing the system while it is running.

Operating systems have a device driver for each device controller. This device driver understands the device controller and provides the rest of the operating system with a uniform interface to the device.

A modern general-purpose computer system consists of one or more CPUs and a number of device controllers connected through a common bus that provides access between components and shared memory

Consider a typical computer operation: a program performing I/O.

To start an I/O operation, the device driver loads the appropriate registers in the device controller. The device controller, in turn, examines the contents of these registers to determine what action to take (such as “read a character from the keyboard”). The controller starts the transfer of data from the device to its local buffer. Once the transfer of data is complete, the device controller informs the device driver that it has finished its operation. The device driver then gives control to other parts of the operating system, possibly returning the data or a pointer to the data if the operation was a read.

For other operations, the device driver returns status information such as “write completed successfully” or “device busy”. But how does the controller inform the device driver that it has finished its operation? This is accomplished via an interrupt.

Hardware may trigger an interrupt at any time by sending a signal to the CPU, usually by way of the system bus.

There may be many buses within a computer system, but the system bus is the main communications path between the major components.

What are database indexes?

Indexes in databases are like organized catalogs for books, making it much faster to find specific information. Instead of scanning every single page of every book to locate a topic, you can consult the catalog to pinpoint its exact location.

An index is a separate, specially organized structure that stores a subset of the database’s columns and their corresponding values.

Indexes are typically created on columns that are frequently used in search criteria, filtering, sorting, and joining tables.

The choice of which columns to index and the specific index types (B-tree, hash, bitmap, etc.) depends on:

https://web.archive.org/web/20231230122426/https://www.freecodecamp.org/news/database-indexing-at-a-glance-bb50809d48bd/