top of page

Concurrency



Having already explored how software handles processes, let's now delve into the concept of concurrency within the framework of the twelve-factor app methodology. This principle emphasizes the importance of scaling an application by increasing the number of process instances. Let’s take a look at an example.


PHP vs. Java Process Handling

Different programming languages and frameworks have their unique ways of managing processes. PHP, for instance, typically scales by spawning child processes under a parent Apache process. On the other hand, Java opts for a hefty JVM (Java Virtual Machine) process that handles concurrency through threads. This diversity in process handling stems from the core principle of treating processes as first-class citizens in your application's architecture.


Processes as First-Class Citizens: Why the Diversity?

In the twelve-factor app methodology, processes are elevated to a status of utmost importance. This philosophy is inspired by the UNIX process model, which is known for its robust service daemons (background processes) management. By prioritizing processes, developers acknowledge their critical role in the system's architecture, ensuring they're managed and maintained effectively.


Architecting for Diverse Workloads

A well-architected twelve-factor app is designed to efficiently handle different types of work by assigning them to specific process types. For example, HTTP requests might be managed by web server processes, while background tasks could be handled by worker processes. This specialization allows for more efficient processing and resource utilization.


Internal Multiplexing: Threading and Asynchronous Models

Within a twelve-factor app, processes can achieve internal multiplexing, meaning they're capable of handling multiple tasks or operations concurrently. This can be achieved through:

  • Threading: Utilizing multi-threading within the runtime VM allows a single process to create multiple threads of execution.

  • Asynchronous/Event-driven Models: This involves processes that don't wait for a task to complete before starting another. Instead, they initiate a task and move on, responding to events like network requests or I/O operations as they occur.


The Limits of Vertical Scaling

While internal multiplexing is powerful, there's a ceiling to how much you can scale up a single process or VM. This limitation underscores the necessity for applications to be designed to scale horizontally—across multiple processes and machines—to handle increased load efficiently.


Process Management: Formation and Operations

In twelve-factor apps, process formation refers to the array of different process types and the number of processes for each type. This setup doesn't involve daemonizing processes (running them in the background) or writing PID files, which can introduce points of failure. Instead, applications rely on the operating system's process managers (like systemd or upstart), distributed process managers in the cloud, or development tools like Foreman. These managers handle output streams, crash recoveries, and user-initiated restarts and shutdowns, ensuring a robust and scalable application infrastructure.


Let's illustrate these concepts with a simple example to further clarify the process model's role in scaling applications efficiently.



By embracing the process model and understanding its underlying principles, developers can architect applications that are not only scalable but also resilient and manageable across different environments. This approach to concurrency and process management is a key driver for building modern, efficient, and scalable software applications.

 

Comments


The Occasionally Amazing Newsletter!

Thanks for submitting!

© 2024 visakhunni.com

bottom of page