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.