Coder Social home page Coder Social logo

spikes's Introduction

Spikes

Some spike stuff in preparation of the final solution to the Note product that will be the backend for one or more Miruvor SaaS offerings.

CodeCov GitHub Actions

Event Sourced

Is the way of working for Spikes. It's an extension of event driven:

Request -> Command -> Event -> Entity -> Response
  1. Request is the instruction from the outside world to perform some task, but not yet a Command,
  2. After a Request is validated as suitable for a Command, it is transformed into a Command and the callback actor is added,
  3. An EventSourcedBehavior handles a Command and checks if the current State is suitable for the Command to be processed,
  4. If 3 is okay, then the Command is transformed into an Event, persisted and the State is updated accordingly,
  5. The Event and the State are used to update that State into a new State with the Entity from the Event,
  6. The requester from step 1 is informed about the result of steps 2..5 in the form of a http status code and the Response from the Entity.

Requests are either a Create, Update or Delete instruction with the required data. Queries are defined later and return a response of the required entity or a list of these responses.

Architecture

From the above and with Akka Persistence we get an architecture that is basically a Handlers container with a Command Handler and an Event Handler:

request via akka-http-route -> 
  validator -> 
  command-handler ->
    event-handler &
    respond with updated state to requestor

to the outside world, this seems like the ubiquous http request -> response way of working.

Akka Persistence is responsible for persisting the events created by the command handler. And Akka persistence will replay the previously persisted events on (re)startup of a Persistent Actor (actually Behaviour, but I still like Actor better).

The validator and the reply to requestor is the reason for the Request instead of the requestor just sending a Command.

Tech Stack

See Implementing µ-services with Akka

Sources

Infrastructure

Inspiration

The initial idea was to build a simple note-taking backend. Gradually some new features crept in, such as Tasks, Events and Log/Journal entries. That scope-creep led to the idea of creating a simple CRM system, with Users logging their activities with Employees of Companies. This backend will focus on storing the data created by the users in a traceable, retrievable and recoverable way. The integration with email and other external systems is not included yet.

In the end I produced a simple note-taking backend. All aspirations for more functionality seem over the top at the moment. With the current implementation of Note all the considered extra's can be implemented at the frontend.

Development

Test Coverage

sunburst

k8s

ConfigMap

kubectl create configmap name --from-literal=SECRET_KEY=$ENV_VAR --from-literal=OTHER_SECRET_KEY=$OTHER_ENV_VAR

see k8s docs

Stuck namespaces

See SO

deploy to k8s

First, enable necessary k8s services: dns, ingress and cert-manager.

As I am using microk8s at the moment, this is as easy as

microk8s enable dns, ingress, cert-manager

on one of the k8s cluster nodes.

In folder /k8s in this project there are 5 YAML files. Apply these as:

  1. cluster-issuer.yaml
  2. microbot-ingress.yaml
  3. service.yaml
  4. deployment.yaml
  5. spikes-ingress.yaml

Truth

The real reason I had to pick Cassandra as a database is that the Astra offering is extremely cool for small projects like this. it's been free for me due to very limited traffic can storage size. But Cassandra is not relational. Not that I like relational databases. Not at all. But that type of database is convenient as there is a lot of experience, including my own, with rdbms's and orms. I also do not like orms. So, what's a good solution that can use C*? Event Sourcing :-).

That is the real reason for choosing this rather exotic setup. But after a while I really love Event Sourcing!! It's unbeatable for growing a backend service. It's unbeatable for separating concerns and as a basis for growth.

Only thing I haven't figured out yet is scalability: I don't see how I can combine the advantages of ES with clustering. Clustering is a great method to guarantee uptime, for instance when a Kubernetes pod with one of the nodes of the app cluster goes down unexpectedly. Rolling updates is possible with one node, so that's covered by k8s.

Note that CQRS is never mentioned in this document. It is considered to be one of the pillars of Event Sourcing, but I don't see what's so great about it. So, no segregation yet. Maybe when there is an actual need. Also, I find a Single Place of Truth (SPoT) essential: having State of an actor at one place and the Read-side of CQRS at another is begging for disaster as soon as the programmer (me) forgets about updating logic in both places. This is one of those instances where DRY is actually useful and good.

ToDo

  1. Comments, mainly in a Router
  2. Tags (CRUD, tags cloud)
  3. External QA and Performance tests

Tips

GitHub Container Repository (GHCR)

Retrieve list of tags for the Spikes image:

curl -H "Authorization: Bearer ${GHCR_TOKEN}" https://ghcr.io/v2/jvorhauer/spikes/tags/list

Use sbt jibImageBuild to create that image.

Use git checkout tags/vM.M.P to check out a specific tag before calling jib to create an image of a specific release tag.

spikes's People

Contributors

jvorhauer avatar

Stargazers

 avatar

Watchers

 avatar  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.