0

I am reading about the concept of Side Car and Multi Process Application in cloud foundry .

  1. https://docs.cloudfoundry.org/devguide/multiple-processes.html
  2. https://docs.cloudfoundry.org/devguide/sidecars.html

I have few questions which I could not figure out myself.

Q1: When to use a CF Application with Sidecar vs when to use a CF Application with Processes

I understood that the primary difference between sidecar vs multiple process application is related to container. A sidecar process runs in the same container whereas for multi process application all of them run in separate containers.

I could not figure out , in which scenarios we should use sidecar vs in which scenarios we can use multiple process application

Q2: Different Processes in different technology

In an application with multiple processes , if I want to run 2 processes in 2 different technology ( one process on Java another process in Go / anything else), how to do so ? This question comes to my mind as I see the buildpack configuration goes with the application , not with the process. So I am getting an impression as if only all processes must be in same technology ( or we can provide multiple buildpacks here ?) .

Here is a sample manifest.yml that I am using:

applications:
  - name: multi-process1
    disk_quota: 1G
    path: target/SampleApp-1.jar
    instances: 1
    memory: 2G
    buildpacks:
      - java_buildpack
    env:
      CONFIG_SERVER_PORT: 8080
    processes:
      - type:  'task'
        command: '$PWD/.java-buildpack/open_jdk_jre/bin/java -jar $PWD/BOOT-INF/lib/mycustomlogger-1.jar'
        memory: 512MB 
        instances: 1
        health_check:
          type: http
          
      - type:  'sampleProcess2'
        command: '$PWD/.java-buildpack/open_jdk_jre/bin/java -jar $PWD/BOOT-INF/lib/mycustomlogger-1.jar'
        memory: 512MB 
        instances: 1
        health_check:
          type: http    
          
      - type:  'web'
        #command: '$PWD/.java-buildpack/open_jdk_jre/bin/java  $PWD/BOOT-INF/classes/com/example/SampleApp'
        memory: 1G 
        health_check:
          type: http   

Q3: Interacting processes

In this context how can one process call/talk/interact with the other processes within the application. What are the options available here ? I could not find any sample which demonstrate multiple interacting processes within an app, any sample would be really helpful.

Q4 : Difference between Multi Target Application vs Multi Process Application

I came across a concept called Multi Target Application , reference : https://www.cloudfoundry.org/blog/accelerating-deployment-distributed-cloud-applications/

I did not find such possibility in standard Cloud Foundry, but I felt it might be "similar" to Multi Process app ( since they run on independent containers and are not impacting each other). My questions are:

  • What are the differences between Multi Target Application vs Multi Process Application?
  • What are the fundamental Could Foundry concepts on which Multi Target Application is built ?

Any guidance would be really appreciated.

1 Answers1

1

Q1: When to use a CF Application with Sidecar vs when to use a CF Application with Processes

Different process types are helpful when you have well-separated applications. They might talk to each other, they might interact, but it's done through some sort of published interface like a REST API or through a message queue.

A typical example is a work queue. You might have one process that's running your web application & handling traffic, but if a big job comes in then it'll instruct a worker process, running separately, to handle that job. This is often done through a message queue. The advantage is you can scale each individually.

With a sidecar, they are in the same process. This works well for the scenario where you need tight coupling between two or more processes. For example, if you need to share the same file system or if you have proxy process that intercepts traffic.

The two processes are often linked in a way that they are scaled in tandum, i.e. there is a one-to-one relationship between the processes. This relationship is necessary because if you scale up the application instance count, you're scaling up both. You cannot scale them independently.

In an application with multiple processes , if I want to run 2 processes in 2 different technology ( one process on Java another process in Go / anything else), how to do so ?

You're correct. You'd need to rely on multi-buildpack support.

Your application is only staged once and a single droplet is produced. Each process is spun up from the same droplet. Everything you need must be built into that one droplet. Thus you need to push everything all together and you need to run multiple buildpacks.

