Apache Cassandra 1.0 Documentation

Running the Portfolio Demo Sample Application

This document corresponds to an earlier product version. Make sure you are using the version that corresponds to your version.

Latest Cassandra documentation | Earlier Cassandra documentation

Your DataStax Community (DSC) installation can run the Portfolio Demo Sample Application. This demo showcases using Apache Cassandra in a real-time web application developed in Java and using the Cassandra Query Language (CQL) JDBC driver.

The demo application is located in:

  • Binary Tarball Installs: <install_location>/demos/portfolio_manager
  • RHEL or Debian Packaged Installs: /usr/share/dse-demos/portfolio_manager

About the Portfolio Demo Use Case

The Portfolio demo is a financial application where users can actively create and manage a portfolio of stocks. Each portfolio contains a list of stocks, the number of shares purchased, and the price at which the shares were purchased. An overall value is maintained for each stock portfolio as well as the percentage of gain or loss compared to the original stock purchase prices for a portfolio.

The demo has a pricer utility that simulates an active feed of live stock market data. For each stock ticker symbol, the application tracks the current stock price and the historical market data (end-of-day price) for each stock for 100 days.

Running the Demo Web Application


  1. You might need to configure the demo application to point to the correct Cassandra installation location. For example, if DataStax Community Edition is installed in a directory called datastax in your home directory:

    $ sed -i -e "s,/usr/share/cassandra,~/datastax,"
If you copy the above text, be sure to delete any extra spaces.
  1. Go to the Portfolio Manager demo directory.

    Binary Installs: $ cd <install_location>/demos/portfolio_manager

    Packaged Installs: $ cd /usr/share/dse-demos/portfolio_manager


    You must run the pricer utility from a directory where you have write permissions (such as your home directory), or else run it as root or using sudo.

  2. Run the pricer utility to generate stock data for the application. To see the available options:

    $ bin/pricer --help
  3. To generate 100 days worth of historical data:

    If running on a single node cluster on localhost:

    bin/pricer -o INSERT_PRICES
    bin/pricer -o UPDATE_PORTFOLIOS
    bin/pricer -o INSERT_HISTORICAL_PRICES -n 100
  1. Start the web service:

    $ cd <install_location>/demos/portfolio_manager/website
    $ java -jar start.jar &
  2. Open a browser and go to:

    • http://localhost:8983/portfolio (if running on the local machine)
    • http://<webhost_ip>:8983/portfolio (if running remotely - specify the correct IP address of the remote server).

This open` the Portfolio Manager demo web application home page.


Exploring the Sample Data Model

The sample data for the demo application is contained in a Cassandra keyspace called PortfolioDemo.

In that keyspace are four column families:

  • Portfolio - One row per portfolio where the column names are the stock ticker symbols and the column values are the current stock price.
  • StockHist - One row per stock ticker symbol with (time-ordered) dates for the column names and column values are the end-of-day price for a particular day.
  • Stocks - One row per stock ticker symbol with a static column name price and the column value is the current stock value.
  • HistLoss - One row per stock ticker symbol where the column name is the worst date in the stock's history in the form of YYYY-MM-DD and the column value is the loss dollar amount.

Viewing the Schema Definitions in Cassandra-CLI

The cassandra-cli program is a command-line interface for Cassandra, which you can use to explore the PortfolioDemo keyspace and data model.

  1. Start cassandra-cli and specify a Cassandra node to connect to. For example:
$ cd <install_location>
$ bin/cassandra-cli -h localhost
  1. Specify the keyspace you want to connect to:
[default@unknown] USE PortfolioDemo;
  1. To see the keyspace and column family schema definitions:
[default@unknown] SHOW SCHEMA;
  1. To select a row from the Stocks column family (by specifying the row key value of a stock ticker symbol):
[default@unknown] GET Stocks[GCO];
  1. To exit cassandra-cli:
[default@unknown] exit;