Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: patch-1

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 app
Octocat-spinner-32 conf
Octocat-spinner-32 project
Octocat-spinner-32 public
Octocat-spinner-32 .cache
Octocat-spinner-32 .gitignore
Octocat-spinner-32 ddl

Play 2.0 Database Sharding Example

This is a simple example application that demonstrates one way to shard data across two postgres databases using Play 2.0 and JDBC.

Running the application on Heroku

You can run this application on Heroku under your own account. Start by cloning the source code and creating a new Heroku app. From the cloned directory:

$ heroku create --stack cedar
$ git push heroku master

Add two databases to the application by executing the following command twice:

$ heroku addons:add heroku-postgresql:dev
----> Adding heroku-postgresql:dev to play20shardexample... done, v11 (free)
  Database has been created and is available
    ! WARNING: dev is in beta
    !          increased risk of data loss and downtime
    !          send feedback to

Create the schema in both databases using the heroku pg:psql command. For each database run:

$ heroku pg:psql db_color

Then run the DDL in the ddl file at the psql prompt. Replace db_color with the color of each of your databases.

Edit the application's configuration. In conf/application.conf you'll find:

# DB1

# DB2

Replace the colors with the two colors in the databases you added.

Now add the changes to git and push the app to Heroku:

$ git add .
$ git commit -m 'update database colors'
$ git push heroku master

See a live example

You can see a live example of the application at:

Something went wrong with that request. Please try again.