Skip to content

AlexsJones/frontier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

frontier

Go Report Card Maintainability

A very simple golang gorilla http server example with a few useful paradigms. I hope this goes some small way to demonstrate a few useful ideas around create a high performance API.

Requirements

For the example install librdkafka

RUN git clone https://github.com/edenhill/librdkafka.git
RUN cd librdkafka && ./configure --prefix /usr && make \
&& sudo make install

Routing

This example uses sub routers to break down paths as part of versioning API. The sub routers use an irouter interface that adheres them to a few common methods. Having this pattern is useful for loading routes via batch.

The current structure is the following:

Base router ---> /
API router --------> /api
V1 router --------------> /v1

This means using the V1 router within routers/API/v1/router.go is ideal for grouping API to this version.

Data processing

Data processing follows a worker/job via channel over channel to push/pop without delaying requests.

Kubernetes

Includes kubernetes manifests and dockerfile for deployment into a k8s cluster.

Test it out in minikube with ./kubernetes/deploy.sh Then look at the created deployment kubectl get pods --namespace=entrypoint

The example

http This example is a simple GET that returns a 200 You can test it at localhost:8080/api/v1/ping

kafka This example POST checks if the incoming number is prime then sends it to a kafka topic called test with the prime number if it is.

# requires kafka running locally https://kafka.apache.org/quickstart with `test` topic
# run go run main.go
# in another tab run the tests
cd test
go run test.go #Runs the incremental prime tests

Example components

Within the components directory are a few singleton pattern components. The reason they are singletons is to make them completely atomic and rely on ENV settings. This works well in an example where you don't necessarily want to impede the user with initialisation of functionality they don't want or understand - it is kept inside of routes only.

Example code throughput

The example is pretty arbitrary but hopefully demonstrates it is perfectly possibly to process many thousands of requests per second.

Bench marking on a laptop at around 10k RP/S it is easy to imagine that load balancing several frontier API as containers could easily achieve over 100,000 RP/S

Removing example code

To remove the example please remove routers/API/v1/example folder Also remove API/v1/router.go with reference to the example here:

	//Example route to demonstrate processing components
	d.BaseRouter.Router.HandleFunc("/processor", example.ExamplePost).Methods("POST")

About

High performance golang API example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published