MovR

On this page Carat arrow pointing down
Warning:
As of May 12, 2021, CockroachDB v19.2 is no longer supported. For more details, refer to the Release Support Policy.

MovR is a fictional vehicle-sharing company created to demonstrate CockroachDB's features.

Overview

The MovR example consists of the following:

  • The movr dataset, which contains rows of data that populate tables in the movr database. The movr dataset is built into cockroach demo and cockroach workload.
  • The MovR application, a fully-functional vehicle-sharing application, written in Python. All of MovR application source code is open-source, and available on the movr GitHub repository.

The movr database

The six tables in the movr database store user, vehicle, and ride data for MovR:

Table Description
users People registered for the service.
vehicles The pool of vehicles available for the service.
rides When and where users have rented a vehicle.
promo_codes Promotional codes for users.
user_promo_codes Promotional codes in use by users.
vehicle_location_histories Vehicle location history.

Geo-partitioning schema

Generating schemas and data for MovR

You can use the cockroach demo and cockroach workload commands to load the movr database and dataset into a CockroachDB cluster.

cockroach demo opens a SQL shell to a temporary, in-memory cluster. To open a SQL shell to a demo cluster with the movr database preloaded and set as the current database, use the following command:

icon/buttons/copy
$ cockroach demo movr

cockroach workload loads sample datasets and workloads into running clusters. To load the movr database and some sample data into a running cluster, do the following:

  1. Start a secure or insecure local cluster.
  2. Use cockroach workload to load the movr dataset:

    icon/buttons/copy
    $ cockroach workload init movr 'postgresql://root@localhost:26257?sslcert=certs%2Fclient.root.crt&sslkey=certs%2Fclient.root.key&sslmode=verify-full&sslrootcert=certs%2Fca.crt'
    
    icon/buttons/copy
    $ cockroach workload init movr 'postgresql://root@localhost:26257?sslmode=disable'
    
  3. Use cockroach sql to open an interactive SQL shell and set movr as the current database:

    icon/buttons/copy
    $ cockroach sql --certs-dir=certs --host=localhost:26257
    
    icon/buttons/copy
    > USE movr;
    
    icon/buttons/copy
    $ cockroach sql --insecure --host=localhost:26257
    
    icon/buttons/copy
    > USE movr;
    

How the MovR application works

The workflow for MovR is as follows (with approximations of the corresponding SQL for each step):

  1. A user loads the app and sees the 25 closest vehicles:

    > SELECT id, city, status, ... FROM vehicles WHERE city = <user location>
    
  2. The user signs up for the service:

    > INSERT INTO users (id, name, address, ...) VALUES ...
    
  3. In some cases, the user adds their own vehicle to share:

    > INSERT INTO vehicles (id, city, type, ...) VALUES ...
    
  4. More often, the user reserves a vehicle and starts a ride, applying a promo code, if available and valid:

    > SELECT code FROM user_promo_codes WHERE user_id = ...
    
    > UPDATE vehicles SET status = 'in_use' WHERE ...
    
    > INSERT INTO rides (id, city, start_addr, ...) VALUES ...
    
  5. During the ride, MovR tracks the location of the vehicle:

    > INSERT INTO vehicle_location_histories (city, ride_id, timestamp, lat, long) VALUES ...
    
  6. The user ends the ride and releases the vehicle:

    > UPDATE vehicles SET status = 'available' WHERE ...
    
    > UPDATE rides SET end_address = <value> ...
    

Extended examples

For a tutorial on running MovR against a multi-region cluster, using two important multi-region data topologies to get very low latency reads and writes, see Low Latency, Multi-Region Deployment.

For a tutorial about performance tuning in CockroachDB, see Performance Tuning.

For a tutorial on developing and deploying a multi-region web application for MovR, see Develop and Deploy a Multi-Region Web Application.

See also


Yes No
On this page

Yes No