Skip to content

Instantly share code, notes, and snippets.

@stephenhenderson
Created April 17, 2015 10:14
Show Gist options
  • Save stephenhenderson/79f86024d78143db5e93 to your computer and use it in GitHub Desktop.
Save stephenhenderson/79f86024d78143db5e93 to your computer and use it in GitHub Desktop.
Simple pixel server exercise

The following exercise is intended for new developers unfamiliar with Python. The idea is to provide a reasonably complex project they can implement in their first week while learning the language which requires a variety of python libraries as well as introducing them to the adtech domain and terminology.

The developer should implement this project as if it were production code, taking account for unit tests and error handling. At the end of each task the developer can submit a code review for feedback.

Pixel Server Exercise

This exercise is to implement a simple pixel server which could be used to track user searches on a single advertiser's website.

Part 1: Implement basic http server which returns 1x1 transparent gif

  • Http server which listens on configurable port.
  • Http endpoint which serves a 1x1 transparent gif to incoming GET requests.
  • Logs details of request (ip-address, timestamp, user-agent, etc.) to standard out.

Part 2: Accept search terms in querystring and write to log in avro format

  • Querystring parameter "st" will contain a list of search terms, these should be parsed and logged.
  • Change logging to write to file in avro format.

Part 3: User tracking via cookie

  • Generate user-id first time we see a user.
  • Set user-id in a cookie when responding.

Part 4: Load advertiser config from db

  • Load list of active advertisers from database.
  • Add advertiser-id as new required querystring parameter.
  • If advertiser-id is missing or not in active set return error response.

Part 5: Redirect to partner

  • Add new table to database: data_partners
  • Data partner has a name and a url: e.g. "DoubleClick" "http://doubleclickpartner.com/ck=<USER_ID>
  • Advertiser can have a one optional data_partner.
  • If a data partner is configured for an advertiser then when we receive a pixel request we should redirect to the partner's url, replacing a USER_ID marker with our id for the user.

Part 6: Log analysis

Add a utility script which can parse a log file of search term pixels and produce a frequency report of top 10 keywords by advertiser-id.

Notes:

  • You can implement the http server with either the standard library or as a WSGI endpoint (with flask or gnunicorn)
  • You can use sqlite or mysql for the db.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment