Anthropic logo

Anthropic Software Engineer System Design Questions

19 practice questions for Anthropic Software Engineer interviews

Anthropic software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
1
System Design
system design Hard Verified Question #1

1. System Design - Inference API


Category: Queue-based system design problem
You need to design a high-concurrency inference API system. This system must handle many requests happening at the same time. You are given an API...
Input: Number(s)
Output: Computed result
Want to practise this one?
Create a free account to open the full question and practise Anthropic questions with AI.
Sign up free
system design Hard concurrency #1

1. Design StackTraceReconstructor — reconstruct nested function events from sampled call stacks


Background


Engineers investigating latency in Claude-serving infrastructure need to turn periodic stack samples into timelines that can be inspected by a profiler. Design an in-memory component for that workflow, adapting the stack-trace problem reported in Anthropic interviews. This is a practice design, not a claim about Anthropic's internal profiling implementation.

Requirements


1. Maintain independent state for each thread. A sample contains an integer timestamp and a stack of function names ordered outermost to innermost. The first sample registers the thread; its stack is compared with an empty stack. Subsequent sample timestamps for that thread must be strictly increasing, even when its stack is unchanged or empty. Timestamps across different threads need not be ordered.
2. Reconstruct events using the longest common prefix of the previous and current stacks. Emit end events for the old suffix, innermost first, followed by start events for the new suffix, outermost first. All events use the new sample's timestamp. A frame's depth is its zero-based position in its stack; repeated function names represent distinct recursive frames. Matching prefix frames are assumed to remain active: do not infer unobserved calls between samples.
3. finish(thread_id, timestamp) closes the thread by ending every remaining frame, innermost first. Its timestamp must be at least the thread's latest sample timestamp. Finishing an already finished thread returns false without emitting events or checking the timestamp. Finishing an unknown thread raises ValueError; adding a sample to a finished thread also raises ValueError.
4. Buffer events until drain_events() returns and removes all buffered events. Each event is an object with exactly thread_id, timestamp, kind, function, and depth. Preserve method-call order, not global timestamp order; within a call, preserve the nesting order defined above. A second drain without intervening events returns an empty list. Copy input stacks so later caller mutations cannot change stored state.
5. Make every public operation thread-safe and atomic. Concurrent calls may take effect in any lock-acquisition order, but their events must not interleave. A rejected operation must leave thread state and buffered events unchanged. Keep finished-thread identities so they cannot be reused.

Class API


  • StackTraceReconstructor() — create an empty reconstructor.

  • add_sample(thread_id: str, timestamp: int, stack: list[str]) -> None — register or update a thread and append inferred events; raise ValueError for a finished thread or a non-increasing timestamp.

  • finish(thread_id: str, timestamp: int) -> bool — return true when an active thread is closed, or false if already closed; raise ValueError for an unknown thread or a timestamp earlier than its latest sample.

  • drain_events() -> list[dict[str, str | int]] — atomically return all pending events and clear the buffer.


Example 1


Input sequence:
[
  {"method":"add_sample","args":["worker-1",10,["serve","decode"]]},
  {"method":"add_sample","args":["worker-1",14,["serve","sample"]]},
  {"method":"finish","args":["worker-1",20]},
  {"method":"drain_events","args":[]}
]

Output, one result per call:
[
  null,
  null,
  true,
  [
    {"thread_id":"worker-1","timestamp":10,"kind":"start","function":"serve","depth":0},
    {"thread_id":"worker-1","timestamp":10,"kind":"start","function":"decode","depth":1},
    {"thread_id":"worker-1","timestamp":14,"kind":"end","function":"decode","depth":1},
    {"thread_id":"worker-1","timestamp":14,"kind":"start","function":"sample","depth":1},
    {"thread_id":"worker-1","timestamp":20,"kind":"end","function":"sample","depth":1},
    {"thread_id":"worker-1","timestamp":20,"kind":"end","function":"serve","depth":0}
  ]
]

