Bird
Raised Fist0
GCPcloud~30 mins

Concurrency and scaling in GCP - Mini Project: Build & Apply

Choose your learning style10 modes available
Concurrency and Scaling with Google Cloud Run
📖 Scenario: You are building a simple web service that needs to handle multiple users at the same time. To do this efficiently, you will use Google Cloud Run, which automatically scales your service based on demand.In this project, you will create a Cloud Run service configuration that sets up concurrency and scaling limits to control how many requests each instance can handle and how many instances can run.
🎯 Goal: Create a Cloud Run service configuration YAML file that sets the concurrency to 10 requests per instance and limits the maximum number of instances to 5.
📋 What You'll Learn
Create a YAML file named cloudrun-service.yaml for Cloud Run service configuration.
Set the concurrency to exactly 10 in the configuration.
Set the maximum number of instances to exactly 5.
Include the required metadata and spec fields for a valid Cloud Run service.
💡 Why This Matters
🌍 Real World
Cloud Run is used to deploy containerized web services that automatically scale based on traffic. Setting concurrency and max instances helps control performance and cost.
💼 Career
Understanding concurrency and scaling in Cloud Run is essential for cloud engineers and developers to build efficient, cost-effective serverless applications.
Progress0 / 4 steps
1
Create the basic Cloud Run service YAML structure
Create a YAML file named cloudrun-service.yaml with the basic structure for a Cloud Run service. Include apiVersion set to serving.knative.dev/v1, kind set to Service, and a metadata section with name set to my-service.
GCP
Hint

Start by defining the API version, kind, and metadata with the service name.

2
Add the spec and template sections for the service
Add a spec section with a template inside it. Under template, add spec and then containers list with one container. The container should have image set to gcr.io/cloudrun/hello.
GCP
Hint

Remember to nest spec and template properly and add the container image.

3
Set concurrency to 10 requests per instance
Inside the template section, add metadata with annotations. Add the annotation autoscaling.knative.dev/concurrency with the value 10 as a string.
GCP
Hint

Annotations go under template.metadata. The concurrency value must be a string.

4
Limit maximum instances to 5
Add another annotation under autoscaling.knative.dev/concurrency inside template.metadata.annotations. Set autoscaling.knative.dev/maxScale to the string 5 to limit the maximum number of instances.
GCP
Hint

Make sure the maxScale annotation is a string and placed alongside concurrency.

Practice

(1/5)
1. What does concurrency control in a Google Cloud service primarily manage?
easy
A. The network bandwidth available to the service
B. The total number of instances running
C. The number of requests one instance can handle at the same time
D. The amount of storage used by the service

Solution

  1. Step 1: Understand concurrency meaning

    Concurrency means how many tasks or requests can happen at once in one place.
  2. Step 2: Apply concurrency to cloud instances

    In cloud services, concurrency controls how many requests a single instance handles simultaneously.
  3. Final Answer:

    The number of requests one instance can handle at the same time -> Option C
  4. Quick Check:

    Concurrency = requests per instance [OK]
Hint: Concurrency = requests per instance at once [OK]
Common Mistakes:
  • Confusing concurrency with total instances
  • Thinking concurrency controls storage or bandwidth
  • Mixing concurrency with scaling
2. Which of the following is the correct way to set maximum concurrency to 10 in a Google Cloud Run service using gcloud CLI?
easy
A. gcloud run services create SERVICE --max-concurrency=10
B. gcloud run services update SERVICE --concurrency=10
C. gcloud run services update SERVICE --max-instances=10
D. gcloud run services update SERVICE --concurrency-limit=10

Solution

  1. Step 1: Identify correct flag for concurrency

    The correct flag to set concurrency in Cloud Run is --concurrency.
  2. Step 2: Use update command for existing service

    To change concurrency, use 'gcloud run services update SERVICE --concurrency=10'.
  3. Final Answer:

    gcloud run services update SERVICE --concurrency=10 -> Option B
  4. Quick Check:

    Concurrency flag is --concurrency [OK]
Hint: Use --concurrency flag with update command [OK]
Common Mistakes:
  • Using --max-concurrency which is invalid
  • Confusing concurrency with max-instances
  • Trying to set concurrency on service creation instead of update
3. Consider a Cloud Run service with max concurrency set to 5 and max instances set to 3. If 20 requests arrive simultaneously, how many instances will be used to handle the load?
medium
A. 5 instances
B. 4 instances
C. 20 instances
D. 3 instances

Solution

  1. Step 1: Calculate needed instances for 20 requests with concurrency 5

    Each instance can handle 5 requests at once, so 20 requests need 20/5 = 4 instances.
  2. Step 2: Apply max instances limit

    The max instances is set to 3, so the service cannot create more than 3 instances.
  3. Final Answer:

    3 instances -> Option D
  4. Quick Check:

    Max instances limit caps instance count [OK]
Hint: Max instances limit caps scaling even if more needed [OK]
Common Mistakes:
  • Ignoring max instances limit and choosing 4
  • Confusing concurrency with max instances
  • Assuming one instance per request
4. You set concurrency to 80 on a Cloud Run service, but your app crashes under load. What is the most likely cause?
medium
A. The app cannot handle that many requests at once causing resource exhaustion
B. The max instances setting is too low
C. The service is not deployed in the right region
D. The concurrency setting must be at least 100

Solution

  1. Step 1: Understand concurrency impact on app

    High concurrency means many requests handled simultaneously by one instance, increasing resource use.
  2. Step 2: Link app crash to resource limits

    If the app crashes, it likely cannot handle that many requests at once, causing memory or CPU overload.
  3. Final Answer:

    The app cannot handle that many requests at once causing resource exhaustion -> Option A
  4. Quick Check:

    Too high concurrency can crash app [OK]
Hint: High concurrency can overload app resources [OK]
Common Mistakes:
  • Blaming region instead of concurrency
  • Assuming concurrency must be at least 100
  • Ignoring app resource limits
5. You want your Cloud Run service to handle sudden traffic spikes efficiently without wasting resources during low traffic. Which combination of settings is best?
hard
A. Set concurrency to a moderate number (e.g., 10) and allow max instances to scale high
B. Set concurrency to 1 and max instances to 1
C. Set concurrency very high (e.g., 100) and max instances low (e.g., 2)
D. Disable concurrency and fix max instances to 10

Solution

  1. Step 1: Balance concurrency and scaling for efficiency

    Moderate concurrency lets each instance handle multiple requests, saving resources.
  2. Step 2: Allow max instances to scale high for spikes

    High max instances lets the service add instances when traffic spikes, keeping performance.
  3. Final Answer:

    Set concurrency to a moderate number (e.g., 10) and allow max instances to scale high -> Option A
  4. Quick Check:

    Moderate concurrency + high max instances = efficient scaling [OK]
Hint: Moderate concurrency + high max instances for spikes [OK]
Common Mistakes:
  • Setting concurrency too low wastes instances
  • Setting concurrency too high risks crashes
  • Fixing max instances limits scaling
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard