learning-it by example

#314 Forward deployed engineer interviews 5.9 min

One Codebase, Many Customers: Config Without Leaks

Customer B got customer A's webhook address and secret reference. The bug was one line.

1. In the one-codebase, many-customers example, what was the bug that gave customer B customer A's webhook address?
2. In the shared-defaults customer settings demo with three customers, how many settings leaked with each loader?
3. What does the Python documentation say about a shallow copy and a deep copy, as the video uses it?
4. In the customer settings example, what should be stored for a webhook secret?
5. Why does the video say the zero leaks for the safe loader needs care?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Run both loaders

    Copy the code folder first. Run python run.py. Find the lines for the private copy and the shared defaults. You should see 0 leaked settings for the private copy, 8 for the shared defaults, and the defaults themselves now saying region: us-east.

    A hint

    Look at which customers have leaks in the list.

  2. Fix the shared loader

    In loader.py, in load_shared, change merge(DEFAULTS, CUSTOMERS[name]) to merge(deepcopy(DEFAULTS), CUSTOMERS[name]). Predict the new leak counts, then run python run.py. With this change both loaders show 0 leaked settings and the defaults still say eu-west. What did the one change do?

    A hint

    That makes load_shared the same as load_safe.

  3. Try a shallow copy

    Restore loader.py, then in load_shared change merge(DEFAULTS, CUSTOMERS[name]) to merge(dict(DEFAULTS), CUSTOMERS[name]). Predict how many settings leak, and whether the defaults say us-east at the end, then run it. With this change the shared loader leaks 5 settings and the defaults say eu-west. Why do some settings still leak? Then restore loader.py to merge(DEFAULTS, CUSTOMERS[name]) in load_shared, because the next exercise needs the original.

    A hint

    A shallow copy only shares the nested objects.

  4. Change the load order

    In run.py swap the two entries in the for loop tuple so that load_shared comes first and load_safe second. Predict what the private copy loader reports now, then run it. With this change the shared loader still leaks 8 settings, but the private copy loader leaks 12. What does that say about testing in one order only?

    A hint

    The defaults are already changed by the time the safe loader starts.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

Made-up customers and settings; secrets are only reference names. One kind of leak (a shared default that is changed), one load order, safe loader first. The check only compares settings that exist in the defaults, and the expected values are built by the same copy and merge.

Up next in Forward deployed engineer interviews

More in Forward deployed engineer interviews

All Forward deployed engineer interviews videos

Related videos