Getting a budget alert notification when your DCP cost exceed your budget is a great way to stay on top of your cloud costs. But controlling costs is more than just avoiding billing surprises. It's also important to provide your teams with the flexibility they need while also minimizing or restricting unnecessary costs. In this video, we'll talk about programmatic budget notifications and go over some examples to help you set up advanced cost controls. In an earlier video, we covered how to trigger email alert notifications when you've exceeded your budgets. And these budget alerts are sent to billing account administrators and billing account users so you can easily control who gets those notifications. However, this also means if there's a need to investigate or follow up with other teams about a charge, you'd have to depend on potentially time consuming offline conversations to determine if any changes need to be made. If you want to put more proactive controls in place, programmatic budget notifications then allow you to run code based on your budgets. For this, we'll use cloud pub/sub. If you're not familiar with pub/sub, think of it as a simple message handler which passes on any events such as budget updates, to any services that are subscribed to it. Cloud functions is a lightweight and serverless way to run code, and it's an ideal solution for quickly handling budget alerts. Any budgets you create with a pub/sub topic will publish the current status of a budget multiple times per day, rather than waiting for a threshold to be crossed. With each budget you set up, you can have both email notifications and programmatic notifications. When setting up advanced cost controls like this, you'll want to have your finance and IT teams work together, since this process involves both sides. When setting up a budget, after choosing the thresholds, you can connect cloud pub/sub to the budget where you'll choose a project, and pub/sub topic to receive notifications. Once the budget is published into pub/sub, you can have any number of subscribers that will handle the notifications, such as cloud functions. Once you've got everything connected with pub/sub, the cloud function will receive notifications with some information. Such as the billing account ID, the display name of the budget, the most recent threshold exceeded, and the amount of your cost for the scope of your budget. Now that you're writing code with this information, you can pretty much do anything that GCP API lets you do. One very common example is to post an update to slack, or other platforms connecting any tools your teams used to stay on top of your costs. Again, this keeps people up to date, but we can also automate direct cost controls to respond to these notifications. One of the more drastic actions you can take, is to disable billing on a project entirely. For example, you may have a development or test environment, and a dev team that constantly spins up resources in that environment. If someone on the team spins up in an expensive resource, like a large compute instance, and forgets to turn it off, it can rack up costs pretty quickly. One way to avoid this maybe to set up a budget and programmatic budget notification, that removes the billing account from the project after a specified cost is reached. It's important to note that when you disable billing on a project, all the billing resources for that project are shut down and then deleted. This is probably not something you want to do in a production environment, but can be a quick way to make sure you set a very hard limit on your cost for that project. Sometimes a more nuanced approach is better, such as limiting the number of resources that can be spun up with quota or simply stopping all compute instances without deleting them. That way you're not paying for them, and the appropriate team can investigate why the usage was higher than planned. When testing your code, you can manually send pub/sub messages so you don't have to actually wait for the budget amount to be triggered. Another driver of unnecessary or accidental costs, can be from resources that aren't being used optimally. Over provisioned resources are larger than they need to be, to serve the current workloads. And since this is the cloud, it can be easier to scale them down as needed. Idle or part time idle resources can also be an easy target for saving costs, since they can be stopped or scaled down when they're not at peak usage. All of these can also be automated on a scheduled basis, such as regularly looking for resources that aren't being used and removing them. You'll find examples of these in the labs covered later in this quest. Using programmatic budget notifications is another step towards setting up cost controls that match your business needs. Each business is different, so how much you'd like to control, and to what extent are decisions to be made collaboratively between your finance and technology teams. Coming up next are the hands on labs. We've organized the labs into two groups along with walkthrough videos, to ease you into the more technical concepts. If you are a billing account administrator, or building account viewer, we recommend paying close attention to the lab walkthrough videos. And if you're also responsible for carrying out the technical tasks or cost optimization, we encourage you to complete the labs as well.