acra icon indicating copy to clipboard operation
acra copied to clipboard

[Query] acraserver in distributed environment behind load balancer

Open devendermishra opened this issue 1 year ago • 4 comments

Describe the bug I want to know if acra can be run in multiple servers/pods behind a load balancer to ensure better availability.

To Reproduce NA

Expected behavior NA

Acra configuration files NA

Environment (please complete the following information):

  • Acra version: [0.95.0]

  • Database server and its version: [MySQL 5.7, MySQL 8]

  • Installed components:

    • [x] AcraServer
  • Data-in-transit encryption between Acra and the client-side application:

    • [x] no transport encryption
  • Installation way:

    • [x] via Docker

Additional context In distributed environment, a node may go out of service unexpectedly. In order to ensure that acraserver works in such case to use multiple server behind load balancer. So, I want to know that if acraserver can work in such settings. Also, want to know what are recommendations to ensure better availability.

devendermishra avatar Jan 04 '24 04:01 devendermishra

Hi @devendermishra!

Yes, Acra server works well with horizontal scaling.

Acra has the whole sections in the docs regarding optimisation, which includes vertical and horizontal scaling: https://docs.cossacklabs.com/acra/configuring-maintaining/optimizations/

Acra also has the Balancer demo with AcraServer, PostgreSQL and HAProxy which demostrates different combination: balancer before the databases, or balancer before AcraServers https://github.com/cossacklabs/acra-balancer-demo

Hope it helps!

vixentael avatar Jan 04 '24 13:01 vixentael

Thanks @vixentael for prompt response. My question is related to MySQL 8 based clients. Currently, MySQL 8 client is not supported. However, acra needs to store the capability of connected client. How that will work in case of horizontal scaling?

devendermishra avatar Jan 11 '24 05:01 devendermishra

In the given demo, there is 1 acra server per DB. I want to know if we can have multiple acra server per DB (especially MySQL).

devendermishra avatar Jan 11 '24 05:01 devendermishra

My question is related to MySQL 8 based clients. Currently, MySQL 8 client is not supported.

However, acra needs to store the capability of connected client.

For now, Acra doesn't store it. Your balancers should park the same client's connection to the same AcraServer and AcraServer will use the same database. Database wire protocols are stateful and operate with client sessions. Every session has its own set of registered prepared statements, opened transactions, connection parameters, db variables, and so on. So, the same client's connection should be proxied to the same database that handle that connection. You can scale your infrastructure by X database instances and every instance should have own AcraServer instance.

In the given demo, there is 1 acra server per DB. I want to know if we can have multiple acra server per DB (especially MySQL).

Yes, you can. But it depends on how your apps will connect to the AcraServer/Database. Let's use next example. You have a service parallelized into 2 instances and it uses a pool of connections of size 2. How you will distribute connection between different AcraServers?

  • You can configure every instance to use different instances of AcraServer. First intance uses AcraServerA, the second uses AcraServerB. Or every odd app instance uses AcraServerA and other uses AcraServerB.
  • You can configure your apps to connect to the AcraServer by it's domain name and DNS record will have X IP addresses of AcraServer instances. If your db drivers in app support round-robin strategy - then it will be scaled. If they will use only the first IP - it will not be scaled. Depends on db driver on app side or you need to write your own logic. In such case, the same instance can have 2 connections routed to 2 different AcraServer instances.
  • You can use any TCP proxy (for example haproxy) that will route connections from the app to different AcraServers using round-robin or any other strategy - it will work. One connection will use own AcraServer instance until close. AcraServer will store the connection state until it closes. In this case, 2 different instances can have 2 connections routed by proxy to 2 different AcraServer instances.

Lagovas avatar Jan 11 '24 17:01 Lagovas