SapphireDb logo SapphireDb

Server - Scaling/Multiple instance configuration

SapphireDb supports running in multiple instances. Each instance will synchronize with the other instances using different mechanisms.

Redis cache (recommended)

If you want to scale dynamically you don't know the instances in advance. You therefor need a kind of message broker that distributes changes to all application instances. SapphireDb provides a sync module that uses Redis to achieve this goal.

You need to install the NuGet package SapphireDb.RedisSync with the version of the SapphireDb package installed.
\f:(json:appsettings.json) "RedisSync": {\n \t"ConnectionString": "<Redis connection string>"\n\n \t// (optional) Only useful, if you want to use the same redis cache for multiple independent SapphireDb applications\n \t"Prefix": "<Custom channel prefix>"\n }, \f:(csharp:Startup.cs) // Add this to ConfigureServices-method\n RedisSyncConfiguration redisSyncConfiguration = new RedisSyncConfiguration(Configuration.GetSection("RedisSync"));\n\n services.AddSapphireDb(...)\n \t.AddContext<RealtimeContext>(cfg => ...)\n \t.AddRedisSync(redisSyncConfiguration);\n\n
You need to have a running Redis cache to use this sync method. You can easily start a redis cache using docker:
docker run -it --rm -p 6379:6379 redis:alpine
The connection string for this cache is,ssl=False
Also works with Azure Cache for Redis and is therefor pretty easy to setup.

Simple sync (Http sync)

If you only have a predefined (and small) number of instances and don't need dynamic scaling you can use this option. SapphireDb will sync changes through a http-interface and send them to all other known instances. You only need a seperate sync configuration for all instances.

You need to install the NuGet package SapphireDb.HttpSync with the version of the SapphireDb package installed.
\f:(json:appsettings.json) "HttpSync": {\n \t// A unique id of the current instance. Will be used as identifier.\n \t"Id": "nlb1"\n\n \t// Secret for current instance. Should be unique for every instance of the application. Has to be a SHA512 Hash\n \t"Secret": "77CF97E34BED553679748144E3676A95942F91EC470BBD7AD9887DC2F0BED0C53A91413F6E366AD25F037222EE4583775B8660A3E5BC72F41066E702A8989851", //= nlbSecret\n\n \t// Urls, ids and secrets of all other instances of the application\n \t"Entries": [\n \t\t{\n \t\t\t"Url": "http://localhost:5001",\n \t\t\t"Secret": "nlbSecret"\n \t\t\t"Id": "nlb2"\n \t\t},\n \t\t{\n \t\t\t"Url": "http://localhost:5002",\n \t\t\t"Secret": "nlbSecret"\n \t\t\t"Id": "nlb3"\n \t\t}\n \t]\n }, \f:(csharp:Startup.cs) // Add this to ConfigureServices-method\n HttpSyncConfiguration httpSyncConfiguration = new HttpSyncConfiguration(Configuration.GetSection("HttpSync"));\n\n services.AddSapphireDb(...)\n \t.AddContext<RealtimeContext>(cfg => ...)\n \t.AddHttpSync(httpSyncConfiguration);\n\n // Add this to Configure-method\n app.UseSapphireDb();\n app.UseSapphireHttpSync();

This website uses Google Analytics. If you want to disable it just unselect the option: