Here's the thing: we have a website which has some i18n. Translations are maintained in DB and manually exported into JSON files which are consumed by our SPA one time on load.

Now I have the following problem to solve: I want to put those i18n JSON files to some CDN and when someone makes updates in database, I would like JSON files to be regenerated automatically and get those uploaded to CDN.

My current thinking is to make Trigger in DB (PostgreSQL) which will send NOTIFY on data change and some service which will listen for that. After this signal it will upload actual JSON to CDN,

Could anyone propose alternative approach?

  • Is there a service layer in front of your database, or are changes made directly in the database? – Samuel Aug 9 '17 at 21:03
  • What's wrong with the approach you proposed? – Robert Harvey Aug 9 '17 at 22:44
  • @RobertHarvey nothing, just want to know if someone had similar experience and could come up with alternatives. – Alexander Efimov Aug 10 '17 at 9:20
  • @Samuel Thanks, a good question. There is not for now, but there will be some UI/Service which will allow maintaining this. Indeed it could be an option to add one more step to UI/Service which will push data to CDN after save is successfully performed – Alexander Efimov Aug 10 '17 at 9:28

First of all, you need a way to serve the data over HTTP, e.g. a web server accessing your database. Then, you need to use the HTTP cache control headers to ensure that any proxied data is refreshed correctly. To start with, set Last-Modified correctly.

How often are your updates? Are they on a schedule? If they are totally random, use ETag. Otherwise, set Expires appropriately.

HTTP, used correctly, is awesome.

  • That's exactly what CDN is for here, but the question is not about how to serve files via http ;) – Alexander Efimov Aug 28 '17 at 17:31
  • @AlexanderEfimov Many CDNs will request your files over HTTP and use the returned Cache-Control headers to automatically update them as needed. You don't call the CDN, the CDN calls you. – Jack Oct 27 '17 at 22:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.