GitHub release  GitHub stars  GitHub forks  GitHub watchers

Sharding-JDBC: A data sharding, read-write splitting, BASE transaction and database orchestration middleware. It provides maximum compatibilities for applications by JDBC and MySQL protocol.


Maven Status GitHub release

Build Status Coverage Status Gitter OpenTracing-1.0 Badge Skywalking Tracing


1. Data sharding

  • Both databases and tables sharding supported.
  • Standard aggregation functions, GROUP BY, ORDER BY, LIMIT and JOIN DQL supported.
  • Standard DML, DDL, TCL and database administrator command supported.
  • Sharding operator =, BETWEEN and IN supported.
  • Sharding algorithm customization and inline expression supported.
  • Route by hint supported.
  • Distributed sequence supported.

2. Read-write splitting

  • Multiple slaves replica supported.
  • Data consistency guarantee in same thread supported.
  • Mix read-write splitting and data sharding supported.
  • Route by hint supported.

3. BASE Transaction

  • Best efforts delivery transaction supported.
  • Try confirm cancel transaction (TBD).

4. Orchestration

  • Configuration center supported, can refresh dynamically.
  • Circuit breaker supported.
  • Open tracing supported.



Use JDBC connect databases without redirect cost for java application, best performance for production.

  • ORM compatible. JPA, Hibernate, Mybatis, Spring JDBC Template or JDBC supported.
  • Connection-pool compatible. DBCP, C3P0, BoneCP, Druid supported.
  • Multi SQL-based databases compatible. Any Database supported theoretically. Support MySQL, Oracle, SQLServer and PostgreSQL right now.

Sharding-JDBC Architecture


Database router. Deploy as a stateless server, support MySQL protocol for now.

  • Use standard MySQL protocol, application do not care about whether proxy or real MySQL.
  • Any MySQL command line and UI workbench supported in theoretically. MySQL Workbench are fully compatible right now.

Sharding-Proxy Architecture


Use sidecar to connect databases, best for Kubernetes or Mesos together.

Sharding-Sidecar Architecture

Quick Start


Add maven dependency

<!-- import sharding-jdbc core -->

Configure sharding rule

Sharding-JDBC support 4 types for sharding rule configuration, they are Java, YAML, Spring namespace and Spring boot starter. Developers can choose any one for best suitable situation.

Create DataSource

Use ShardingDataSourceFactory to create ShardingDataSource, which is a standard JDBC DataSource. Then developers can use it for raw JDBC, JPA, MyBatis or Other JDBC based ORM frameworks.

DataSource dataSource = ShardingDataSourceFactory.createDataSource(dataSourceMap, shardingRuleConfig);


Configure sharding rule

Edit ${sharding-proxy}\conf\sharding-config.yaml. Same format with Sharding-JDBC-Driver’s YAML configuration.

Start server

${sharding-proxy}\bin\start.sh ${port}