Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (31 sloc) 1.69 KB

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: