How santanusinha/dropwizard-db-sharding-bundle works
Main Components Identification
• Sharding Bundles – The core classes (e.g., DBShardingBundle, MultiTenantDBShardingBundle, BalancedDBShardingBundle) in the package indicate that the library supports various sharding strategies.
• Sharding Logic Module – This includes the hashing (using Guava’s murmur3_128), bucket-to-shard mapping logic (using a 1024 bucket default), and the logic used to calculate the target shard.
• Data Access Objects (DAOs) – There are multiple DAO implementations (RelationalDao, LookupDao, CacheableLookupDao, CacheableRelationalDao) that serve as a layer above Hibernate.
• Cache Modules – Components such as LookupCache and RelationalCache abstract the caching layer (supporting integrations with Caffeine/Guava caches).
• Administration and Health Check Components – Such as Shard blacklisting tasks, BlacklistingStore interface, and health check classes that ensure the operational status of shards.
• Utility and Support Components – Including transaction execution, filtering (TransactionFilter), listeners, observers, and metrics to observe operations and record system behavior.
Relationships and Interactions
• The dropwizard bundle initializes and configures the sharding logic at application startup by determining the number and mapping of physical shards.
• Business data flows from the application to the DAOs. The DAOs use the sharding logic to calculate the correct shard (bucket mapping, then shard selection) before interacting with the database via Hibernate sessions.
• The caching wrappers (CacheableLookupDao & CacheableRelationalDao) intercept DAO calls to provide read-through/write-through behavior.
• Administrative components allow runtime management features such as blacklisting problematic shards. Health checks monitor the state of shards.
• The DAO operations (such as Save, Get, Select, and Update) are broken down into operations classes that implement specific transactional or query behaviors.
Architectural Patterns and Design Principles
• Separation of Concerns – Sharding mechanisms, data access, caching, and administration are clearly separated into different packages and classes.
• Plugin/Extensibility Model – With interfaces like ShardBlacklistingStore, custom cache implementations, and transaction observers, the framework is designed to be extensible.
• Modular design – Each component (e.g., sharding, caching, DAO operations) has its dedicated package and sub-packages, which helps in understanding and maintaining the code.
• Dropwizard Integration – The bundle is designed to integrate with Dropwizard, leveraging its configuration, lifecycle, and health check mechanisms.
Essential Elements
• Interaction paths for resharding scenarios: Optionally include an annotation or note showing the resharding process when the number of physical shards changes.