All Projects → second-state → dapr-wasm

second-state / dapr-wasm

Licence: Apache-2.0 license
A template project to demonstrate how to run WebAssembly functions as sidecar microservices in dapr

Programming Languages

rust
11053 projects
shell
77523 projects
Makefile
30231 projects

Projects that are alternatives of or similar to dapr-wasm

ocp-flyway-db-migration
Database Migration Sample with Flyway, Docker and Kubernetes in Openshift Container Platform
Stars: ✭ 17 (-89.88%)
Mutual labels:  sidecar
dapr-gbb-workshop
Details regarding the customer-ready Dapr workshop created by the Microsoft Cloud Native Global Black Belt Team
Stars: ✭ 27 (-83.93%)
Mutual labels:  dapr
athenz-client-sidecar
Moved to https://github.com/AthenZ/athenz-client-sidecar
Stars: ✭ 14 (-91.67%)
Mutual labels:  sidecar
management-api-for-apache-cassandra
RESTful / Secure Management Sidecar for Apache Cassandra
Stars: ✭ 50 (-70.24%)
Mutual labels:  sidecar
Mosn
The Cloud-Native Network Proxy Platform.
Stars: ✭ 3,451 (+1954.17%)
Mutual labels:  sidecar
blue-green-with-containerapps
This is a demo scenario for implementing continuous blue/green deployments on containerapps using GitHub actions
Stars: ✭ 43 (-74.4%)
Mutual labels:  dapr
kubernetes-sidecar-injector
Easy Service Mesh with Kong and Kubernetes
Stars: ✭ 20 (-88.1%)
Mutual labels:  sidecar
showcase
A Full Stack Journey with Micro Services and Micro Front Ends. Using dapr, kubernetes, react module federation and web assembly,
Stars: ✭ 45 (-73.21%)
Mutual labels:  dapr
Dapr
Dapr is a portable, event-driven, runtime for building distributed applications across cloud and edge.
Stars: ✭ 16,274 (+9586.9%)
Mutual labels:  sidecar
swir
SWIR - Sidecar Written In Rust
Stars: ✭ 49 (-70.83%)
Mutual labels:  sidecar
spring-cloud-sidecar-polygot
This project contains samples demonstrating the usage of side car polygot
Stars: ✭ 30 (-82.14%)
Mutual labels:  sidecar
k8s-mongo-sidecar
Kubernetes sidecar for MongoDB
Stars: ✭ 35 (-79.17%)
Mutual labels:  sidecar
mongoproxy
Lightweight proxy to collect MongoDb client metrics
Stars: ✭ 26 (-84.52%)
Mutual labels:  sidecar
authorization-proxy
No description or website provided.
Stars: ✭ 31 (-81.55%)
Mutual labels:  sidecar
marin3r
Lightweight, CRD based envoy control plane for kubernetes
Stars: ✭ 51 (-69.64%)
Mutual labels:  sidecar
tailscale-sidecar
A TCP proxy used to expose services onto a tailscale network without root. Ideal for container environments.
Stars: ✭ 87 (-48.21%)
Mutual labels:  sidecar
secret-sidecar
A Kubernetes init container that retrieves a secret from AWS Secrets Manager
Stars: ✭ 24 (-85.71%)
Mutual labels:  sidecar
vault-sidecar-injector
Kubernetes admission webhook for secure, seamless and dynamic handling of secrets in your applications
Stars: ✭ 55 (-67.26%)
Mutual labels:  sidecar
Z370M-ITX-ac-macOS-OpenCore
A working OpenCore configuration and files for ASRock Z370M-ITX/ac
Stars: ✭ 19 (-88.69%)
Mutual labels:  sidecar
sidecache
Sidecar cache for kubernetes applications.
Stars: ✭ 38 (-77.38%)
Mutual labels:  sidecar

Dapr and WasmEdge

Live Demo | Tutorial video

Introduction

This is a template application to showcase how Dapr and WasmEdge work together to support lightweight WebAssembly-based microservices in a cloud-native environment. The microservices are all written in Rust and compiled into WebAssembly. They run inside the WasmEdge Runtime as opposed to Linux containers or VMs for these reasons.

While this demo is done in Rust, WasmEdge can also run Node.js compatible JavaScript applications.

This application consists of 3 microservices and a standalone web page that enables users to interact with the microservices using a HTML+JavaScript UI. It is a very typical JAMstack setup. Each microservice is attached to a Dapr sidecar, which provides a suite of useful services commonly required by cloud-native microservices. The overall architecture is as follows.

Microservices architecture

The Rust version of Dapr SDK for WasmEdge is used to access Dapr sidecars from the microservice apps. Specifically, the grayscale microservice takes an image from an HTTP POST, turns it into grayscale, and returns the result image data in the HTTP response.

  • It uses Dapr to discover and invoke the events microservice to record every successful user request.
  • It also stores each user’s IP address and last timestamp data in its Dapr sidecar’s state database. That allows the service to rate limit users if needed.

The classify microservices takes an image from an HTTP POST, runs a Tensorflow model against it to classify the object on the image, and returns the result as a text label in the HTTP response. You can learn more about AI inference in Rust and WasmEdge here. It uses its own Dapr sidecar the same way as the grayscale microservice.

The events microservice takes JSON data from a HTTP POST and saves it to an external MySQL database for later analysis.

  • It uses Dapr to make itself discoverable by name by other microservices that need to record events.
  • It also uses its Dapr sidecar to store secrets such as the MySQL database credentials.

Now, go ahead and fork this repo. Create and deploy your own lightweight microservices for better security, faster performance, and smaller footprints.

Build and deploy these microservices in Dapr

You will need install the following software toolchain to run these examples.

Start the database and place the connection string in the config/secrets.json file under DB_URL:MYSQL. Next, start Dapr with the following commands.

dapr init

The image grayscale microservice

Build.

cd image-api-grayscale
cargo build --target wasm32-wasi --release
wasmedgec ./target/wasm32-wasi/release/image-api-grayscale.wasm image-api-grayscale.wasm

Deploy.

dapr run --app-id image-api-grayscale \
        --app-protocol http \
        --app-port 9005 \
        --dapr-http-port 3503 \
        --components-path ../config \
        --log-level debug \
	wasmedge image-api-grayscale.wasm

The image classification microservice

Build.

cd image-api-classify
cargo build --target wasm32-wasi --release
wasmedgec target/wasm32-wasi/release/wasmedge_hyper_server_tflite.wasm wasmedge_hyper_server_tflite.wasm

Deploy.

dapr run --app-id image-api-classify \
        --app-protocol http \
        --app-port 9006 \
        --dapr-http-port 3504 \
        --log-level debug \
        --components-path ../config \
        wasmedge-tensorflow-lite wasmedge_hyper_server_tflite.wasm

The events recorder microservice

Build.

cd events-service
cargo build --target wasm32-wasi --release
wasmedgec target/wasm32-wasi/release/events_service.wasm events_service.wasm

Deploy.

dapr run --app-id events-service \
        --app-protocol http \
        --app-port 9007 \
        --dapr-http-port 3505 \
        --log-level debug \
        --components-path ../config \
        wasmedge events_service.wasm

Test

You can use the static web page UI or curl to test the services.

Initialize the events database table.

$ curl http://localhost:9007/init
{"status":true}

$ curl http://localhost:9007/events
[]

Use the grayscale microservice. The return data is base64 encoded grayscale image.

$ cd docs
$ curl http://localhost:9005/grayscale -X POST --data-binary '@food.jpg'
ABCDEFG ...

Use the image classification microservice.

$ cd docs
$ curl http://localhost:9006/classify -X POST --data-binary '@food.jpg'
hotdog is detected with 255/255 confidence

Query the events database again.

$ curl http://localhost:9007/events
[{"id":1,"event_ts":1665358852918,"op_type":"grayscale","input_size":68016},{"id":2,"event_ts":1665358853114,"op_type":"classify","input_size":68016}]

Learn more

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].