Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Asynchronous Processing with Retries
00:00
5 left

Asynchronous Processing with Retries

MediumPython

Problem

Bekaert integration services may receive messages that fail temporarily during asynchronous processing. Implement a queue-based processor that retries failed messages up to a fixed limit and sends messages that still fail to a dead-letter list.

A deterministic failure_plan simulates the message handler. For a message ID, a non-negative value indicates how many initial attempts fail before processing succeeds. A value of -1 indicates a permanent failure. Messages are processed from a FIFO queue, and each retry is appended to the queue so other pending messages can be handled first.

Formal Specification

Implement process_messages(messages, max_retries, failure_plan):

  • messages is a list of dictionaries, each containing a unique string id and any payload fields.
  • max_retries is a non-negative integer. A message may be attempted at most max_retries + 1 times.
  • failure_plan is a dictionary mapping message IDs to failure counts. IDs absent from the dictionary succeed immediately.
  • Return a dictionary with processed, dead_letter, and attempts keys. processed and dead_letter contain IDs in the order they finish. attempts maps every ID to its total number of attempts.

Constraints

  • 1 <= len(messages) <= 10^4
  • 0 <= max_retries <= 10^3
  • Message IDs are unique strings
  • Each failure-plan value is -1 or a non-negative integer

Function Signature

def process_messages(messages, max_retries, failure_plan):
Interviewer

Your question is Asynchronous Processing with Retries. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.