What is a process and what is a thread?
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
When is better to use multi-proccessing vs multi-threading?
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.
==========================================
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.
🔧 Ejemplos:
Tarea Mejor opción
Scraping web de miles de URLs Multithreading
Entrenar un modelo de ML Multiprocessing
Procesar archivos pesados Multiprocessing
Escuchar múltiples sockets Multithreading
Comprimir miles de imágenes Multiprocessing
Descargar muchos archivos a la vez Multithreading
What is BE Idempotency
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)
-