Jieun 15 min read
Optimization

Why Did Requests from Korea Reach a U.S. Edge? Moving the Web and API Proxy to CloudFront

Investigating slow startup in the WITIM desktop app led me to Cloudflare response delays and U.S. edge locations. I verified an Incheon edge in a development PoC before moving the production web and API proxy to CloudFront.

On this page

Introduction

WITIM, the internal company groupware I worked on, had intermittently slow screen loading. It did not happen all the time, but in the comparison described here, the office Wi-Fi was slower than an LTE hotspot. The delay was particularly noticeable during initial loading after signing in to the desktop app.

Preparing the first screen involves a series of network requests, including authentication, session checks, and initial data queries. Slow responses can delay what appears on screen. In one recording on the office Wi-Fi, about 30.8 seconds elapsed between the loading screen appearing and the main text in the channel list becoming visible. (This was a severe case observed at the time, not a claim that every load took 30 seconds.)

I initially suspected the app’s initialization flow. There were opportunities to improve the code. But the development environment was fast while production was slow, despite sharing the same codebase. Investigating that difference revealed that the first response through Cloudflare arrived much later than a direct response from the NCP origin.

I needed another proxy that could retain WAF and DDoS protection without exposing the production server directly to users. I therefore verified CloudFront’s Incheon edge and API forwarding in development first, then replaced the production web and API proxy. The NCP production server, direct Cloudflare R2 file transfers, and Cloudflare DNS management remained in place.

I Initially Suspected the App’s Initialization Flow

I started with the initialization code after sign-in. The desktop app sent a bridge request to pass authentication information to the web session, while the web app waited for a session recheck and account cache connection. The dashboard also waited for user and workspace information and several initial queries before returning the screen.

There were improvements to consider, such as displaying the screen first and loading some data later. However, I had not measured how much each initialization task contributed to the total wait. Slow responses across multiple network requests could extend initial loading, but the presence of waits in the code did not establish them as the main cause.

Investigating desktop network traffic also had limitations. Requests sent through the Tauri HTTP plugin are handled by a Rust HTTP client, so they do not all appear in the WebView’s Network tab. A slow screen alone was not enough to identify a particular API or bridge call as the cause.

Development Was Fast, but Production Was Slow

The fact that only production was slow changed the direction of the investigation. The desktop app felt substantially different between the two environments, despite using the same codebase.

The request paths differed as follows:

Development: User → Vultr development server
Production: User → Cloudflare proxy → NCP production server

Cloudflare managed DNS for the development domain without proxying web or API traffic. The production domain had the Cloudflare proxy enabled.

The remote servers, deployments, and data also differed between development and production. The speed difference alone did not establish Cloudflare as the cause. I therefore measured the same URL on the same production server through Cloudflare and through a direct connection to the origin.

Cloudflare’s First Response Was Slow Even on Cache HITs

Using the same Mac and office network, I requested a production static JavaScript file. I alternated between requests through the existing Cloudflare proxy and requests directly to the NCP load balancer, measuring each path three times. Because of a certificate issue at the time, the diagnostic requests directly to the origin skipped certificate verification.

RequestTTFB through CloudflareTTFB directly from NCP origin
Same static JavaScript file1.726–2.765 s0.041–0.066 s
Unauthenticated session API1.425–4.946 s0.040–0.041 s

The JavaScript returned by Cloudflare was a cache HIT on all three requests, processed at LAX in Los Angeles, U.S. The unauthenticated session API was an uncached dynamic request.

Here, TTFB (Time to First Byte) measures the time from the start of a request until the first response byte arrives, including connection setup and TLS negotiation.

What caught my attention was that the first response was slow despite a cache HIT, and a request from Korea was being processed at the distant LAX edge. Since the response came from a cached file, file processing at the origin alone was unlikely to explain the delay. These observations led me to focus on Cloudflare’s processing location and the network path to it.

The Same App Loaded Differently on Office Wi-Fi and LTE

I compared the same desktop app version on office Wi-Fi and an iPhone LTE hotspot. Cloudflare’s LAX edge was observed on office Wi-Fi, and KIX in Osaka, Japan, on LTE.

Screen intervalOffice Wi-FiLTE hotspot
Loading screen → basic screenAbout 22.2 sAbout 2.2 s
Basic screen → main channel-list textAbout 8.6 sAbout 1.0 s
Loading screen → main channel-list textAbout 30.8 sAbout 3.2 s

These are approximate measurements from one recording on each connection. The same app displayed its content later on office Wi-Fi through LAX in the U.S., and sooner on LTE through KIX in Japan. Together, the slow cache HIT responses and the loading difference between connections convinced me to prioritize the Cloudflare edge reached from the office connection and its network path over the app’s initialization code.

Production had been using Cloudflare Free. I also briefly tried Cloudflare Pro to see whether changing plans would improve the route. Immediately after the upgrade, office Wi-Fi still reached LAX, and initial loading did not improve. I did not observe the expected routing improvement on the office connection at that time.

