← Nextdoor Interview Insights

Nextdoor·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Nextdoor analytics engineer interview, SQL-heavy technical screen. Three queries on a social graph schema plus a discussion about indexing strategy. Pretty standard for the role but the indexes conversation is where they actually push back.

Questions Asked (4)

Q1

Write a SQL query to return the total number of users in the database.

Product Analytics & Metrics
Author's notes

Warmup question, COUNT(*) on users, nothing to it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the definition of 'user' and the relevant table, then write a simple COUNT(*) query. If the table may contain duplicates or soft-deleted users, adjust the query accordingly (e.g., COUNT(DISTINCT user_id) or add a WHERE clause).

Pro tip: Mention that COUNT(*) is generally faster than COUNT(column) and that for large tables, an approximate count (e.g., using pg_class.reltuples in PostgreSQL) might be acceptable for analytics dashboards.

1. Clarify requirements

Ask whether 'users' means all rows in a users table, distinct user IDs, or active users. Confirm if soft-deleted or test accounts should be excluded.

2. Identify the table and column

Determine the exact table name (e.g., users) and the primary key or relevant column (e.g., user_id) to count.

3. Write the basic query

Use SELECT COUNT(*) FROM users; for total rows, or SELECT COUNT(DISTINCT user_id) FROM users; if duplicates are possible.

4. Add filters if needed

If excluding soft-deleted users, add WHERE deleted_at IS NULL; if only active users, add WHERE status = 'active'.

5. Consider performance

For very large tables, mention that COUNT(*) can be slow and suggest alternatives like approximate counts or maintaining a counter.

Key Points to Mention

  • Difference between COUNT(*) and COUNT(column)
  • Handling duplicates with COUNT(DISTINCT user_id)
  • Filtering out soft-deleted or inactive users
  • Performance implications of COUNT on large tables
  • Using approximate counts for analytics if exactness isn't critical
  • Clarifying the definition of 'user' with stakeholders

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

Q2

Write a SQL query to find the calendar month with the highest number of user signups, returning the month and the count.

Product Analytics & MetricsData Modeling
Author's notes

This is where I fumbled a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and assumptions (e.g., signups table with a timestamp column, definition of 'calendar month'). Then write a query that groups signups by month, counts them, orders descending, and limits to 1. Consider edge cases like ties and time zones.

Pro tip: Mention that you'd use DATE_TRUNC or EXTRACT to get the month, and that you'd handle ties by either returning all months with the max count or using a window function. Also, note that for large datasets, you might pre-aggregate or use an index on the signup date.

1. Clarify requirements and schema

Ask about the table structure, the definition of 'calendar month' (e.g., based on signup timestamp), and whether ties should be handled. Confirm the database system (e.g., PostgreSQL, MySQL) as syntax varies.

2. Extract month from timestamp

Use a date function to truncate or extract the month from the signup timestamp. For example, DATE_TRUNC('month', signup_date) in PostgreSQL or DATE_FORMAT(signup_date, '%Y-%m') in MySQL.

3. Group and count signups

Group by the extracted month and count the number of signups per month. Use COUNT(*) or COUNT(user_id) depending on whether you want to count all rows or distinct users.

4. Order and limit to top month

Order the results by count descending and limit to 1 to get the month with the highest signups. If ties are possible, consider using a window function like RANK() to return all top months.

5. Consider performance and edge cases

Mention indexing on the signup date column, handling NULLs, and time zone considerations. Also, discuss how to handle months with no signups if needed.

Key Points to Mention

  • Use of DATE_TRUNC or EXTRACT for month extraction (database-specific).
  • Grouping by month and counting signups.
  • Ordering by count descending and limiting to 1.
  • Handling ties with window functions (e.g., RANK() OVER (ORDER BY count DESC)).
  • Performance considerations: indexing on signup date, pre-aggregation for large datasets.
  • Time zone handling: ensure signup timestamps are in the correct time zone for month boundaries.

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

Q3

Write a SQL query to find the user with the most followers, returning their user_id and follower count. Handle ties in any consistent way.

Product Analytics & MetricsData Modeling
Author's notes

JOIN or subquery on the follows table, GROUP BY followee_id, COUNT follower_id, ORDER BY desc, LIMIT 1.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and edge cases (e.g., no followers, ties). Then write a query that groups by user_id, counts followers, and selects the top user using ORDER BY with a LIMIT 1, or a window function for tie handling. Explain your choice and how it scales.

Pro tip: Mention that you would add an index on the follower table's user_id column to speed up the GROUP BY, and consider using a window function like RANK() if ties need to be returned.

1. Clarify requirements and schema

Ask about the table structure (e.g., users, follows) and whether ties should return multiple users or just one. Confirm if the follower count should include only direct followers.

2. Choose aggregation strategy

Decide between a simple GROUP BY with ORDER BY and LIMIT, or a window function like RANK() if ties need to be handled. Consider performance implications for large datasets.

3. Write the SQL query

Construct the query: SELECT user_id, COUNT(*) AS follower_count FROM follows GROUP BY user_id ORDER BY follower_count DESC LIMIT 1; or use RANK() OVER (ORDER BY COUNT(*) DESC) to handle ties.

4. Address edge cases and optimizations

Discuss handling users with zero followers, ensuring deterministic tie-breaking (e.g., by user_id), and adding indexes on the follower column for performance.

Key Points to Mention

  • Use of GROUP BY and COUNT to aggregate followers per user
  • ORDER BY with DESC and LIMIT 1 for simple top-1 selection
  • Window functions (RANK, DENSE_RANK) for tie handling
  • Indexing the follower table's user_id column for performance
  • Handling ties consistently (e.g., by adding a secondary sort on user_id)
  • Scalability considerations for large datasets (e.g., avoiding full table scans)

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

Q4

What indexes would improve performance for each of these three queries, and why?

System DesignTechnical Trade-offs
Author's notes

This was the real question.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

For each query, analyze the WHERE, JOIN, and ORDER BY clauses to identify which columns are used for filtering, joining, and sorting. Then propose composite indexes that follow the leftmost prefix rule and cover the query to minimize lookups. Explain how each index reduces I/O and improves performance, considering selectivity and write overhead.

Pro tip: Mention that indexes have trade-offs: they speed up reads but slow down writes and consume storage, so you should verify with EXPLAIN and consider covering indexes for hot queries.

1. Analyze query patterns

Examine each query's WHERE, JOIN, ORDER BY, and GROUP BY clauses to determine which columns are used for filtering, joining, and sorting.

2. Identify candidate indexes

For each query, propose composite indexes that include equality columns first, then range/sort columns, following the leftmost prefix rule.

3. Consider covering indexes

If a query selects only a few columns, suggest a covering index that includes all selected columns to avoid table lookups.

4. Evaluate trade-offs

Discuss the impact on write performance, storage, and maintenance; recommend verifying with EXPLAIN and monitoring.

5. Summarize and prioritize

Conclude with the most impactful indexes and suggest an implementation order based on query frequency and criticality.

Key Points to Mention

  • Composite index column order: equality conditions first, then range/sort columns
  • Leftmost prefix rule and how it affects index usability
  • Covering indexes to avoid table lookups (index-only scans)
  • Selectivity of columns and its impact on index effectiveness
  • Trade-offs: write amplification, storage overhead, and maintenance cost
  • Using EXPLAIN to validate index usage and performance gains

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