In your manifest.yml, the buildpacks entry is a list. You can specify the buildpacks you want to run and they will run in that order.

Alternatively, you could pre-compile. If you're using Go. Cross-compilation is often trivial, so you could compile ahead of time and just push the binary you generate with your application.

In this context how can one process call/talk/interact with the other processes within the application. What are the options available here ? I could not find any sample which demonstrate multiple interacting processes within an app, any sample would be really helpful.

I'll split this in two parts:

If you're talking about apps running as a sidecar, it depends on what the sidecar does, but you have options. Basically, anything you can do in a Linux environment, keeping in mind you're running as a non-root user, you can do. Coordinate through a shared file/folder, intercept the network port & proxy to another port, or other ipc.

If you're talking about multiple processes (the CF terminology) such that you have each running in a separate container, then you are more limited. You would need to use some external method to communicate. This could be a service broker, a database (not recommended), or an API (Rest, gRCP or rsocket are all options).

Note that this "external" method of communication doesn't necessarily need to be public, just external to the container. You could use a private service like a broker/DB, or you could use internal routes & container networking.

Q4 : Difference between Multi Target Application vs Multi Process Application

Sorry, I'm not sure about this one. Multi Target apps are not a core concept in CF. I'll leave it for someone else to answer.

Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28
  • Hello @Daniel , Many thanks for this detailed and amazing response. Regarding `Q3: Interacting processes`, sorry I was not clear about my scenario. In this case I wanted to check the possibilities of interacting between processes in a Multi Process Application ( not with Side Car process , I could access using localhost). In the example `manifest` attached with the question , I am trying to create spring boot applications as separate processes. But I do not know how to access them /call them since they so not expose accessible "routes". I also could not find any example easy to understand. :( – atanu mallik Jan 09 '22 at 07:19
  • I am also aware that in case of Multi Process Application ( https://docs.cloudfoundry.org/devguide/multiple-processes.html ) each of these processes are running in its own *container*. So we need to overcome the boundary of _container_. It might be possible to use an external message broker ( like Kafka) where both processes can communicate using events. However If I want to tryout something simple using REST, where one process exposes an Endpoint and another process consumes the endpoint, can it be done ? ( I did something similar for sidecar process using `localhost` url). – atanu mallik Jan 09 '22 at 07:34
  • 1
    I updated the answer. I think an internal route might be what you're missing. That would replace `localhost`, but can still be "internal" to the application and not public. – Daniel Mikusa Jan 10 '22 at 19:26
  • Is it possible to bind ( map) a route to a Process ? In my example, I am starting a springboot web app as a process under a multiple processes application. This spring boot application runs in its container. I want to map this to a route , how to achieve it?@Daniel Mikeusa – atanu mallik Jan 15 '22 at 20:29
  • Since my application is a multi process application , It spawns individual containers for each of the processes. I can ssh into one such container using `cf ssh multi-process1 --process sampleProcess2` and inside the container I am able to access the running spring boot app using `curl http://localhost:8080`. My question is : it is possible to map a route (internal / external) to a springboot app running inside the process container? When I check the documentation for `map-route`, I do not see any possibility to map a route to a process. This is where I am not able to connect the dots. – atanu mallik Jan 16 '22 at 06:27
  • Note: This is not a productive application , I am trying to learn the CF technology and this questions come to my mind after reading the documentation. Many thanks @Daniel for taking your time to help the community and this is a great help for me and keeps me interested in learning this technology. – atanu mallik Jan 16 '22 at 06:29
  • 1
    According to the CF v3 API documentation, you can set the process type. See http://v3-apidocs.cloudfoundry.org/version/3.113.0/index.html#the-destination-object. I don't see options to do that in the cf cli though, under create-route or map-route (with the v8 cf cli). You would probably need to `cf curl` and set that manually, but this is all very new so hopefully the cf cli will get that capability soon. – Daniel Mikusa Jan 17 '22 at 01:00