Chapter 5: Offloading operations with YugabyteDB Managed

YugaPlus - Offloading Operations

YugaPlus has become one of the top streaming platforms, with hundreds of millions of people around the world spending countless hours watching their favorite movies, series, and live events. The YugaPlus team has mastered the art of scaling in the cloud, building a service that handles user traffic with low latency across multiple regions and tolerates all sorts of possible outages.

However, maintaining such a platform was not a trivial task. The engineering and infrastructure teams were spending a significant portion of their time just to keep the streaming platform running, secure, and up-to-date.

Eventually, the YugaPlus team found a way to spend more time on innovation. They transitioned to YugabyteDB Managed, a DBaaS (Database-as-a-Service) that allowed them to offload the management, maintenance, and operations of their database cluster...

In this chapter, you'll learn how to do the following:

  • Deploy a free YugabyteDB Managed instance.
  • Connect the application to the YugabyteDB Managed cluster.

Prerequisites

You need to complete Chapter 4 of the tutorial before proceeding to this one.

Start YugabyteDB Managed cluster

YugabyteDB Managed is a fully managed YugabyteDB-as-a-Service that allows you to run YugabyteDB clusters on Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP). The service offers a free sandbox cluster for everyone wishing to use YugabyteDB in a real cloud environment.

Follow these steps to deploy a free YugabyteDB Managed instance:

  1. Create a YugabyteDB Managed account: https://cloud.yugabyte.com/signup

  2. Begin creating the free cluster by clicking on the Create a Free cluster button.

    YugatebyDB Managed Create Cluster

  3. Choose the Sandbox cluster option:

    YugatebyDB Managed Sandbox Cluster

  4. Select a preferred cloud provider and region (note, Microsoft Azure is available only for paid clusters):

    YugatebyDB Managed Select Cloud

  5. Click on the Add Current IP Address button to add the address of your machine (where you run the YugaPlus application) to the IP Allow list:

    YugatebyDB Managed Add Address

  6. Make sure to download the file with your cluster credentials:

    YugatebyDB Managed Download Credentials

  7. Wait while the cluster is being created:

    YugatebyDB Managed Cluster Creation

Spinning up and configuring your sandbox instance can take up to 5 minutes. During this time, the system is preparing everything you need to get started with your YugabyteDB Managed instance.

Connect the application to YugabyteDB Managed

After the YugabyteDB Managed cluster is started, go ahead and connect the YugaPlus movie recommendations application to it.

First, rebuild the YugaPlus backend image to remove one of the database migration files created in the previous chapter:

  1. Use Ctrl+C or run {yugaplus-project-dir}/docker-compose stop to stop the YugaPlus application containers.

  2. Rename the V2__create_geo_partitioned_user_library.sql file to skip_create_geo_partitioned_user_library.sql making sure it's not applied during the database migration phase. The YugabyteDB Managed sandbox instance can't be used for the geo-partitioning use case that explored in chapter 4.

    cd {yugaplus-project-dir}/backend/src/main/resources/db/migration/
    mv V2__create_geo_partitioned_user_library.sql skip_create_geo_partitioned_user_library.sql
    
  3. Navigate to the YugaPlus project dir:

    cd {yugaplus-project-dir}
    
  4. Rebuild the Docker images:

    docker-compose build
    

Next, start the application connecting to your YugabyteDB Managed cluster:

  1. Go to the YugabyteDB Managed Settings tab and copy the public address of your cluster instance:

    YugatebyDB Managed Public Address

  2. Open the{yugaplus-project-dir}/docker-compose.yaml file and update the following settings:

    - DB_URL=jdbc:yugabytedb://${YOUR_YBM_PUBLIC_ADDRESS}:5433/yugabyte?sslmode=require
    - DB_USER=${YOUR_YBM_USER}
    - DB_PASSWORD=${YOUR_YBM_PASSWORD}
    
    • ${YOUR_YBM_PUBLIC_ADDRESS} - is the public address (host) of your YugabyteDB Managed instance.
    • ${YOUR_YBM_USER} and ${YOUR_YBM_PASSWORD} - your database credentials from the file that you downloaded during the cluster configuration.
  3. Start the application:

    docker-compose up
    

As soon as the yugaplus-backend container starts, it applies the database migration files to your cloud database instance. You can view the created tables in the Tables tab of the YugabyteDB Managed dashboard.

YugatebyDB Managed Tables

Can't connect to YugabyteDB Managed?

If the application fails to connect to YugabyteDB Managed, ensure you've added your IP address to the IP Allow list.

Ask for movie recommendations one last time

With the YugaPlus backend operational and successfully connected to your YugabyteDB Managed cluster, do one final search for movie recommendations.

  1. Go to the YugaPlus UI.

  2. Ask for movie recommendations:

Need to troubleshoot slow queries?

And, as one last hint, if it seems that some queries are running slow, navigate to the Performance -> Slow Queries dashboard of YugabyteDB Managed to check if any require optimization.

YugatebyDB Managed Slow Queries

Congratulations! You've completed Chapter 5, the final chapter of the tutorial. Throughout this tutorial, you've learned essential capabilities of YugabyteDB that set you up for the next stage of your development journey.

Let's recap!

With that said, good luck building applications that scale and never fail! And don't forget to join our community, where you can get your questions answered and learn about the latest updates from the world of YugabyteDB.