Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Trending in AI
Hot
Agentic AI EngineerForward-Deployed EngineerGenAI EngineerAI Architect
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Start free
Message Routing with Multiple Providers
00:00
5 left

Message Routing with Multiple Providers

MediumSQL · PostgreSQL

Problem

Machine coding: build a communication service handling multiple request types (Email, SMS, Soundbox) with per-type mandatory fields; providers support one or more channels, multiple providers per channel, providers have multiple accounts (e.g. for critical OTP traffic); randomly select one active eligible provider per request. Asked in the Machine coding stage.

Output

  1. Return one row per valid request with request_id, request_type, account_id, and provider_name.
  2. Exclude requests missing their type-specific mandatory field or lacking an eligible account.
  3. Select only active providers and accounts, require critical OTP support when applicable, and order by request_id.

Output details

  • Treat email_address, phone_number, and soundbox_device_id as present only when non-NULL and nonblank after trimming whitespace.
  • Require critical-OTP support unless is_critical_otp is exactly FALSE; treat NULL as requiring support.
  • Choose randomly among eligible provider-account rows, so multiple accounts from one provider are separate choices.
  • Order results by request_id ascending.

Schema

communication_requests
ColumnTypeDescription
request_idPKINTCommunication request identifier
request_typeVARCHAR(20)Requested channel: EMAIL, SMS, or SOUNDBOX
email_addressVARCHAR(255)Required for email requests
phone_numberVARCHAR(30)Required for SMS requests
soundbox_device_idVARCHAR(50)Required for Soundbox requests
is_critical_otpBOOLEANWhether the request requires a critical OTP-capable account
providers
ColumnTypeDescription
provider_idPKINTProvider identifier
provider_nameVARCHAR(100)Provider display name
supported_channelsTEXT[]Channels supported by the provider
is_activeBOOLEANWhether the provider can receive new requests
provider_accounts
ColumnTypeDescription
account_idPKINTProvider account identifier
provider_idINTReferenced provider
account_nameVARCHAR(100)Provider account label
is_activeBOOLEANWhether the account is available
supports_critical_otpBOOLEANWhether the account supports critical OTP traffic
Tablescommunication_requestsprovidersprovider_accounts
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

Sign up free to run or submit. Log in
CodePostgreSQL
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 1
Run your query to see results here.