Skip to content

Commit

Permalink
fix(ddb): use two instances, select primary as read instance
Browse files Browse the repository at this point in the history
We previously went to one instance thinking that there was a problem
with stale reads. This turned out to be CloudFront caching api traffic.

With a single instance and no secondaries, mongoose tries forever to
reach the secondary, in vain.

This should be solved by using `readPreference=primary` in the conn
string, but to allow for longevity of the setup, we will bump ddb back
to 2 instances.

We will also specify a read preference of `primaryPreferred`, to
better assure some consistency
  • Loading branch information
LoneRifle committed Aug 20, 2024
1 parent e372584 commit d607586
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/formsg-on-cdk-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class FormsgOnCdkStack extends cdk.Stack {
// providing 750 machine hours free per month
// See https://aws.amazon.com/documentdb/free-trial/
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE3, ec2.InstanceSize.MEDIUM),
instances: 1,
instances: 2,
engineVersion: '4.0',
parameterGroup: new cdk.aws_docdb.ClusterParameterGroup(this, 'ddb-parameter-group', {
dbClusterParameterGroupName: 'disabled-tls-parameter2',
Expand All @@ -126,7 +126,7 @@ export class FormsgOnCdkStack extends cdk.Stack {
secretName: 'ddb-connstring',
removalPolicy: cdk.RemovalPolicy.DESTROY,
secretStringValue: cdk.SecretValue.unsafePlainText(
`mongodb://root:${ddbPassSecret.secretValue.unsafeUnwrap()}@${db.clusterEndpoint.socketAddress}/form?replicaSet=rs0&retryWrites=false`
`mongodb://root:${ddbPassSecret.secretValue.unsafeUnwrap()}@${db.clusterEndpoint.socketAddress}/form?replicaSet=rs0&readPreference=primaryPreferred&retryWrites=false`
),
})
)
Expand Down

0 comments on commit d607586

Please sign in to comment.