Suyog Acharya
Case study · Enrollment Center · Frontend owned by me

Making a 9-step insurance sign-up feel instant

I owned the frontend of a new enrollment platform that replaced the old sign-up flow. The server decides which steps each person sees, the next step loads while they are still typing, and Back never waits. Pages now load about twice as fast.

Role
Owned the frontend end to end: requirements, features, performance
Stack
React 18, TypeScript, Vite, Redux Toolkit, RTK Query, React Hook Form
Span
366 commits, Feb 2025 to Mar 2026
Result
Pages load about 2x faster in production

In short: signing up for an insurance plan means filling in up to nine screens: your details, contact, employer, beneficiary, health questions, family members, payment, an agreement to sign, and a final review. Every screen used to make you wait while it loaded.

I owned the frontend of the platform that replaced it. Each screen now starts loading while you are still on the one before, so pressing Next usually shows it straight away. Going Back shows what you typed without asking the server again. Prices are always fetched fresh, so nobody sees an old price. In production, pages load about twice as fast.

The problem

The legacy enrollment flow was one long sequence of screens. Every Next meant a full wait: send the answers, then ask the server what the next screen should contain, then draw it. Going Back did the same work again.

It was also rigid. Not every plan needs every screen. An individual plan has no employer. A member-only plan has no family members. A plan billed to the employer has no payment screen. Hard-coding those cases in the browser would mean two places that must agree on every plan.

I was given the frontend to own: gather the requirements, design how it works, build every screen, and make it fast. The new platform shipped next to the old one, with a banner that lets anyone switch back to the classic form while teams move over.

Decision 1: the server decides which steps exist

Problem. Which screens a person needs depends on their plan, their coverage level and how the plan is billed. That knowledge lives in the backend.

Decision. The backend sends a list of steps. Each step has a name, a required flag, an order and a status. The frontend keeps only the required steps, sorts them, and looks each name up in one map from step name to screen. It has no plan logic of its own.

Why. One source of truth. A new plan type changes the step list on the server, and the frontend follows without a release. Each screen then asks for its own field list too: which fields are required, which are read-only, the dropdown options, and any values already on file.

Try it. Change the plan below and watch the step list the server would send.

Made-up plan Coverage level
What the server sends

            
Filter to required steps, sort by order, map each name to a screen. The simulator below uses the steps you pick here.
For engineers: the mapping
const componentMap = {
  primary_info: PersonalInfo,   contact_info: ContactInfo,
  employer_info: EmployerInfo,  beneficiary_info: BeneficiaryInfo,
  primary_health_info: HealthQuestion,
  dependent_info: DependentInfo, billing_info: BillingInfo,
  agreement_info: AgreementSign, review_info: Review,
};

const steps = tabInfo
  .filter(t => t.required)
  .sort((a, b) => a.order - b.order);

The side panel reads the same list. Each step shows Completed, In progress or Waiting, and completed steps are clickable so people can jump back and edit.

Decision 2: load the next step while the person is still typing

Problem. People spend tens of seconds on each screen. The network sits idle the whole time, then everything happens at once when they press Next.

Decision. I wrote a small hook, usePrefetchNextTab. It finds the step that is in progress, works out the next required step, and asks for that step's data in the background. Some steps need a second piece of data, so it fetches that too: the cart before the beneficiary and family screens, the payment types before billing, and the agreement text before the signature screen.

Why it works with no config. The hook turns the step name into the query name by a fixed rule. dependent_info becomes getDependentTabInfo, and primary_health_info becomes getPrimaryHealthTabInfo. A new step that follows the naming rule gets prefetching for free.

Step through a sign-up below. Switch between the two modes and press Next. The timings are illustrative, picked to be realistic, and the same in both modes.

