Code Monkey home page Code Monkey logo

pgshardnet's Introduction

pgshardnet

C# library for sharding PostgreSQL database

History

We're migrating our database to PostgreSQL. We needed to split our data horizontally on several Microsoft Azure VM instances to get required amout of resources that allowe us to achieve good performance. After some test I've decided to publish this library on GitHub as it may be usefull base for many other C# applications that use PostgreSQL. implementations.

Concept

  1. Splits data equally on many PostgreSQL servers using modulo on bigint key.
  2. Some tables can be sharded and some may be replicated on every server for optimal querying.
  3. It is designed for projects where data structure changes hardly ever. Maintaining changes on many, many shards may be painfull.

Physical and logical shards

There is concept of Logical shard and Physical Shard. Physical shard is just PostgreSQL instance running on dedicated server. Logical Shard is scheme on Physical Shard that contains tables. First project that uses pgshardnet is running on 6 Azure VMs (6 physical shards). On every VM there are 3 schemes created, each on separated tablespace on separated drive. So it gives finally 18 logical shards. Every scheme can be quite easly moved to another physical server so I can scale this project up to three times before I would need to incremet modulo and recalculate data split.

PostgreSQL ODBC vs Npgsql

At the beggining I was using Npgsql. I had disconnection issues on Microsoft Azure during long queries I coudn't avoid. I switched to ODBC and set Windows Convifuration tcp keep alive options in registry for longer values. Works like a harm. The only problem is that you have to distribute PgODBC with your project.

2DO

  1. Write universal test. I was using my own testing environment, but it cannot be published as is project specific.
  2. Maybe add option to select using ODBC or Npgsql, as it doesn't change any logic but rather only connection object.

pgshardnet's People

Contributors

adekmm avatar

Watchers

 avatar  avatar

Forkers

fdsmax

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.