Explanation: At timestamp 14 the shared prefix is ["serve"], so only decode ends and sample starts. Finishing ends the two remaining frames in reverse depth order.

Example 2


Input sequence:
[
  {"method":"add_sample","args":["A",5,["walk","walk"]]},
  {"method":"add_sample","args":["B",2,[]]},
  {"method":"add_sample","args":["A",6,["walk"]]},
  {"method":"add_sample","args":["B",3,["serve"]]},
  {"method":"finish","args":["A",6]},
  {"method":"finish","args":["A",0]},
  {"method":"drain_events","args":[]},
  {"method":"drain_events","args":[]}
]

Output, one result per call:
[
  null,
  null,
  null,
  null,
  true,
  false,
  [
    {"thread_id":"A","timestamp":5,"kind":"start","function":"walk","depth":0},
    {"thread_id":"A","timestamp":5,"kind":"start","function":"walk","depth":1},
    {"thread_id":"A","timestamp":6,"kind":"end","function":"walk","depth":1},
    {"thread_id":"B","timestamp":3,"kind":"start","function":"serve","depth":0},
    {"thread_id":"A","timestamp":6,"kind":"end","function":"walk","depth":0}
  ],
  []
]

Explanation: Recursive frames are distinguished by depth. Thread B's empty first sample registers it without creating events. Its timestamp-3 event remains after A's timestamp-6 event because calls, rather than timestamps, define buffer order. Repeating finish is a no-op even with an earlier timestamp.

Constraints


  • At most 10,000 distinct thread IDs and 100,000 total sample/finish calls; each stack has at most 1,000 frames.

  • Timestamps are integers in [0, 10^12]; thread IDs and function names are nonempty strings of at most 128 characters. Types and these bounds are guaranteed by callers.

  • At most 1,000,000 events are pending between drains. There are at most 32 concurrent callers, and callers must not mutate an input stack while its call is executing.

  • Use only in-memory state and standard-library facilities; persistence, actual stack sampling, and global timestamp sorting are out of scope.
Want to practise this one?
Create a free account to open the full question and practise Anthropic questions with AI.
Sign up free
system design Medium api design #2

2. Design FileStorageSystem — an object-oriented representation of a file storage system


Background: Anthropic requires a scalable file storage system to efficiently manage user files in a way that supports key operations like storing, retrieving, filtering, backing up, and restoring files. This is crucial for data management across various applications.
Requirements:
1. Implement set(file: str, data: bytes) -> None to store a file.
2. Implement get(file: str) -> Optional[bytes] to retrieve file data by name.
3. Implement filter(criteria: Callable[[str], bool]) -> List[str] to return a list of files matching certain conditions.
4. Implement backup(destination: str) -> None to backup all files to a specified location.
5. Implement restore(source: str) -> None to restore files from a backup location.
Class API:
  • set(file: str, data: bytes) -> None: Stores the file file with the content data in bytes.

  • get(file: str) -> Optional[bytes]: Returns the content of the file if it exists, otherwise returns None.

  • filter(criteria: Callable[[str], bool]) -> List[str]: Returns a list of file names that match the given criteria.

  • backup(destination: str) -> None: Backs up the current files to the specified destination.

  • restore(source: str) -> None: Restores files from a backup source.


Example 1:
Input:
  • set('document.txt', b'This is a document.')

  • set('image.png', b'Image data here.')

Output:
  • get('document.txt') returns b'This is a document.'

  • filter(lambda x: x.endswith('.png')) returns ['image.png']

Explanation: The method set is used to store files and get retrieves the content of a specific file. The filter method uses a lambda function to find files with the .png extension.
Example 2:
Input:
  • backup('/backup/location')

  • restore('/backup/location')

Output: No direct output, but files are backed up and restored as needed.
Constraints:
  • Maximum number of files: 1000

  • File name length: up to 255 characters.

  • Data size: up to 1MB per file.


Related Anthropic Software Engineer interview prep

Start practicing Anthropic questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free