← Shopify Interview Insights

Shopify·Software Engineer·Take-home Assignment·Intermediate

Intermediate
May 2026

Summary

Shopify software engineering interview that was basically a full mini-project: build a local URL shortener from scratch, covering encoding, persistence, memory, and tests. No vague questions, just a concrete spec and a lot of ground to cover.

Questions Asked (4)

Q1

Design and implement a local URL shortener tool with input validation, short code generation, in-memory storage with JSON file persistence, and a full test suite targeting 90%+ coverage.

System DesignAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

This was a lot to hold in your head at once.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints (e.g., expected scale, persistence needs, API design). Then outline a modular design covering validation, code generation, storage, and persistence, and discuss trade-offs. Finally, walk through implementation details and testing strategy, emphasizing how you achieve 90%+ coverage.

Pro tip: Mention that you'd use property-based testing (e.g., Hypothesis) for input validation and code generation to catch edge cases, and that you'd mock file I/O to keep tests fast and isolated.

1. Clarify Requirements and Scope

Ask about expected traffic, URL length limits, custom aliases, expiration, and whether persistence should be synchronous or asynchronous. Confirm the API surface (e.g., CLI, HTTP, library).

2. Design the Components

Break down into input validation (URL format, length), short code generation (base62, random or hash-based), in-memory storage (dict with collision handling), and JSON persistence (load on start, save on write).

3. Discuss Trade-offs and Edge Cases

Compare random vs. sequential codes, discuss collision probability and resolution, persistence frequency (write-through vs. batch), and handling of invalid URLs, duplicates, and concurrent access.

4. Outline Implementation Details

Describe key functions: validate_url, generate_code, shorten, resolve, save_to_json, load_from_json. Mention using standard libraries (e.g., urllib.parse, json, secrets) and error handling.

5. Testing Strategy for 90%+ Coverage

Plan unit tests for each component, integration tests for end-to-end flows, and edge cases (empty input, long URLs, collisions, file I/O errors). Use coverage tools to identify gaps and mock external dependencies.

Key Points to Mention

  • Input validation: use urllib.parse to check scheme and netloc, enforce max length, and reject invalid characters.
  • Short code generation: base62 encoding of a counter or random bytes, with collision detection and retry.
  • In-memory storage: dictionary mapping short code to original URL, with O(1) lookup and insertion.
  • JSON persistence: atomic writes (write to temp file then rename) to avoid corruption, and load on startup.
  • Testing: unit tests with pytest, mocking file I/O, property-based tests for validation and code generation, and coverage measurement.
  • Trade-offs: random vs. sequential codes (security vs. predictability), persistence frequency (durability vs. performance), and memory vs. disk storage.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

How would you handle hash collisions in a short URL encoding scheme, and how would you test for them?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was to just say 'rehash with a salt' and call it done.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining the trade-offs between different collision resolution strategies (e.g., open addressing, chaining, or using a counter) and how they apply to short URL encoding. Then describe how you would test for collisions, including unit tests, property-based testing, and load testing with high concurrency.

Pro tip: Mention that you would monitor collision rates in production and have a fallback mechanism, such as appending a random suffix or using a different encoding, to ensure reliability. This shows you think beyond just the algorithm.

1. Clarify requirements and constraints

Ask about expected scale, acceptable collision rate, and whether URLs are immutable. This helps choose the right approach.

2. Choose a collision resolution strategy

Discuss options like using a unique counter with base62 encoding, open addressing with linear probing, or chaining with a database. Explain trade-offs in terms of performance, complexity, and storage.

3. Design the encoding and storage

Explain how you would generate short codes (e.g., hash then encode, or sequential ID) and store mappings. Consider using a database with a unique index on the short code to detect collisions.

4. Outline testing strategies

Describe unit tests for the encoding function, property-based tests to ensure uniqueness, and integration tests with concurrent writes to simulate collisions.

5. Discuss monitoring and mitigation

Explain how you would monitor collision rates in production and implement fallback mechanisms, such as retrying with a different code or using a longer code.

