Citus Introduction
Tags: database, postgressql, citus, programming
Published: 2023-08-31 10:06:23

In the evolving landscape of data management, the challenges of horizontal scaling are becoming crucial. Citus is an open-source extension for PostgreSQL that gives it the power of scalability with distrubuted tables. It takes the strength of PostgreSQL's data integrity and combines it with the scalability and performance of a distributed database management. In this blog we will explore about citus, about how it handles large-scale data.

## Introduction

Traditionally relational databases like SQL and PostgreSQL maintains data integrity and along with that also provides powerful querying capability. PostgreSQL is one of the mist popular open source database management system. One of the main issue or the limitation we can say is dealing with extremely large data sets which requires high concurrency demand. Citus addresses these challenges by providing a solution of architecture that spread all the data across different or multiple  nodes. Which enables better hardware resource management and improvement in performance.

## Citus Architecture
Citus is designed in such a way that a in a citus cluster, all servers run PostgreSQL having citus extension along with other number of extensions installed. Citus mainly uses the PostgreSQL's extension API's to change the behaviour of database in two ways.

- It replicates database objects, which mainly includes custom types and function, to all servers.
- It add two new table types that are used to take the advantages of the additional servers.

![Citus image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/idvsemva3mup3ezhskwv.png)

It basically uses the sharding mechanism to deal with scalability. Which means it divide the large datasets into different managable parts called `chunks` or `shards` and then divides these chunks on different nodes. It manages the query very intelligently by sending those to the relevant node and then collection result from those.

## Key Features
### Horizontal Scalability:
It allows us to divide or distribute our data across multiple nodes, allowing us to scale out by adding more computer or machines to our cluster instead of vertically scaling by increasing the power of already machines we have to manage our workload.
### Parallel Processing
As our data is distributed across multiple nodes, so citus can execute queries in parallel which in turns combines the query processing power from all nodes and to speed up performance. It can speed up query porcessing by 20x to 300x or more times with the help of this parallelism.
![Query Processing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bnt5mnjh2caffifng5cy.png) 

### High Throughput
It is well suited and optimized for large-scale data application. As it uses different nodes to process high volume of data and queries which helps it to prevent different bottlenecks and ensure highly efficient utilzation of resources. 

### Multi-Tenancy
Citus can be used to build multi-tenant applications, in which data is stored across separate distrubuted tables.

### Ease of use

Because of its compatibility with POstgreSQL, you can use familiar PostgreSQL tools, extensions and techniques. So you can also easily use and learn Citus if you are familar with PostgreSQL. 

## Conclusion
It provides a strength to relational database having an option to scale it horizontally. Making it a good choice for all the user applications that are in need of both powerful query capability and handle large-data along with concurrent users. It's main use case is in real-time analytics, large-scale applications where we need high power system so instead of vertical scaling we can do the same job using horizontal scaling of Citus.