raychenfj / nomisma-backend

nomisma backend code changllege

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nomisma Backend Code Challenge

repo for nomisma backend code challenge

Build Status

Overview

This is a project for nomisma backend code challenge. Read the challenge guideline at docs section.

Build with Express

Design

Schedule

The schedule should be decoupled from specific business logic in order to reuse.

So it has an executor option to define what you want to do, sending email or doing something else.

Email Service

The email service should like an adapter, provide consistent interface for different email service providers.

And should not care about which email service is actually used when call it from outside.

Links

Production: http://raychenfj.me:3007

API

list tasks

url: /api/v1/tasks

method: GET

output:

[
  {
    "to": "example@example.com",  // recipient's email
    "content": "hello world", // email content
    "subject": "hello world", // email subject
    "timestamp": 1544065545639, // timestamp, when the email should be send
    "immediate": false, // send it immediately
    "id": "88672290-ba4a-4689-aaba-c6924ea00b88", // auto-gen uuid
    "status": "complete", // status, can be pending/complete/fail
    "retry": 0 // retry times
  }
]

create new task

url: /api/v1/tasks

method: POST

input:

body: {
	"to": "example@example.com", // recipient's emaild
	"content": "hello world", // email content
	"subject": "hello world", // email subject
	"timestamp": 1544111630082, // unix timestamp
}

output:

will send schedule task successfully when success

Install

npm run install
# or
yarn

Test

npm run test

Run

  1. Rename config.example.js to config.js

  2. Fill api keys for both development and production env in config.js( get your api keys here SendGrid and SparkPost )

  3. Then run npm run start:dev/prod for development/production env

Deploy with Docker

bash publish.sh

Some Other Thoughts

Producer Consumer Pattern

Can re-implement this email service by using producer consumer pattern. Can provide improve performance when payload and concurrency are high.

The web service works as producer, it constantly add new tasks to some queue, like RabbitMQ.

And the schedule as a worker or consumer, constantly fetch tasks from queue when it's idle or payload is low.

Create more producers and consumers to scale.

OpenApi

Doc in OpenApi can provide some benefits.

It's json format and be easily parsed.

What I come up with is auto-generating some frontend api code.

Docs

Guidelines

About

nomisma backend code changllege


Languages

Language:JavaScript 95.1%Language:Shell 1.9%Language:Dockerfile 1.2%Language:HTML 1.1%Language:CSS 0.7%