Skip to content

Instantly share code, notes, and snippets.

@Ravi2712
Last active July 28, 2022 21:42
Show Gist options
  • Save Ravi2712/dcdd0c10985bc0165964bf426f67f429 to your computer and use it in GitHub Desktop.
Save Ravi2712/dcdd0c10985bc0165964bf426f67f429 to your computer and use it in GitHub Desktop.

Python Coding Challenge

This coding challenge is an exercise to look at your programming style. This is your chance to show off your programming design skills, your testing habits (unittest), and your attention to details. Your solution should be well documented and tested for production release. It should follow good Python conventions, and should be easy to get running.

Acceptance criteria

  • A single zip file named <lastname_jobposition_date.zip>
    • python files (you can create as many files as you want, you are allowed to create framework template)
    • server.log (log file for capturing all output from server side)
    • README.md (write instructions how to run your file)

After you’ve engineered a solution to your satisfaction, package up your response and send it through Email.

Coding challange

Design and implement a RESTful web API that can be used to maintain a database of GUIDs (Globally Unique Identifier) and associated metadata. The API must expose commands to perform CRUD operations (Create, Read, Update, Delete). GUIDs should be 32 hexadecimal characters, all uppercase. The GUIDs should be valid only for a limited period of time, with a default of 30 days from the time of creation, if an expiration time is not provided. The expiration time should be formatted in Unix Time. Input and output data should be valid JSON format. Validations should be put in place to make sure input data conforms the specified formats. Code must be documented.

Bonus points if the solution is fully asynchronous.

Commands specification

Create

Creates a new GUID and stores it in the database along with the metadata provided. If a GUID is not specified, the system should generate a random one.

Example 1

URL: POST /guid/9094E4C980C74043A4B586B420E69DDF

Input:
{
  "expire": "1427736345",
  "user": "Salemount Labs"
}
Output:
{
  "guid": "9094E4C980C74043A4B586B420E69DDF",
  "expire": "1427736345",
  "user": "Salemount Labs"
}
  
 ---------
 
 
Example 2

URL: POST /guid

Input:
{
  "user": "Jay Patel"
}
  
Output:    
{
  "guid": "9094E4C980C74043A4B586B420E69DDF",
  "expire": "1427736345",
  "user": "Jay Patel"
}

Read

Returns the metadata associated to the given GUID.

Example

URL: GET /guid/9094E4C980C74043A4B586B420E69DDF

Output:
{
  "guid": "9094E4C980C74043A4B586B420E69DDF",
  "expire": "1427736345",
  "user": "Jay Patel"
}

Update

Updates the metadata associated to the given GUID. The GUID itself cannot be updated using this command.

Example

URL: PATCH /guid/9094E4C980C74043A4B586B420E69DDF

Input:
{
  "expire": "1427822745",
}

Output:
{
  "guid": "9094E4C980C74043A4B586B420E69DDF",
  "expire": "1427822745",
  "user": "Jay Patel"
}

Delete

Deletes the GUID and its associated data.

Example

URL: DELETE /guid/9094E4C980C74043A4B586B420E69DDF 
No output.

Error code returns

The following response codes should be returned by the service:

  • 200's on accepted/successful requests
  • 400's on client errors
  • 500's on server errors

Suggestions

  • Use the Django/Flask/Tornado web framework for the RESTful interface
  • Use Redis for the cache
  • Use MySQL or MongoDB to store data permanently
  • The application should use a cache layer to quickly serve the most recently used GUIDs.

Python version

Please ensure your program runs correctly for Python 3+ version.

Questions? Feel free to email. Good luck! 👍

Author

Jay Patel(patel.jay9586@gmail.com)

@Ravi2712
Copy link
Author

To be fancy, how about trying one of "Producer-Consumer" pattern? e.g. celery, Faktory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment