This principle in the operational excellence pillar of the
[Google Cloud Well-Architected Framework](https://docs.cloud.google.com/architecture/framework)
provides recommendations to help you manage and optimize the resources that are
used by your cloud workloads. It involves right-sizing resources based on actual
usage and demand, using autoscaling for dynamic resource allocation,
implementing cost optimization strategies, and regularly reviewing resource
utilization and costs. Many of the topics that are discussed in this principle
are covered in detail in the
[Cost optimization](https://docs.cloud.google.com/architecture/framework/cost-optimization)
pillar.

## Principle overview

Cloud resource management and optimization play a vital role in optimizing
cloud spending, resource usage, and infrastructure efficiency. It includes
various strategies and best practices aimed at maximizing the value and return
from your cloud spending.

This pillar's focus on optimization extends beyond cost reduction. It emphasizes
the following goals:

- **Efficiency**: Using automation and data analytics to achieve peak performance and cost savings.
- [**Performance**](https://docs.cloud.google.com/architecture/framework/performance-optimization): Scaling resources effortlessly to meet fluctuating demands and deliver optimal results.
- **Scalability**: Adapting infrastructure and processes to accommodate rapid growth and diverse workloads.

By focusing on these goals, you achieve a balance between cost and
functionality. You can make informed decisions regarding resource provisioning,
scaling, and migration. Additionally, you gain valuable insights into resource
consumption patterns, which lets you proactively identify and address potential
issues before they escalate.

## Recommendations

To manage and optimize resources, consider the recommendations in the following
sections. Each recommendation in this document is relevant to one or more of
the
[focus areas of operational readiness](https://docs.cloud.google.com/architecture/framework/operational-excellence/operational-readiness-and-performance-using-cloudops#focus-areas-of-operational-readiness).

### Right-size resources

Continuously monitoring resource utilization and adjusting resource allocation
to match actual demand are essential for efficient cloud resource management.
Over-provisioning resources can lead to unnecessary costs, and
under-provisioning can cause performance bottlenecks that affect application
performance and user experience. To achieve an optimal balance, you must adopt a
proactive approach to right-sizing cloud resources. This recommendation is
relevant to the governance
[focus area of operational readiness](https://docs.cloud.google.com/architecture/framework/operational-excellence/operational-readiness-and-performance-using-cloudops#focus-areas-of-operational-readiness).

[Cloud Monitoring](https://cloud.google.com/monitoring)
and
[Recommender](https://cloud.google.com/recommender)
can help you to identify opportunities for right-sizing. Cloud Monitoring
provides real-time visibility into resource utilization metrics. This visibility
lets you track resource usage patterns and identify potential inefficiencies.
Recommender analyzes resource utilization data to make intelligent
recommendations for optimizing resource allocation. By using these tools, you
can gain insights into resource usage and make informed decisions about
right-sizing the resources.

In addition to Cloud Monitoring and Recommender, consider
using custom metrics to trigger automated right-sizing actions. Custom metrics
let you track specific resource utilization metrics that are relevant to your
applications and workloads. You can also configure alerts to notify
administrators when predefined thresholds are met. The administrators can then
take necessary actions to adjust resource allocation. This proactive approach
ensures that resources are scaled in a timely manner, which helps to optimize
cloud costs and prevent performance issues.

### Use autoscaling

Autoscaling compute and other resources helps to ensure optimal performance and
cost efficiency of your cloud-based applications. Autoscaling lets you
dynamically adjust the capacity of your resources based on workload
fluctuations, so that you have the resources that you need when you need them
and you can avoid over-provisioning and unnecessary costs. This recommendation
is relevant to the processes
[focus area of operational readiness](https://docs.cloud.google.com/architecture/framework/operational-excellence/operational-readiness-and-performance-using-cloudops#focus-areas-of-operational-readiness).

To meet the diverse needs of different applications and workloads,
Google Cloud offers various autoscaling options, including the following:

- [Compute Engine managed instance groups (MIGs)](https://docs.cloud.google.com/compute/docs/instance-groups#managed_instance_groups) are groups of VMs that are managed and scaled as a single entity. With MIGs, you can define autoscaling policies that specify the minimum and maximum number of VMs to maintain in the group, and the conditions that trigger autoscaling. For example, you can configure a policy to add VMs in a MIG when the CPU utilization reaches a certain threshold and to remove VMs when the utilization drops below a different threshold.
- [Google Kubernetes Engine (GKE) autoscaling](https://docs.cloud.google.com/kubernetes-engine/docs/concepts/cluster-autoscaler)
  dynamically adjusts your cluster resources to match your application's
  needs. It offers the following tools:

  - Cluster Autoscaler adds or removes nodes based on Pod resource demands.
  - Horizontal Pod Autoscaler changes the number of Pod replicas based on CPU, memory, or custom metrics.
  - Vertical Pod Autoscaler fine-tunes Pod resource requests and limits based on usage patterns.
  - Node Auto-Provisioning automatically creates optimized node pools for your workloads.

  These tools work together to optimize resource utilization, ensure
  application performance, and simplify cluster management.
- [Cloud Run](https://cloud.google.com/run)
  is a serverless platform that lets you run code without having to manage
  infrastructure. Cloud Run offers built-in autoscaling, which
  automatically adjusts the number of instances based on the incoming
  traffic. When the volume of traffic increases, Cloud Run
  scales up the number of instances to handle the load. When traffic
  decreases, Cloud Run scales down the number of instances to
  reduce costs.

By using these autoscaling options, you can ensure that your cloud-based
applications have the resources that they need to handle varying workloads,
while avoiding overprovisioning and unnecessary costs. Using autoscaling can
lead to improved performance, cost savings, and more efficient use of cloud
resources.

### Leverage cost optimization strategies

Optimizing cloud spending helps you to effectively manage your organization's
IT budgets. This recommendation is relevant to the governance
[focus area of operational readiness](https://docs.cloud.google.com/architecture/framework/operational-excellence/operational-readiness-and-performance-using-cloudops#focus-areas-of-operational-readiness).

Google Cloud offers several tools and techniques to help you optimize
cloud costs. By using these tools and techniques, you can get the best value
from your cloud spending. These tools and techniques help you to identify areas
where costs can be reduced, such as identifying underutilized resources or
recommending more cost-effective instance types. Google Cloud options to
help optimize cloud costs include the following:

- [Committed use discounts (CUDs)](https://docs.cloud.google.com/docs/cuds) are discounts for committing to a certain level of usage over a period of time.
- [Sustained use discounts](https://docs.cloud.google.com/compute/docs/sustained-use-discounts) in Compute Engine provide discounts for consistent usage of a service.
- [Spot VMs](https://docs.cloud.google.com/compute/docs/instances/spot) provide access to unused VM capacity at a lower cost compared to regular VMs.

Pricing models might change over time, and new features might be introduced that
offer better performance or lower cost compared to existing options. Therefore,
you should regularly review pricing models and consider alternative features. By
staying informed about the latest pricing models and features, you can make
informed decisions about your cloud architecture to minimize costs.

Google Cloud's
[Cost Management](https://cloud.google.com/cost-management)
tools, such as budgets and alerts, provide valuable insights into cloud
spending. Budgets and alerts let users set budgets and receive alerts when the
budgets are exceeded. These tools help users track their cloud spending and
identify areas where costs can be reduced.

### Track resource usage and costs

You can use tagging and labeling to track resource usage and costs. By
assigning tags and labels to your cloud resources like projects, departments, or
other relevant dimensions, you can categorize and organize the resources. This
lets you monitor and analyze spending patterns for specific resources and
identify areas of high usage or potential cost savings. This recommendation is
relevant to these
[focus areas of operational readiness](https://docs.cloud.google.com/architecture/framework/operational-excellence/operational-readiness-and-performance-using-cloudops#focus-areas-of-operational-readiness):
governance and tooling.

Tools like Cloud Billing and Cost Management help you to get a comprehensive
understanding of your spending patterns. These tools provide detailed insights
into your cloud usage and they let you identify trends, forecast costs, and make
informed decisions. By analyzing historical data and current spending patterns,
you can identify the focus areas for your cost-optimization efforts.

Custom dashboards and reports help you to visualize cost data and gain deeper
insights into spending trends. By customizing dashboards with relevant metrics
and dimensions, you can monitor key performance indicators (KPIs) and track
progress towards your cost optimization goals. Reports offer deeper analyses of
cost data. Reports let you filter the data by specific time periods or resource
types to understand the underlying factors that contribute to your cloud
spending.

Regularly review and update your tags, labels, and cost analysis tools to ensure
that you have the most up-to-date information on your cloud usage and costs. By
staying informed and conducting cost postmortems or proactive cost reviews, you
can promptly identify any unexpected increases in spending. Doing so lets you
make proactive decisions to optimize cloud resources and control costs.

### Establish cost allocation and budgeting

Accountability and transparency in cloud cost management are crucial for
optimizing resource utilization and ensuring financial control. This
recommendation is relevant to the governance
[focus area of operational readiness](https://docs.cloud.google.com/architecture/framework/operational-excellence/operational-readiness-and-performance-using-cloudops#focus-areas-of-operational-readiness).

To ensure accountability and transparency, you need to have clear mechanisms
for cost allocation and chargeback. By allocating costs to specific teams,
projects, or individuals, your organization can ensure that each of these
entities is responsible for its cloud usage. This practice fosters a sense of
ownership and encourages responsible resource management. Additionally,
chargeback mechanisms enable your organization to recover cloud costs from
internal customers, align incentives with performance, and promote fiscal
discipline.

Establishing budgets for different teams or projects is another essential
aspect of cloud cost management. Budgets enable your organization to define
spending limits and track actual expenses against those limits. This approach
lets you make proactive decisions to prevent uncontrolled spending. By setting
realistic and achievable budgets, you can ensure that cloud resources are used
efficiently and aligned with business objectives. Regular monitoring of actual
spending against budgets helps you to identify variances and address potential
overruns promptly.

To monitor budgets, you can use tools like
[Cloud Billing budgets and alerts](https://docs.cloud.google.com/billing/docs/how-to/budgets).
These tools provide real-time insights into cloud spending and they notify
stakeholders of potential overruns. By using these capabilities, you can track
cloud costs and take corrective actions before significant deviations occur.
This proactive approach helps to prevent financial surprises and ensures that
cloud resources are used responsibly.