Skip to content

citusdata/citus-example-microservices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Citus Example: Microservices

Three microservices used to demonstrte setting up Citus as scalable storage backend for microservices.

Citus setup

    SET citus.enable_schema_based_sharding TO ON;

    CREATE SCHEMA AUTHORIZATION user_service;
    CREATE SCHEMA AUTHORIZATION time_service;
    CREATE SCHEMA AUTHORIZATION ping_service;

Execute the corresponding SQL file as every service.

psql -U user_service -f user_service/user.sql
psql -U time_service -f time_service/time.sql
psql -U ping_service -f ping_service/ping.sql

Connection configuration

Modify the db_config variable for every service in their app.py.

db_config = {
    'host': 'localhost',
    'database': 'citus',
    'user': 'time_service',
    'port': 9700
}

Running the apps

Change into every app directory and run them in their own python env.

cd user
pipenv install
pipenv shell
python app.py

Repeat the above for time and ping service.

Execute some commands against the API

    # Create 10 users
    curl -X POST -H "Content-Type: application/json" -d '[
      {"name": "John Doe", "email": "[email protected]"},
      {"name": "Jane Smith", "email": "[email protected]"},
      {"name": "Mike Johnson", "email": "[email protected]"},
      {"name": "Emily Davis", "email": "[email protected]"},
      {"name": "David Wilson", "email": "[email protected]"},
      {"name": "Sarah Thompson", "email": "[email protected]"},
      {"name": "Alex Miller", "email": "[email protected]"},
      {"name": "Olivia Anderson", "email": "[email protected]"},
      {"name": "Daniel Martin", "email": "[email protected]"},
      {"name": "Sophia White", "email": "[email protected]"}
    ]' http://localhost:5000/users

    # List users
    curl http://localhost:5000/users

    # Get current time
    curl http://localhost:5001/current_time

    # Ping example.com
    curl -X POST -H "Content-Type: application/json" -d '{"host": "example.com"}' http://localhost:5002/ping

LICENSE

Copyright (c) 2023, Microsoft

Licensed under the MIT license - feel free to incorporate the code in your own projects!

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages