title: Multi Region Architecture on AWS for SNS notifications
body: <p>We are trying out multi-region architecture for our application. Which is used by multiple clients.</p>
  
  <p>We are using aws to replicate databases (s3 and dynamodb), and it solves data availability issues.</p>
  
  <p>We use SNS to notify our clients whenever there is any data change, but I could not find any good pattern for message replication cross region.</p>
  
  <p>Here are few consideration/requirements we will have to keep in mind</p>
  
  <ol>
  <li><p>Clients should be able to get all the notifications even if they are in only one region.</p></li>
  <li><p>Application should continue to work even if one region goes down. And if possible message can be replayed when region comes up.</p></li>
  </ol>
  
  <p>Here are few approaches with pros and cons that are coming to our mind.</p>
  
  <ol>
  <li><p>EC2 server writes to both the regions </p>
  
  <p>Pros.</p>
  
  <p>a. Requirement 1 is easily satisfied.</p>
  
  <p>Cons.</p>
  
  <p>a. Not sure if this is feasible, since no doc suggests to do so.</p>
  
  <p>b. won't be able to replay messages if one region goes down.</p>
  
  <p>c. latency delays in writing to both the regions.</p></li>
  <li><p>Having a lambda function to write to both the regions. Since lambda functions can subscribe to cross region sqs and sns. We can have a lambda function in both the regions listening to another region's sns/sqs and then writing to its own region's sns.</p>
  
  <p>Pros: </p>
  
  <p>a. Requirement 1 is solved.</p>
  
  <p>b. <del>Requirement 2 is solved if we use sqs instead of sns, where message will be kept in queue for some time if the region is down and messages will be replayed whenever region comes up.</del> cross region sqs subscription is not possible and lambda function has to subscribe to sns.</p>
  
  <p>Cons: </p>
  
  <p>a. Cross region permissions means hardcoding in the cloudformation, not sure if cloudformation supports import from another region.</p>
  
  <p>b. Cost of lambda function. (although it will be minimal)</p></li>
  <li><p>Instead of writing to sns, we write to dynamodb and use dynamodb global table and streams to send notification in both the regions.</p>
  
  <p>Pros.</p>
  
  <p>a. Requirement 1 is solved.</p>
  
  <p>b. Requirement 2 is solved since dynamodb replication will take care of replicating message.</p>
  
  <p>Cons.</p>
  
  <p>a. Costly solution.</p></li>
  </ol>
  
  <p>Can you please suggest if I am missing anything or some other pattern is there which we should consider?</p>
  
  <p>looking at above possible approaches, I am inclined towards approach 2, </p>