Mode

    Personal details

    Loading this step…
    Waited 0 ms
    send answersfetch after the clickfetched earlier, in the backgroundserved from cache, 0 ms

    With prefetch on, the only wait left on most steps is saving the current answers. The screen's own data is already in memory.

    Decision 3: a cache rule for every step

    Problem. Caching makes things fast, and caching prices is dangerous. A family adds a child and the premium changes. If the payment screen shows a cached total, the person agrees to the wrong number.

    Decision. I set how long each step's data is kept after you leave it, one rule per step:

    • Stable steps keep their data for 5 minutes. Personal details, contact, employer, beneficiary and health questions do not change unless the person changes them.
    • Steps that carry money keep nothing. Family members, billing and the cart are dropped as soon as no screen is using them, and fetched fresh the next time one needs them.
    • Saving one step clears only that step. Each enrollment's data is tagged by step. Saving family members marks only the family step as out of date, so the rest of the cache survives.

    The table below follows the simulator above. Move through the steps and watch entries arrive, wait, expire or disappear. The countdowns run in real time.

    On step: Personal details
    QueryStateKept after leavingWhy
    A 0-second rule means the data is removed as soon as no screen uses it. Payment types and agreement text use the library default of 60 seconds.
    A trade-off I chose on purpose

    The two rules meet at the money steps. Prefetching the family or billing step does start the request early, but with a 0-second rule the answer is thrown away as soon as it lands, unless the screen is already open. So those steps always pay for a fresh request. I kept it that way: a slightly slower billing screen is better than a stale price. The prefetch still pays off for those steps through their side data, like payment types and agreement text, which are kept.

    For engineers: the endpoint config
    getContactTabInfo: builder.query({
      query: (id) => ({ url: CONTACT_FIELDS, params: { enrollment_id: id } }),
      providesTags: (_r, _e, id) => [{ type: 'ContactInfo', id }],
      keepUnusedDataFor: 300,          // stable: keep 5 minutes
    }),
    getBillingTabInfo: builder.query({
      query: (id) => ({ url: BILLING_FIELDS, params: { enrollment_id: id } }),
      keepUnusedDataFor: 0,            // money: never reuse
    }),
    submitDependentInfo: builder.mutation({
      query: (body) => ({ url: SUBMIT_DEPENDENTS, method: 'POST', body }),
      invalidatesTags: (_r, _e, body) => [{ type: 'DependentInfo', id: body.enrollment_id }],
    }),

    The app has two RTK Query APIs, one for sign-in and verification and one for the enrollment itself, each with its own cache and middleware.

    Decision 4: Back costs nothing

    Problem. After someone saves a step, the cached copy of that step still holds the values from before they typed. Going Back would show old answers, or force a reload to get the new ones.

    Decision. When a step is submitted, I write the submitted values straight into the cached copy of that step's fields. The cache now matches what the person typed, so Back draws the screen from memory with zero requests. This runs for personal details, contact, employer and health questions.

    What it does not do. The patch is applied when the save starts and is not undone if the save fails. The failed save shows its error on the same screen, so the person never leaves with a wrong value. Adding a proper undo is on my list below.

    For engineers: patching the cache
    onQueryStarted(formData, { dispatch }) {
      dispatch(enrollmentApi.util.updateQueryData(
        'getPrimaryTabInfo', formData.enrollment_id,
        (draft) => {
          draft.data.result.forEach((field) => {
            if (field.field_name in formData) field.value = formData[field.field_name];
          });
        }
      ));
    }

    Surviving a refresh

    Problem. A sign-up takes a while. People refresh, lose signal, or come back later. Starting again from step one loses them.

    Decision. Two pieces of app state are saved to the browser with redux-persist. The auth slice holds the enrollment id, the step list, the step count, the theme and feature flags. The cart slice holds the coverage level, whether the person is an existing member, and how many family members they have. A refresh puts them back on the same step with the same side panel.

    A third slice, save and continue, keeps a live copy of the current screen's answers using React Hook Form's watch. The "save and continue later" action sends that copy to the server, so a half-finished screen is not lost.

    Errors land on the exact field

    Problem. Some checks can only happen on the server: is this zip code real, does this bank routing number exist, is this family member valid for this plan, is this phone number really yours. A generic "something went wrong" banner tells the person nothing.

    Decision. Every field has its own rules in React Hook Form, plus custom validators for phone numbers, zip codes and email. For server checks, I map each 400 or 422 error back onto the field it belongs to, including fields deep inside a health question. The zip lookup fills in and locks the state, and the routing number lookup finds the bank.

    Server reply (made up)
    422 {
      "errors": {
        "condition_questions.2.conditions.0.date":
          ["Date cannot be in the future."]
      }
    }
    What the person sees
    Q3. Have you been treated for a heart condition?
    Yes
    Diagnosis date: 03/14/2031Date cannot be in the future.
    The error key is a path. Question 3, first condition, diagnosis date. The message appears under that one input.

    Rules the form enforces

    • Family members follow the coverage level. At most one spouse, up to nine dependents, and only the relationships the tier allows. A member + children plan cannot add a spouse.
    • Health questions branch. Answering Yes reveals the follow-up fields. Switching to No hides them and clears their values, so stale answers are never sent.
    • Each family member and beneficiary is checked on the server as it is added, before the whole step is submitted.
    • Phone numbers are verified with a one-time code sent and checked through the API.

    Signing every request

    Problem. The API should be able to tell if a request was changed on the way, or if an old request is being replayed.

    Decision. One wrapper around every API call signs it. It builds a string from the method in capitals, the full URL with its query string, and the current Unix time, then computes an HMAC-SHA256 of it. It sends the signature and timestamp in headers. The server rebuilds the same string, compares the signatures in constant time, and rejects any request whose timestamp is more than 180 seconds away from its own clock.

    What it gives. Request integrity and replay protection. Change one character of the URL and the signature no longer matches. Capture a request and send it again ten minutes later and it is refused. Who the person is still comes from the verification step they start with. A 401 from any call sends the person back to the start.

    Try it. This demo signs in your browser with a made-up key.

    1 · String to sign
    2 · Headers sent
    3 · Server check
      The key and hostname are made up. In the real app the signing happens in the shared base query, so no screen can forget it.

      Finishing cleanly

      The agreement step lets people sign three ways: draw with a finger or mouse, type their name, or upload an image of their signature. The review step submits everything and the server returns the new policy id.

      After that, a success guard takes over. Pressing Back can no longer reopen a finished enrollment, and the saved state is cleared, so the browser holds nothing from the finished sign-up.

      Results

      ~2xfaster page loads in production after the prefetch and cache work
      0requests to go Back to a saved stable step
      0 sthat a price stays cached once its screen closes

      The new platform replaced the legacy enrollment flow. The frontend has no plan rules of its own, so new plan types arrive from the server. Most Next clicks only wait for the save, Back is instant, and prices are always fresh. Every request is signed in one place.

      What I would do next

      • Await the save in the cache patch and undo it if the save fails, so the cache can never hold a value the server rejected.
      • Keep money-step prefetches alive for a few seconds, long enough for the screen to pick them up, while still never reusing them later.