Solutions#

Concurrency#

Solution to Exercise 1

Both:

  • a bird is flying away

  • but another bird is flying towards this bird’s departure point to eat the rest of the bread

Even we tend to focus on sequences, but world is inherently concurrent.

Solution to Exercise 2

Speaking with someone, traffic lights, playing football

Solution to Exercise 3

Like the nature, computers need to work in a concurrent fashion to deal with the concurrency of the daily life.

Solution to Exercise 5

C10k problem

problem of optimizing network sockets to handle a large number of clients at the same time. Nowadays the number is rather 10M rather than 10k.

In the first scenario, there is no bottleneck. Each thread gets 100 us. In the second one, all threads want the be executed inside a second and we need to change threads => 10000 * (100 us + 1 us) = 1.01s. The threads won’t be executed timely.

If the number of threads is high, then the thread switching cost overweighs.

Solution to Exercise 6

Typical desktop applications do not have frequent reads writes to the disks or network. Webserver’s purpose is serving web clients.

Solution to Exercise 7

  1. We use non-blocking calls, we put the requests in a queue, we poll them one by one.

  2. Unnecessary polling

Future-proof systems#

Solution to Exercise 9

Yes and no.

  • reliability: the hardware is designed to be fault-tolerant and highly available

  • modularity: components can be replaced

  • adaptability: new components can be added (to a limited degree)

  • longevity: Excerpt from IBM System/360

    … announced by IBM on April 7, 1964…

    Application-level compatibility (with some restrictions) for System/360 software is maintained to the present day with the System z mainframe servers.

  • does not scale like elastic cloud computing

  • programming models (COBOL) are not aligned with modern practices

  • specialized knowledge required which is typically not taught in universities

  • integration with cloud-native applications?

Solution to Exercise 10

Without a codebase, it becomes impossible to coordinate in a team. A single codebase means that one base is contains all the information to deploy the whole app.

Solution to Exercise 11

If the dependencies are not provided, then the setup of the system will not be deterministic. This makes especially the setup by another employee difficult.

Solution to Exercise 12

To maintain a central config is difficult. Every deployment should have their own set of variables

Customer A environment variables

DATABASE_URL=postgres://customerA-db-url
API_KEY=customerA-api-key
LOG_LEVEL=debug

Customer B environment variables

DATABASE_URL=postgres://customerB-db-url
API_KEY=customerB-api-key
LOG_LEVEL=info

Where do we provide these environment variables? In context of GitLab CI, we could provide all the environment variables in Settings CI/CD Variables and gitlab-ci.yml could iterate over all these variables to deploy the system at different URLs.

Solution to Exercise 13

You hardcode a local database service to your app in your source code:

DATABASE_URL = "postgres://localhost:5432/mydb"

When you want to scale, you want to change to an external provider. Switching will not be very straightforward, because this info is hidden somewhere in the code.

Solution to Exercise 14

If run and build were not separated, they the error probability of a simple restart of the app would be much higher, because build has typically much more actions than run. This would create a burden for an administrator who may not be developing the app and thus may not be aware of the technical details

Solution to Exercise 16

An app binds directly to HTTPS. This makes a future multiplexing of multiple service on HTTPS difficult.

Solution to Exercise 15

If a process creates own local files, then this will create difficulties in the future when the app is horizontally scaled, because the user must be routed to the specific process.

Solution to Exercise 17

Imagine you have a monolithic web application that uses a single process. You only want to scale up database processing. Scaling up only this part will not be possible.

Solution to Exercise 18

Imagine the application process takes a long time to start. It will not be able to handle traffic spikes.

Backend maintenance#

Solution to Exercise 21

Some distributions like Ubuntu and Debian have extra security-update channels and security updates are automatically installed as default. However, in a mission-critical production system, it may be necessary to facilitate additional checks.