Git Product home page Git Product logo

postcode-backend-api's Introduction

This is a backend solution to the technical assignment propose ahead.

Let’s pretend you are starting your first day with us. After you settle in, your first task will be assigned. Both Joseph (Product Owner) and Ness (Technical Lead) are ready to give you more details on your first task.

Joseph - “Hi, I have your first task, excited?

We need to create a web application that allows you to find the addresses of our customers based on their postcodes. Multiple addresses will be searched, so it would be nice if we could add the history of the last 3 in the page. Finally, alongside the address, we need to display the distance in a straight line, from the customer location to London Heathrow airport (lat/long: 51.4700223,-0.4542955) this should be displayed in both kilometers and miles.”

Ness - “Ok, I understand the request and I think I can provide some help. I’ve heard about https://postcodes.io/, and we can use it as web service where we can type the postcode and we get the address details back, alongside the latitude and longitude. As its straight line it should be very easy to calculate the distance between the airport and the customer address.

A working example for the web service is: http://api.postcodes.io/postcodes/N76RS

A few examples of valid postcodes in the UK are:

Index Postcode
#1 N76RS
#2 SW46TA
#3 SW1A
#4 W1B3AG
#5 PO63TD

I think a NodeJS application would be an excellent idea. There are definitely benefits to it but feel free to use other technologies/frameworks. Obviously if you want to use other frontend tools/technologies to help you achieve the work, I’m happy with it, but remember the focus must be as much in having it working as it should to have a good user experience, bonus points if you are able to produce a mockup and explain the reason why you used certain components. It is important the user understands all the functionalities we have to offer and is able to understand them correctly.

Once you are done please commit the code and create a Pull Request so we can code review it.”

Now that the exercise has been explained, you can start working on it, we normally request for it to be uploaded into our git repository within 3 working days, but can be changed if you need more time to start. This task should take you no longer than 3 hours and needless to say should be totally completed by you, after all this is supposed to be a fun challenge!

Backend Solution Proposal

This Rest API build based on Express is the backend proposal to manage different online unsigned clients ( no logging necessary ) making requests with postcodes in order the retrieve their addresses. For each client a 1 hour session is generated, and up to the last three request responses made before are returned for each new request made. Above is the top level architecture of the API.

Top-Level

It was used the pattern Adapter to decouple the use of database and Http Client libraries into the main service, here being available for use the Redis database client and Axios Http client.

The design patterns FactoryMethod and Facade were also used. The concept of Dependency Injection was applied. In addition, it was developed with Automated Tests using the Jest library for the creation, simulation and execution of tests.

The project also has a log service using Winston and Elasticsearch, being possible to view the logs through Kibana. Both are available for development environment through Docker.

Technologies

The project uses the following technologies:
NodeJs
Ts-Node
Typescript
Express
GeoLib
Cors
Winston
Jest
SuperTest
Ts-Jest
Redis
Eslint
Express-Rate-Limit
http-status-codes
Elasticsearch
Kibana
Docker
Config

Main Throughput Solution

Cache-Solution

No only client sessions are been stored in Cache. In order to enhance the throughput capabilities, a cache architecture solution was applied. For every postcode researched on API the first check is if this postcode was researched previously, and if the answer is still save on cache, in this case, Redis. This solution not only give the client a faster answer, but also lower the amount of request made for a third party client. An expiration time of 1 hour was set the development and test proposals, but probably it would be necessary a better tunning in an production scenario.

Installation local environment

  • Make Elasticsearch, Kibana and Redis services available
  $ docker-compose up --build -d
  • ( for WSL environment) You might need to free more space on docker to run Elastic, in this case use the command below and restart the container:
  $  wsl -d docker-desktop
  $  sysctl -w vm.max_map_count=262144
  $  exit
  • The Nodejs Project should be running on Docker now, but if you need to run it outside docker, follow the next instructions

  • To install all project dependencies

  $ npm install
  • Stop the Main Api Container, if it's running

  • To run the project in dev environment

  $ npm run dev

The main API port should be available on the port 80

Use Cases

Routes




postcode-backend-api's People

Contributors

mcesarpl avatar craftsw-rjso avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.