Azure Cosmos DB for Postgres Autoscale

Aaron Tonkovich 20 Reputation points
2024-09-21T20:15:26.4466667+00:00

Hello,

We're currently using Azure Cosmos DB for Postgres in production and we'd like to setup auto scaling using a similar strategy like this. However, this only shows scaling up and I'm curious if there's a way in citus to move shards into another worker node and remove that node. For example, collapsing two nodes into a single node.

Our use case would be to scale the DB both horizontally and vertically depending on time of day.

Thanks!

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,643 questions
0 comments No comments
{count} votes

Accepted answer
  1. Vinodh247 21,881 Reputation points
    2024-09-22T10:37:33.5433333+00:00

    Hi Aaron Tonkovich,

    Thanks for reaching out to Microsoft Q&A.

    In Azure Cosmos DB for PostgreSQL (Citus), autoscaling horizontally involves adding or removing worker nodes based on the load. While scaling up (adding worker nodes) is straightforward, scaling down (removing worker nodes) requires manually redistributing shards before removing a node.

    Here’s a general approach for scaling down or collapsing nodes in Citus:

    Move Shards from a Node:

    To scale down, you need to first redistribute the shards from the node you wish to remove. This can be done using the rebalance_shards() function.

    For example, if you want to move the shards from worker node 2 to worker node 1:

         SELECT rebalance_shards('node_name_to_keep', 'node_name_to_remove');
    
    

    Remove a Worker Node:

    After moving the shards, you can safely remove the worker node that no longer holds any shards:

         SELECT master_remove_node('node_name_to_remove');
    

    Vertically Scale:

    You can vertically scale (scale up or down the vCores, memory, or storage) using Azure's built-in scaling options for each node, independent of Citus, by resizing the underlying VMs in the portal or via CLI.

    Automating Horizontal Scaling:

    For time-based horizontal scaling, you would have to script the process of adding and removing nodes. While there's no out-of-the-box autoscaler for Citus in Cosmos DB for PostgreSQL, you can use Azure Automation or scheduled runbooks to trigger rebalance_shards() and master_remove_node() functions based on time of day or other load metrics.

    This approach allows you to adjust the cluster size dynamically based on workload requirements. Let me know if you need further details on automating this or managing shard rebalancing!

    Please 'Upvote'(Thumbs-up) and 'Accept' as an answer if the reply was helpful. This will benefit other community members who face the same issue.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.