The following captures, taken two days after switching to Pro, also showed no Korean edge. With HTTPS requests pinned to the same Cloudflare IPv4 address, the /cdn-cgi/trace response reported colo=SJC (San Jose, U.S.) on office Wi-Fi and colo=NRT (Tokyo, Japan) on LTE.

Office Wi-Fi capture two days after switching to Pro, reporting colo=SJC in San Jose, U.S.
Office Wi-Fi capture two days after switching to Pro, reporting colo=SJC in San Jose, U.S.
LTE capture two days after switching to Pro, reporting colo=NRT in Tokyo, Japan
LTE capture two days after switching to Pro, reporting colo=NRT in Tokyo, Japan

I used the final colo response to identify the processing location rather than inferring it from intermediate traceroute hops alone. The * entries in the LTE capture indicate missing hop responses, so I did not treat that capture as a complete view of the route.

I Needed to Retain a Proxy Instead of Exposing the Origin Directly

Based on response times alone, disabling the Cloudflare proxy and connecting directly to NCP would have been straightforward. But I did not want users connecting directly to the production server. I needed a proxy in front of the web and API endpoints to provide WAF and DDoS protection.

A web application firewall (WAF) inspects and blocks malicious HTTP requests. DDoS protection handles large volumes of attack traffic. Simply removing the proxy would not preserve the protection previously provided at the Cloudflare entry point. I also needed to consider how caching static JavaScript and CSS reduces origin load and transfer volume.

The goal was to replace the slow request path while retaining the existing security and caching roles. CloudFront supported WAF and DDoS protection, static file caching, and an external origin on NCP. Before using it in production, though, I needed to verify that actual requests reached a Korean edge.

Only the web and API path changed in this migration.

Replacing only the web and API proxy with CloudFront while retaining the NCP origin, direct R2 transfers, Cloudflare DNS, and the separate WebSocket path
Replacing only the web and API proxy with CloudFront while retaining the NCP origin, direct R2 transfers, Cloudflare DNS, and the separate WebSocket path

Control APIs, such as issuing upload URLs, completing uploads, and registering messages, pass through CloudFront. File bytes for images and videos still travel directly between the client and R2 using presigned URLs. Some thumbnail and download APIs that serve file data through the application server use the web and API path.

Also, attaching WAF to CloudFront and blocking direct access to the NCP origin are separate concerns. I did not have evidence that all proxy-bypassing access to the origin had been blocked, so I treat the security coverage separately from the operational checks.

I Verified an Incheon Edge in a Development PoC Before Production

Before changing production, I directly verified an Incheon edge connection in a development proof of concept. Product documentation stating that CloudFront offered Korean edges was not enough. I needed to check where actual requests were processed and whether authentication and application APIs could be forwarded without caching.

First Pass: Verify Forwarding and the Incheon Edge with Caching Disabled

On November 11, 2026, I applied CloudFront Free to the development environment. The existing Vultr development server remained the origin; only the entry point changed to CloudFront.

In the first test, with all caching disabled, I sent ten requests each for four types of unauthenticated web and API requests. All 40 returned HTTP 200, and X-Amz-Cf-Pop: ICN57-P1 confirmed the Incheon edge.

The following is an actual Chrome DevTools capture of a video-attachment API request while signed in to the development environment. The response headers show X-Amz-Cf-Pop: ICN57-P1 and X-Cache: Miss from cloudfront. This API was excluded from shared caching, so a MISS was expected.

Development CloudFront response headers confirming Incheon POP ICN57-P1 and a cache MISS
Development CloudFront response headers confirming Incheon POP ICN57-P1 and a cache MISS

The actual development Network panel. Account information and workplace identifiers are masked; the ICN57-P1 and cache MISS headers are preserved.

I also measured control requests directly to the development origin around the same time. For the unauthenticated APIs, median TTFB through CloudFront was only about 4–8 ms longer. Since the development origin was on Vultr, I did not interpret this as the improvement to expect from production on NCP. This step established that uncached APIs could be forwarded successfully through the Incheon edge.

Second Pass: Verify Static Caching and Authentication

The next day, I added a policy to cache only public JavaScript and CSS. The results were:

Request typeDevelopment PoC result
Public JavaScript and CSS20/20 HIT
HTML and unauthenticated APIs30/30 MISS

Application APIs and authentication responses were excluded from shared caching. I then tested attaching a video in a signed-in browser and confirmed successful responses for the presign, complete, and messages requests through CloudFront. File bytes continued to use the existing direct R2 transfer path.

I proceeded with the production migration only after verifying the Incheon edge, API forwarding, static caching, and video attachments in development. HTTPS, authentication, and feature checks on the production NCP environment were performed separately.

After the PoC, I Replaced the Production Web and API Proxy

Replace the NCP Origin’s HTTPS Certificate First

After checking the development PoC results, I connected CloudFront to the production NCP origin. I prepared HTTPS before changing DNS. The existing NCP load balancer used a Cloudflare Origin CA certificate. CloudFront needed a publicly trusted certificate to validate the origin certificate through the normal public trust chain.

