Task: Viral Growth

Tags

Microservice, Backend, Performance, Social Network

Description

We're making the next Facebook. In order to make this the next big thing, we need to go viral!

We want to build an account management system, with referral/invitation functionality. To be specific:

  • Each user has a unique ID and a user name
  • Each user can generate an invitation code and share via their channels
  • On registration, the new user can provide an invitation code from other users
  • User can see how many new users he has directly invited joined

As the lead developer in the company, this feature of course goes to you. Make it happen!

PS: If you're curious why there's no password for users, because nothing is completely safe! So the product decided to go the other direction. There's no password to leak, if there's no password at all! :)

Specification

Configuration

We expect a working HTTP server. This server reads the following configuration.

configSource: { "jsonFile": "./config.json" }

{
    // The server should start at this port
    "port": 8080,
    // Only these characters are allowed to appear in the generated invite code
    "inviteCodeChars": "ABCDEFGH"
}

configSource: "env"

PORT=8080
INVITE_CODE_CHARS=ABCDEFGH

The server has the following endpoints.

POST /register

Register a user. The request comes with two possible input:

  • userName: Mandatory string
  • inviteCode: Optional string

The endpoint should

  • Accepts application/json content type, as shown in the example below
  • Return a 200 OK with a single string in the body, representing the user ID.
  • Return a 400 Bad Request if anything goes wrong. To name one, the invite code is invalid.

GET /userProfile?id=<ID>

Input is a single user ID, and response should give back a JSON object that looks like this. Note that the inviteCode must only use the characters in the config.

{
  "userName": "THE_USER_NAME",
  "inviteCode": "ABCDABCD",
  "invitedUsers": 100,
}

Return 400 if the user with that ID does not exist.

Example

The server is started with config: { "port": 8080, "inviteCodeChars": "REAL" }.

And we have the following request/response stream:

$ curl -d '{"userName": "Real Dev"}' -H 'Content-Type: application/json' 'http://localhost:8080/register'
1

$ curl 'http://localhost:8080/userProfile?id=1'
{"userName":"Real Dev","inviteCode":"REAL","invitedUsers":0}

$ curl -d '{"userName": "Luke", "inviteCode": "REAL"}' -H 'Content-Type: application/json' 'http://localhost:8080/register'
42

$ curl 'http://localhost:8080/userProfile?id=42'
{"userName":"Luke","inviteCode":"YO","invitedUsers":0}

$ curl 'http://localhost:8080/userProfile?id=1'
{"userName":"Real Dev","inviteCode":"REAL","invitedUsers":1}
Instructions
Get started
My Submissions

Submit to see your result!

Leaderboard

Nobody here yet, solve it now to get on the board!