Execution of long running transactions

I have an application which does long running transactions:

  1. Start transaction
  2. Select from database
  3. Go to service 1
  4. Update in database
  5. Go to service 2
  6. Update in database
  7. End transaction.

It is matter to keep this process atomic: if something happened transaction should be rolled back. Services may be slow. They can respond for second or more. As you see most time is waiting. This is not a problem on application level. I use non-blocking architecture, and maintain the processes without any cost. The only bottleneck is database (PostgreSQL) which able to maintain limited amount of connections. PG protocol doesn’t support multiplexing, so my parallelism is limited by connection pool.

As I see, CockroachDB supports serializable transactions and have non-blocking architecture too. So I have few questions:

  1. Will CockroachDB cluster not suffer if I start a lot of queries described above? As I understand the answer is “not”, because of non-blocking nature of CockroachDB.
  2. Does it have a protocol with multiplexing support? It is nice to have one because maintaining thousands TCP-sockets is expensive for OS.

Cockroach implements the postgres wire protocol, so it too does not have any means for multiplexing. Fortunately, cockroach can handle many more connections than postgres.

Cockroach connections, especially when left idle, are much, much cheaper than in postgres. While maintaining lots of TCP sockets is somewhat expensive, it’s not nearly as expensive as maintaining that number of processes (which is what postgres does: one process per connection). Thousands of connections while most of them are idle should not at all be a problem in cockroach.

1 Like