reym
Deployments

Blue / Green Deployments

What are blue / green deployments?

Using Freym you can deploy your application without any downtime or data loss. This is done by using a deployment strategy called blue / green deployments. This strategy is based on the idea of having two identical stages, one called "blue" and the other called "green". The idea is to have one stage (blue) that is currently running the application and another stage (green) that is being prepared for the next release. Once the green stage is ready, you can switch the traffic from the blue stage to the green stage.

How does a deployment of a real application look like?

Create and apply the GraphQL schema to Freym

Create and apply a deployment for the green stage as described in the cli documentation.

Build and deploy your backend services

If your build process does not rely on data in Freym, you can actually build your backend services while the GraphQL schema is appliyed Freym (step 1).

Deploy your backends to the green stage as soon as the deployment of the schema is activated (step 1).

Build and deploy your frontends

If your build process does not rely on data in Freym or in your backend services, you can actually build your frontend services while the GraphQL schema is appliyed Freym (step 1).

Deploy your frontends to the green stage as soon as the deployment of the schema is activated (step 1) and all used backends are deployed (step 2).

Shift traffic to the green stage

Once all services are deployed to the green stage, you can shift the traffic from the blue stage to the green stage.

This process is highly dependent on your infrastructure and the way you deploy your services.

Here are some examples:

Rollback

If you want to rollback the deployment, you can do this by switching back the traffic from the green stage to the blue stage.

After switching back the traffic you cann execute a rollback of the deployment as described in the cli documentation.

You can also rollback the deployment of your backend and frontend services.

Cleanup the blue stage

Once the traffic is shifted to the green stage, you can cleanup the blue stage:

  • Confirm the deployment of the green stage as described in the cli documentation.
  • Create, apply and confirm the deployment to the blue stage as described in the cli documentation.
  • You can shutdown the blue backend services and frontends to save resources.

The next deployment

The next deployment of your application will be done on the blue stage.

How does Freym handle data between the blue and green stage?

Imagine the following scenario:

You already deployed a CRUD type like this to blue and green:

type User {
	id: ID!
	name: String!
	email: String!
}

At this time, both blue and green use exactly the same underlying data structure. This means when data gets updated in blue, the changes are automatically reflected in green as well.

Now imagine you want to deploy a new version of the User type to green:

type User {
	id: ID!
	name: String!
	email: String!
	age: Int
}

This creates a scenario where the underlying data structure of the User type differs between blue and green.

Here's what happens with data synchronization:

  • If a user is created on blue (where the age field doesn't exist), the user will be added to green too. However, the age field will be null in green since it wasn't provided in the blue data.
  • If a user is created on green (where the age field exists), the user will be added to blue too. However, the age field will be omitted from the blue data since that field doesn't exist in blue's schema.

When gradually shifting traffic to a new version of your application, you need to ensure new fields have sensible defaults. This can be accomplished using the default directive in your GraphQL schema:a:

type User {
	id: ID!
	name: String!
	email: String!
	age: Int! @default(value: 0)
}

For more complex scenarios, you may need to implement custom data migration logic in your application based on your specific requirements.