Key Points to Mention

  • Base62 encoding and its efficiency for short URLs
  • Trade-offs between deterministic (e.g., hash-based) and non-deterministic (e.g., counter-based) approaches
  • Using a unique constraint in the database to detect and handle collisions
  • Property-based testing (e.g., QuickCheck) to verify uniqueness across many inputs
  • Concurrency testing to ensure thread-safe code generation
  • Monitoring collision rates and having a retry or fallback strategy

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Estimate how many URL mappings an in-memory hash map can hold on a typical machine, and describe how you'd scale beyond a single process.

System DesignTechnical Trade-offs
Author's notes

Rough math: each entry is maybe 200-300 bytes when you account for both strings and map overhead, so a few million entries fits comfortably in a few GB.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by estimating the memory footprint per URL mapping (key, value, and hash map overhead) and then divide the available RAM by that number to get a rough capacity. Then discuss scaling strategies such as sharding, distributed caches, and consistent hashing to handle larger datasets beyond a single process.

Pro tip: Mention that real-world systems often use a distributed cache like Redis or Memcached, but also consider the trade-offs between memory usage, latency, and consistency. Showing awareness of these trade-offs demonstrates senior-level thinking.

1. Estimate memory per entry

Calculate the approximate memory used by a single URL mapping, including the key (short URL), value (long URL), and overhead from the hash map structure (e.g., pointers, load factor).

2. Determine available memory

Assume a typical machine has 16-64 GB of RAM, but consider that the JVM or process overhead reduces usable memory. For example, a Java process might have 2-4 GB heap by default.

3. Compute capacity

Divide the available memory by the memory per entry to get an estimate. For instance, if each entry takes 100 bytes and you have 4 GB, you can hold about 40 million entries.

4. Discuss scaling beyond a single process

Describe approaches like sharding the hash map across multiple machines, using a distributed cache (e.g., Redis), or employing consistent hashing to distribute keys evenly.

5. Address trade-offs and considerations

Mention trade-offs such as increased latency, network overhead, consistency models, and fault tolerance when moving to a distributed system.

Key Points to Mention

  • Memory overhead of hash map entries (e.g., object headers, pointers, load factor)
  • Typical machine memory sizes and process heap limits
  • Sharding and consistent hashing for distributing data
  • Distributed caching solutions like Redis or Memcached
  • Trade-offs: latency vs. capacity, consistency vs. availability
  • Fault tolerance and replication in distributed systems

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

How would you persist the in-memory URL map across restarts without using a database?

System DesignAPI & Integrations
Author's notes

JSON file on shutdown, reload on startup.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements: the size of the map, read/write patterns, and durability needs. Then propose a file-based persistence strategy such as append-only log with periodic snapshots, and discuss trade-offs like performance, consistency, and recovery time.

Pro tip: Mention that you would use atomic file writes (write to temp file then rename) to avoid corruption, and consider using a write-ahead log for durability without sacrificing read performance.

1. Clarify Requirements

Ask about the expected size of the URL map, read/write ratio, acceptable latency, and durability guarantees. This determines whether a simple file or a more sophisticated approach is needed.

2. Choose Persistence Strategy

Propose an append-only log for writes and periodic snapshots for compaction. Alternatively, use a write-ahead log combined with in-memory map for fast reads.

3. Design File Format and Atomicity

Define a simple format (e.g., JSON lines or binary) and ensure atomic writes by writing to a temporary file and renaming it. This prevents partial writes on crash.

4. Implement Recovery on Startup

On restart, load the latest snapshot and replay the append-only log to rebuild the in-memory map. Handle corrupted entries gracefully.

5. Discuss Trade-offs and Alternatives

Compare with using an embedded key-value store like RocksDB or SQLite, and explain why a custom solution might be preferable for simplicity or performance.

Key Points to Mention

  • Append-only log for durability and fast writes
  • Periodic snapshots to compact the log and speed up recovery
  • Atomic file operations (write to temp, then rename) to avoid corruption
  • Recovery process: load snapshot, replay log
  • Trade-offs: performance vs. durability, complexity vs. simplicity
  • Alternatives: embedded databases (SQLite, RocksDB) or serialization formats (JSON, Protocol Buffers)

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.