Resource Reconciler: Plan and Apply Creates
Updated
Problem statement
A resource reconciler compares the configuration you want with what really exists, then makes the changes needed to close the gap. You will build its first two parts.
Three inputs describe the world:
desiredmaps a logical address to the attributes you want. Each row is[address, attributes].stateis the saved state. Each row is a binding[address, resourceId, attributes]: the resource that the address was last bound to, and its attributes at that time.remotelists the resource ids that the resource client can find.client.read(resourceId)returns the resource when its id is inremote, and nothing otherwise.
Attributes are one text value, such as replicas=3. Copy them exactly; never parse or merge them.
Part 1: Plan the creates (part = "plan")
Go through the addresses in desired in sorted order. Compare addresses as plain strings, character by character. For each address:
- If
statehas no binding for it, it needs aCREATEchange. There is no resource id to read, so do not call the client. - If it has a binding but
client.readfinds nothing for the bound resource id, the resource is gone and it needs aCREATEchange. - If the bound resource exists, it needs no change in this problem, even when its attributes differ. Updates and deletes belong to later parts that are not covered here.
Return one line per change, in plan order: "CREATE <address> <attributes>", using the attributes from desired.
Part 2: Apply the creates (part = "apply")
Build the same plan, then run its changes in order. For each change:
- Call
client.create(attributes). The k-th create call returns a new resource with idres-k(res-1,res-2, and so on). - Save the binding
[address, newId, attributes]in the state store withput. It inserts a new binding or replaces the old binding for that address.
A change is done only when its resource was created and its binding was saved. If failAt is not 0, the create call number failAt throws an error instead of returning. The error must go back to the caller: stop at once, save nothing for that change, and run no later change. Bindings saved by earlier changes stay saved.
Return the final state store, one line per binding sorted by address: "<address> <resourceId> <attributes>". Bindings for addresses that are not in desired stay as they are. If a create call threw, add one more line at the end: "ERROR <address>", naming the change that failed.
Function
reconcile(part: String, desired: String[][], state: String[][], remote: String[], failAt: int) → String[]Examples
Example 1
part = "plan"desired = [["search_api","replicas=3"]]state = [["search_api","r-123","replicas=1"]]remote = []failAt = 0return = ["CREATE search_api replicas=3"]The state binds search_api to resource r-123, but the client cannot find r-123, so the resource is missing and must be created with the desired attributes replicas=3.
Example 2
part = "plan"desired = [["web","replicas=2"],["cache","size=4"],["db","tier=gold"]]state = [["db","r-7","tier=gold"],["web","r-9","replicas=1"]]remote = ["r-7"]failAt = 0return = ["CREATE cache size=4","CREATE web replicas=2"]The addresses are checked in sorted order: cache, db, web. cache has no binding in the state, so it is created without asking the client. db is bound to r-7, which the client finds, so it needs no change. web is bound to r-9, which the client cannot find, so it is created. The plan is cache, then web.
Example 3
part = "apply"desired = [["web","replicas=2"],["cache","size=4"],["db","tier=gold"]]state = [["db","r-7","tier=gold"],["web","r-9","replicas=1"]]remote = ["r-7"]failAt = 0return = ["cache res-1 size=4","db r-7 tier=gold","web res-2 replicas=2"]The same inputs, now applied. The plan creates cache first, and the client returns res-1; then web gets res-2. Each new binding is saved, so web's old binding to r-9 is replaced. db keeps its binding. The final state is listed by address.
Example 4
part = "apply"desired = [["web","replicas=2"],["cache","size=4"],["db","tier=gold"]]state = [["db","r-7","tier=gold"],["web","r-9","replicas=1"]]remote = ["r-7"]failAt = 2return = ["cache res-1 size=4","db r-7 tier=gold","web r-9 replicas=1","ERROR web"]This time the second create call fails. cache was already created as res-1 and saved, so it stays. The failure happens while creating web, so its binding is not saved and the old binding to r-9 is still there. The error goes back to the caller and nothing after it runs, so the last line is ERROR web.
Constraints
partis"plan"or"apply".1 <= desired.length <= 50and eachdesired[i]has 2 strings.0 <= state.length <= 50and eachstate[i]has 3 strings.0 <= remote.length <= 50- An address is 1 to 20 characters: a lowercase letter followed by lowercase letters, digits or underscores. Addresses in
desiredare distinct, and so are addresses instate. - An attributes value is 1 to 30 characters from lowercase letters, digits,
_,=and,. - A resource id is 1 to 12 characters: a lowercase letter followed by lowercase letters, digits or
-. Ids inremoteare distinct. No id instateorremotestarts withres-. 0 <= failAt <= 50, andfailAt == 0whenpartis"plan".
More Perplexity AI interview questions
- In-Memory Filesystem CommandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Agent Task Dependency TrackerPHONE SCREEN · Seen May 2026
- LLM Provider Pool FailoverPHONE SCREEN · Seen Aug 2025
- Out-of-Order Bank Ledger BalancesOA · Seen Nov 2026
- Feature Flags with Rules, Dependencies and ExposureONSITE INTERVIEW · Seen Nov 2026
- Sort Topic Names by Prefix and NumberONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
- Resolve Visible User FeaturesStripe · PHONE SCREENStripe interview questions
- Credit Card Command ProcessorChime · PHONE SCREEN
- Popular and Instant-Runoff Election WinnersCoursera · PHONE SCREEN
- AI Role: Collection with Add and Remove OperationsApple · PHONE SCREENApple interview questions
- Read a File from Distributed ChunksHudson River Trading · ONSITE INTERVIEWHudson River Trading interview questions
- HTTP Request RedirectionAmazon · OA
- P&L Leaderboard OperationsBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Aggregate Paginated Project Run RecordsReplit · OA
- Parcel Attribute Store with TTLAirbnb · OAAirbnb interview questions