guardian / dynamo-db-switches

Dynamo DB feature switches
Other
2 stars 1 forks source link
production

Dynamo DB Feature Switches

dynamo-db-switches Scala version support

Feature switches in Dynamo DB.

Usage

Schema

Create a DynamoDB table called 'featureSwitches' with the following schema:

+-------------------+---------------+
| Hash key (String) | Number        |
+-------------------+---------------+
| name              | enabled       |
+-------------------+---------------+

Set enabled to 1 to enable the feature switch, 0 to disable it.

Switch instantiation

Define your switches in an object

object ApplicationSwitches extends Switches {
  val dynamoDbClient = // define your dynamo DB client here

  val mySwitch = Switch("nameOfSwitch", default = false)

  // make sure you put all switches in here or they won't update
  val all = List(mySwitch)
}

Updates

Use a scheduler to update the switches from Dynamo DB once per minute

Akka.scheduler.schedule(0.seconds, 1.minute) { ApplicationSwitches.update() }

Testing switches

Use as follows:

if (ApplicationSwitches.mySwitch.enabled) {
  // do something
}

Releasing builds

Releases are published to Sonatype OSS and synced to Maven Central. This is carried out automatically by the release GHA workflow whenever a PR is merged to main.

Copyright

Copyright 2013 Guardian Media Group. Licensed under Apache 2.0. (See LICENSE.)