Skip to main content

Practice ยท 2 of 4

Kill the N+1

CHALLENGE
Difficulty: intermediate+25 XP

LegacyLoader fetches one record per customer โ€” the N+1 shape, captured by a counting fake. Write Solution.LoadNames(Customer[] customers, ILookup store) that returns names in input order with **exactly one store round trip**: - store port: ILookup { string[] FetchMany(int[] ids); int Calls { get; } } โ€” returns the names for the requested ids, **in the same order as the ids**. - behavior: distinct ids are fetched once; results map back to each customer by position of their first occurrence; repeated customers get the same name without extra calls. The fake's Calls must be 1 after a batched load. The store provides the names โ€” do not read Customer.Name; the point is the batched fetch. ``csharp public static class Solution { public sealed class Customer { public int Id; } public static string[] LoadNames(Customer[] customers, ILookup store); } // top level: public interface ILookup { string[] FetchMany(int[] ids); int Calls { get; } } ``

Back to lesson: Practice: Architecture Practice: Seams, Batches, Boundaries