What’s the Best Way to Optimize API Requests from a Mobile App to EC2?

0
7
Asked By TechieDoodle123 On

I'm currently using Cloudflare to redirect my mobile app's API calls to an Amazon EC2 instance. I've set up DNS records with the proxy on and enabled SSL for my domain, all while using the free tier of Cloudflare with minimal traffic. However, I'm experiencing a delay of up to 1.5 seconds for the server to respond to my mobile app. When I bypass Cloudflare and hit EC2 directly, the latency disappears, but I'm unsure how to address the slowing caused by Cloudflare without compromising security. What strategies can I implement to improve the response time for requests from the frontend to the backend?

3 Answers

Answered By CodeWhiz84 On

To optimize your API requests, it's important to trace where the delays are occurring. Since you mentioned that the payload is small and latency is only an issue with Cloudflare, try hitting your EC2 instance directly and compare the response times. Utilize tools like logging or tracing to identify any bottlenecks between your app's API call and Cloudflare. Also, consider checking Cloudflare's caching and whether it's affecting the speed. You might find that cached responses are also slow, indicating an issue on their side.

AppNerd77 -

That makes sense! I had a similar experience where Cloudflare had a temporary issue affecting response times for cached content. Monitoring the headers might help you pinpoint if the delay is a cache hit issue.

Answered By CloudGuru95 On

If speed is your priority, consider using AWS services natively instead of going through Cloudflare. Deploy your EC2 instance in the region that is closest to your users to reduce latency.

FastTrackUser -

But isn't Cloudflare supposed to enhance performance? It feels odd that it would slow things down if both users and EC2 are in the same region.

Answered By NetNinja42 On

Have you checked if the cached responses from Cloudflare are also slow? If so, that could confirm the issue lies with Cloudflare, as there would be no direct call to your EC2 instance during cache hits. I’ve had similar issues before where a local Cloudflare cache server was overloaded, causing response delays. Sometimes, it resolves itself after a while.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.