How to shard using OrientDB
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
OrientDB, a versatile multi-model database supporting graph, document, object, and key/value models, has sharding capabilities that enable it to scale out across distributed architectures. Sharding is the process of splitting and distributing data across multiple servers or nodes, each holding a part of the dataset. This setup helps in managing large datasets and high throughput operations by distributing the workload.
Understanding Sharding in OrientDB
In OrientDB, sharding is often referred to as "Distributed Architecture". The database uses a multi-master architecture, meaning all nodes are active and can handle requests for read and write operations. Data is partitioned across various servers known as nodes, and each node holds one or more shards.
Setting up Sharding
To set up sharding in OrientDB, you need to follow these steps:
- Installation and Node Setup: Begin by installing OrientDB on all the nodes that will be part of the cluster. Every node in the system should have OrientDB installed and configured properly.
- Configuration: Configure the
hazelcast.xmlanddefault-distributed-db-config.jsonfiles. These configuration files control aspects of networking among the nodes and the distribution strategy of the clusters (the term OrientDB uses for shards). - Starting the Server: Start the OrientDB server on all nodes. Each node will try to communicate with other nodes as per the configuration to form a cluster.
- Database Creation: Create a new database through the OrientDB Studio or console. When creating a database in a distributed setup, it automatically becomes distributed unless specified otherwise.
- Class and Cluster Creation: When you create a class (comparable to a table in relational databases), OrientDB automatically creates clusters. Adjust the number of clusters per class depending on the expected load and database size. You can manually specify on which nodes each cluster resides using the
CREATE CLUSTERcommand.
- Data Distribution: Data distribution can be controlled using sharding strategies like round-robin or by hashing based on a specific field. For custom sharding strategies, additional coding and configuration are required.
Example Scenario
Imagine you have a social media application storing user data. You want to distribute this data across three servers to ensure high availability and load distribution.
First, install OrientDB on three servers, configure them to join the same cluster, and create a "SocialMedia" database. Next, create a class User:
Define clusters for this class across your servers:
This setup routes the data into different clusters based on the user's region, assuming your application logic routes them correctly when creating new records.
Benefits and Considerations of Sharding with OrientDB
Sharding offers scalability and improves application performance as the database grows. However, it also introduces complexity in the configuration and maintenance of the database system. Monitoring and optimizing the performance across different nodes become crucial.
Here’s a brief summary table of key points discussed:
| Feature | Description |
| Multi-master architecture | Every node can handle read and write requests, enhancing redundancy and availability. |
| Manual cluster management | Control over the number of clusters and their distribution across servers. |
| Custom sharding strategies | Allows implementation of specific logic to control data distribution. |
Conclusion
Sharding with OrientDB provides a robust way to distribute data across multiple servers, which is especially beneficial for applications processing large amounts of data. By setting up clusters and carefully configuring them as illustrated, OrientDB can significantly boost an application's performance and scalability.
Related reading
- How to share a single static class code among different applications
- How to share faust table between multiple agents or faust timers?
- How to share rate limiting state between traefik instances?
- How to solve Timeout FeignClient
- How to show a MySQL warning that just happened?
- How to show the last queries executed on MySQL?
- How to solve two generals issue between event store and persistence layer?
- How to stop all containers when one container stops with docker-compose?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.