Backend Executions Patterns Flashcards

1
Q

What is a process and what is a thread?

A

PROCESS
- A set of instructions (for instance, a piece of Assembly code)
- Has an isolated memory
- has a PID
- Scheduled in CPU (every time a process go to an I/O device, it is kicked of the CPU. As a process you want to avoid being kicked off the CPU)

THREAD
It is a Light Weight Process (LWP) which means:
- A set of instruction
- shares memory with Parent Process
- Has a ID

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When is better to use multi-proccessing vs multi-threading?

A

Multiprocessing architecture is better when:

Multiprocessing is well-suited for CPU-bound tasks where parallelism is needed. It can take full advantage of multi-core processors since each process can run on a separate core. Examples include data processing, scientific simulations, and rendering.

  • Task requires full CPU utilization: In CPU-bound tasks, where the computation is the dominant factor and there’s little I/O or waiting involved, multiprocessing can take advantage of multiple CPU cores more effectively than multithreading.
  • Fault tolerance is crucial: If one process crashes, it won’t affect the others, ensuring better isolation and fault tolerance.
  • Need to leverage multiple machines: Multiprocessing can be distributed across multiple machines in a cluster, which can be useful for scaling and handling large-scale parallel processing.

==========================================
Multithreading architecture is better when:

-Multithreading is suitable for I/O-bound tasks and tasks that involve a lot of waiting, such as handling multiple client connections in a server application, GUI applications, and web servers. It may not fully utilize multiple CPU cores if the threads spend a lot of time waiting.

  • Task requires high communication and data sharing between threads: Threads in the same process can easily share data and communicate, which can be more efficient than inter-process communication used in multiprocessing.
  • Task is I/O-bound: If the tasks involve a lot of waiting for I/O operations (e.g., reading from files, network communication), multithreading can be more efficient as threads can release the CPU and let other threads run while waiting.
  • Memory footprint is a concern: Threads within a process share the same memory space, making it more memory-efficient than multiprocessing, where each process has its own memory space.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is BE Idempotency

A

The BE is Idempotency when you can make a request that change the state of the BE and if you retry that request (because, for example, you loose the connection), the state of the BE is not going to be affected.

An example is a comment in a Social media, you make the POST, loose connection, so you try to make the post again, but the first POST was actually executed and the comment was saved.

On possible solution for this is a request ID to keep track if the request was executed or not.

==================
In HTTP:
- GET is idempotent (don’t have side effects)
- POST isn’t, but we can make it.
- Browsers and Proxys treat GET as Idempotent (never makes state change in GET request because of that)
-

How well did you know this?
1
Not at all
2
3
4
5
Perfectly