I installed a publicly trusted certificate on the NCP load balancer and verified TLS validation and HTTP responses through a direct origin connection. An AWS ACM certificate was used between users and CloudFront.

The following diagram shows which certificate is used on each HTTPS connection.

AWS ACM certificate on the user-to-CloudFront connection and an NCP public certificate on the CloudFront-to-origin connection
AWS ACM certificate on the user-to-CloudFront connection and an NCP public certificate on the CloudFront-to-origin connection

Separate Static File and API Cache Policies

In production, I configured CloudFront to cache only public build assets.

Request pathCache policyOrigin request policy
/_next/static/*Managed-CachingOptimizedManaged-HostHeaderOnly
Default path *Managed-CachingDisabledManaged-AllViewer

The static path allowed GET and HEAD, while the default path allowed the HTTP methods required by application APIs. The default path forwarded authentication headers, cookies, and query strings to the origin. This configuration kept login state and user-specific responses out of CloudFront’s shared cache.

Cloudflare continued to manage production DNS. I changed the web and API domains to point to CloudFront and set the Cloudflare proxy to DNS only, avoiding an additional Cloudflare proxy hop in the CloudFront request path.

Before changing DNS, I tested the CloudFront path in a browser while preserving the actual production domain’s Host and TLS name. I checked sign-in, sessions, chat, work, notes, message sending, video attachments, and PDF previews.

Verify the Incheon Edge Again After the Production Cutover

After changing production DNS on November 12, 2026, I checked responses using normal DNS resolution, without forced connection overrides.

RequestHTTP statusCloudFront POPCache status
Web HTML /200ICN57-P6MISS
Public API /api/version200ICN57-P6MISS
Unauthenticated session API200ICN57-P6MISS
Public static JavaScript200ICN57-P6HIT

All TLS checks also passed. The development PoC confirmed ICN57-P1, while the production cutover confirmed ICN57-P6. Both were evidence of Incheon edge processing at the time.

The main features were reported to work immediately after the cutover. That night, however, the certificate on the NCP origin was reverted to its previous value, and the service returned 502 Bad Gateway the following morning. I rolled back to the existing Cloudflare proxy to restore service first, then updated the certificate declaration in production Git and switched back to CloudFront. I wrote up that process separately in A CloudFront 502 on My Morning Commute: From Rollback to Root Cause Analysis.

How Did Actual Screen Loading Change?

Confirming the edge location and HTTP responses did not by itself show whether the user interface had become faster. I therefore compared before-and-after recordings of initial rendering after desktop sign-in and first visits to web pages.

Initial Rendering After Desktop Sign-In

In the severe pre-migration case recorded on office Wi-Fi, about 30.8 seconds elapsed from the loading screen to the main channel-list text appearing. This was not the duration of every sign-in. In a separate recording after the migration, the initial screen appeared much sooner.

Before: Cloudflare proxy

After: CloudFront proxy

These videos show the interval from the initial loading screen to visible content, not the entire time from clicking the sign-in button. They are single observations recorded at different times, with deployment and cache states that were not identical. I did not treat 30.8 seconds as the universal baseline or attribute the entire difference to the proxy change.

First Visits to Web Notes and Chat

On the web, I compared the first visit to each page after signing in. I read the recordings from navigation until the actual list or messages appeared.

ScreenBeforeAfter
Notes page list visibleAbout 1.2 sAbout 0.5 s
Chat messages visibleAbout 1.0 sAbout 0.4 s

These are approximate values observed once in each recording. A “first visit” means opening the page for the first time after signing in, not a cold-cache test with both browser and CDN caches cleared.

Notes page: before

Notes page: after

Chat: before

Chat: after

The HTTP response headers show that requests were processed at an Incheon edge. The screen recordings show that users waited less after the migration. These are different kinds of evidence. Since this was not a repeated experiment with fully controlled deployment state, caching, and server load, I did not present a statistical performance improvement percentage.

Conclusion

WITIM’s initial loading delay was intermittent and particularly severe on the office Wi-Fi at the time. The app had room for improvement, but development was fast while production was slow. Measuring separate request paths to the same production origin revealed slow Cloudflare responses and U.S. processing locations.

I chose to keep a proxy capable of WAF and DDoS protection and static caching rather than expose the origin directly. After verifying CloudFront’s Incheon edge and core request forwarding in a development PoC, I replaced only the production web and API proxy. NCP, R2, and Cloudflare DNS remained in place.

After the production cutover, I confirmed Incheon edge responses and shorter initial loading in the desktop and web recordings. The day after the cutover, an origin certificate problem forced one rollback before I switched back. Optimizing initialization inside the app and further validating origin protection policies remain separate tasks.

I did not immediately label the improvement candidates in the code as the main cause. Using the development–production difference as a clue and measuring request paths to the same production origin helped identify the web and API proxy segment that needed to change first.

Comments