does anyone have any opinions on reducing latency ...
# random
s
does anyone have any opinions on reducing latency on API Gateway requests coming in from users around the world? I’m debating whether I should put my HTTP API behind a CloudFront distribution, or just switch to REST API.
t
How does switching to a REST API change things?
s
REST API is edge-optimized, HTTP API is not
basically REST API automatically has CloudFront behind the scenes
since SST’s
Api
construct is HTTP API, I think I might just put a CF dist in front of it
j
Yeah I haven't seen a comparison of the two. I just remember the rest API’s internal CF isn't as configurable
s
a
Just use HTTP API.
s
yeah, I am. but now I’m getting weird 502 errors from CloudFront now that I’m using that URL for the API, and it’s using the HTTP API as its origin
s
Does cloudfront have an origin identity granted to the http API?
s
no, I thought that’s only needed if you’re restricting access
s
You could be right, I am just reading the docs. I think it's used to grant cloudfront access to restricted S3 buckets
s
yeah that sounds right. this is a CloudFront distribution using an HTTP API as the origin. it should be pretty straightforward
but now I’m getting 403 errors. which also make no sense
s
That's some weird stuff right there. Does you API have any Auth?
s
on some routes, yeah. but I’m testing on a fully public route
AWS support is looking into it. hopefully they come back with something soon
s
Yeah, that would be good 👍 I was reading https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-cloudfront-distribution/ (you've probably seen already). It does seem there are weird things about stages and some debugs in this, but it doesn't seem to relate exactly to your issue. Tbh I'm guessing you've tried a bunch of things
t
I'm curious what latency improvements you see @Sam Hulick
I've found APIG to be pretty slow latency wise
So would be nice if throwing it behind CF made a meaningful difference
s
yeah, I feel like I’ve tried every combination possible! ugh. thanks for looking, though 🙂 And yeah, I’ll do some latency tests from a VPN in Australia once I have this set up properly
s
Yeah, I think latency wise I found edge optimization slower if you are in the region. I have been wondering if you'll see any speed gains latency wise. I thought the benefits were being on aws backbone network, which supports high quality bandwidth. Versus just getting normal DNS lookup and going whatever route your ISP takes you through
Really interested to find out though
j
If you're handling >1M requests a day you're probably going to be better off with Application Load Balancer instead of API Gateway
s
I think it’s more a question of requests per second where you need to consider using ALB
we’re nowhere near 10,000 req/sec
j
Where is the latency actually occurring though? CloudFront can give you a cache policy to work with but are we talking about reads or writes and do you need cache invalidation or TTL etc. There are a few considerations to first make. You can roll your own Redis cache to boost database read performance too. So many options, depends on so much.
s
that was easy to determine. it’s geographical location. API calls from where I am is super fast. but when I hopped on a VPN server in Australia, it was slower. putting the API Gateway behind CloudFront will speed things up, because their requests will hit an edge network near them and then it’ll move faster once it’s inside AWS’s general network
j
Maybe can consider read replicas/global tables and multi-region deployments. But yes CloudFront is the first point of call.
t
This was one of the last things that pushed me into using GQL, GraphCDN basically solves this problem for api data