Search code examples
postgresqlamazon-web-servicesamazon-s3amazon-cloudfront

What's the point of CDN if my server need to manage payment authentications?


I'm developing a project which has restricted content to periodically paymetns (subscriptions) and single payment methods.

Now, I need to distribute the content globally, however, due to everybody has to pass through my main back-end to check payment verifications to give and allow an presigned URL, the point of CDN lose a bit the sense in my head.

I let an example:

  1. A user located in Chicago (North America) wants to see a restricted image, so contact with my main back-end server located in Paris (Europe).
  2. The back-end server checks the credentials, and if the user paid for the content, it generates and return a redirect to the given presigned URL.
  3. The user recibes the redirect and now has to wait, again, now for AWS S3 servers to return the restricted image.

If in this last step I could use CloudFront to "improve" the image redirect, it stills giving a long time to complete the cycle, because my verification process is in Europe.

Are there some way, to check if the user paid in North America? I know about replication (meaning PostgresSQL replicas and a second back-end server), but, if uploads process require a master database, at somepoint, the request will need to go to Europe to be fullfilled.

Does need my app to check where the user is located to access to the closest back-end server, which can only be functional on reading process? That means another server in North America.

Am a bit confused, so, all point of view are welcomed.


Solution

  • Your question title and content can be re-worked to be more focused

    As you said yourself, at point number 3. A CDN does exactly its nominal use-case, saving your user from having to fetch the image from a data center far away ( putting the object or static content closer to the user )

    There are different techniques to further reduce the user's delay by putting the worker/application code closer to the user and putting your database close to where your code is executed. A CDN is not one of the ways to implement these techniques