PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/System Design/Tesla

Design synchronization for water molecule assembly

Last updated: Mar 29, 2026

Quick Overview

This question evaluates concurrency and synchronization skills, including thread coordination, use of locks/semaphores/condition variables, and reasoning about safety and liveness properties in concurrent systems.

  • medium
  • Tesla
  • System Design
  • Software Engineer

Design synchronization for water molecule assembly

Company: Tesla

Role: Software Engineer

Category: System Design

Difficulty: medium

Interview Round: HR Screen

Multiple threads repeatedly provide 'H' and 'O' atoms as callable actions. Design synchronization so that the program outputs a valid sequence representing water molecules, where for every molecule exactly two 'H' actions and one 'O' action are released together. Do not busy-wait; use semaphores/locks/condition variables. Ensure safety (no extra atoms), liveness (no starvation), and scalability under an unbounded stream of atoms. Provide pseudocode and explain correctness.

Quick Answer: This question evaluates concurrency and synchronization skills, including thread coordination, use of locks/semaphores/condition variables, and reasoning about safety and liveness properties in concurrent systems.

Related Interview Questions

  • Design booking and settlement systems - Tesla (medium)
  • Compare RDBMS and NoSQL trade-offs - Tesla (medium)
  • Design concurrency-safe shared payment account API - Tesla (hard)
  • Explain HTTP methods and your usage - Tesla (medium)
  • Describe how you use Kubernetes - Tesla (medium)
Tesla logo
Tesla
Aug 14, 2025, 12:00 AM
Software Engineer
HR Screen
System Design
8
0

Concurrency: Build H2O from concurrent H and O actions

Context

You are given two kinds of threads that repeatedly call the following functions:

  • hydrogen(releaseHydrogen)
  • oxygen(releaseOxygen)

Each function receives a callable action:

  • releaseHydrogen() emits/prints "H"
  • releaseOxygen() emits/prints "O"

Goal

Design synchronization so that the program outputs a valid sequence of water molecules. For every molecule, exactly two H actions and one O action must be released together (i.e., the three actions for a molecule proceed as a group; groups do not interleave).

Constraints

  • Do not busy-wait. Use semaphores, locks, and/or condition variables.
  • Safety: no extra atoms are emitted; every molecule releases exactly two H and one O.
  • Liveness: no starvation assuming both atom types arrive infinitely often.
  • Scalability: handle an unbounded stream of atoms without unbounded resource growth.

Deliverables

  • Pseudocode for hydrogen and oxygen functions and any supporting synchronization primitives.
  • A brief explanation of correctness (safety, liveness, scalability).

Solution

Show

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More Tesla•More Software Engineer•Tesla Software Engineer•Tesla System Design•Software Engineer System Design
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.