Klaviyo OA Interview Problem: Weather Challenge

15 Views
No Comments

Weather Challenge

Information

For this interview, we’d like you to add some new functionality to an existing system. There are a few things we’d like to mention before diving into the parts of the interview:

  • This interview requires no prior knowledge of the specific technologies used in the project. You must use Python and the specific libraries called out within each part.
  • We can help with language-specific syntax, and will provide relevant links to third-party documentation where necessary. You are also welcome to use Google to answer questions or look up references.
  • You must finish parts in sequential order, before moving on to subsequent parts.
  • It’s okay if you don’t get to every part of this interview. We don’t expect everyone to finish.

Executing the App

To start the Flask app, run:

make start

in your terminal.

Your Task

Note: We don’t expect you to finish all the parts of this challenge; they are just here in case you need more things to do!

Part 1

Exercise a JSON REST API

First, send a test GET to the / route. To do so with curl, open a new terminal tab and enter:

curl http://localhost:3000

Next, send a test POST request to /test. This can be done using the following command:

curl http://localhost:3000/test --request POST --data foobar

Finally, try sending requests using –verbose and review the information returned. For example:

curl http://localhost:3000/ --verbose
curl http://localhost:3000/ --request POST --verbose
curl http://localhost:3000/nonexistent-route --verbose

Part 2

Implement a POST endpoint that accepts an email address + city pair and saves it to the database.

  • Implement ajax_subscribe in app.py
  • Both the email and the city are required.
  • An email can sign up for multiple cities, but each email can only sign up for the same city once.
  • We’ve provided a models.py file which has an unfinished table schema set up.
  • We’ve provided a file cities.json which is loaded into memory. The city must belong to the list of provided cities.

Implement a GET endpoint that returns a list of saved email address / city pairs.

  • Implement ajax_list_subscriptions in app.py

For this part, we will be using the PonyORM library to interface with an SQLite database. We recommend scanning through the Getting Started page for a quick primer for most operations, but the Declaring Entities docs will provide more relevant information for any schema definitions.

Part 3

Update ajax_list_subscriptions in app.py to do the following:

  • List all saved email address/city pairs
  • Alongside each pair, also list the current temperature at each city
  • You should use the OpenWeatherMap Current Weather API for this – you can use this API key: 6dca56a8c78e572f0b3263b4d7b05af

Part 4

Open ended discussion

  • We’ll ask you open-ended questions about how you might improve your system, or help it scale up to handle more volume, etc.
  • [execution time limit] 30 seconds
  • [memory limit] 1 GB

This Klaviyo Weather Challenge is a multi-part Flask and REST API exercise centered on building an email-to-city subscription system. Candidates first verify the basic routes, then implement database-backed POST and GET endpoints with validation rules such as required fields, unique email-city pairs, and city membership in a provided list. The final step enriches each saved subscription with current weather data from OpenWeatherMap, testing API integration, data modeling with PonyORM, and practical backend design skills.

END
 0