• Stars
    star
    275
  • Rank 149,796 (Top 3 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 3 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A template project to demonstrate how to run WebAssembly functions as sidecar microservices in dapr

Dapr and WasmEdge

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. The detailed steps are shown in the GitHub Actions script.

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
wasmedge compile ./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
wasmedge compile 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 wasmedge_hyper_server_tflite.wasm

The events recorder microservice

Build.

cd events-service
cargo build --target wasm32-wasi --release
wasmedge compile 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

More Repositories

1

wasmedge-quickjs

A high-performance, secure, extensible, and OCI-complaint JavaScript runtime for WasmEdge.
JavaScript
487
star
2

wasm-learning

Building Rust functions for Node.js to take advantage of Rust's performance, WebAssembly's security and portability, and JavaScript's ease-of-use. Demo code and recipes.
Rust
430
star
3

SOLL

SOLL is a new compiler for generate Ewasm from solidity and yul. See a demo here: https://asciinema.org/a/ezJqNLicn5fya02zwu4VXIo8a
C++
376
star
4

buidl

A browser-based IDE for creating, deploying, and sharing blockchain apps (DApps, or decentralized apps). Publish your first blockchain DApps in 5 minutes! Here is how: https://docs.secondstate.io/buidl-developer-tool/getting-started
Vue
364
star
5

microservice-rust-mysql

A template project for building a database-driven microservice in Rust and run it in the WasmEdge sandbox.
Rust
346
star
6

smart-contract-search-engine

Takes a link to a smart contract's raw ABI file and an RPC URL and then indexes all instances of that smart contract
JavaScript
267
star
7

WasmEdge-WASINN-examples

Rust
237
star
8

LlamaEdge

The easiest & fastest way to run customized and fine-tuned LLMs locally or on the edge
Rust
206
star
9

wasmedge-nodejs-starter

A template project to run Rust functions in Node.js through the Second State WebAssembly engine.
JavaScript
158
star
10

rustwasmc

Tool for building Rust functions for Node.js. Combine the performance of Rust, safety and portability of WebAssembly, and ease of use of JavaScript.
Rust
129
star
11

how_to_deploy_uniswap

Detailed instructions on how to deploy Uniswap on an Ethereum compatible blockchain
JavaScript
124
star
12

chat-with-chatgpt

Chat with ChatGPT via GitHub issue comments.
111
star
13

WasmEdge-go

The GO language SDK and API for WasmEdge
Go
107
star
14

vercel-wasm-runtime

A template project for building high-performance, portable, and safe serverless functions in Vercel.
JavaScript
81
star
15

wasmedge-containers-examples

Shell
71
star
16

wasmedge_wasi_socket

A Rust lib for socket on WasmEdge.
Rust
70
star
17

meetups

70
star
18

rust-by-example-ext

Rust by Example -- Extended Edition
Dockerfile
64
star
19

lity

A rule-based contract-oriented high-level language.
C++
56
star
20

wasm-joey

Serverless Wasm - A lightweight Node.js application for deploying and executing WebAssembly(Wasm) binary-code via HTTP
JavaScript
54
star
21

ssvm-deno-starter

A template project to run Rust functions in Deno through the Second State WebAssembly engine.
Dockerfile
53
star
22

SewUp

A library to help you sew up your Ethereum project with Rust and just like develop in a common backend
Rust
52
star
23

rust-wasm-ai-demo

Rust functions for Tensorflow inference in Node.js. Rust's performance, WebAssembly's security and portability, and Javascript's ease-of-use.
Dockerfile
49
star
24

WasmEdge-go-examples

Go
46
star
25

recrypt-as-a-service

An open key management service to support privacy-first and scalable file sharing.
Rust
46
star
26

learn-rust-with-github-actions

Getting started with the Rust programming language using this VSCode and GitHub Actions template.
Dockerfile
46
star
27

aws-lambda-wasm-runtime

A template project for building high-performance, portable, and safe serverless functions in AWS Lambda.
JavaScript
44
star
28

wasmedge-seL4

Integrate WasmEdge with seL4
Shell
42
star
29

dapr-sdk-wasmedge

An experimental Dapr SDK in Rust. It is designed to run in WasmEdge applications.
Rust
41
star
30

MEGA

Make ETLs Great Again!
Rust
40
star
31

tencent-tensorflow-scf

A template project for serverless functions for Tensorflow inference on Tencent Cloud.
HTML
38
star
32

simple-staking-smart-contract

A smart contract which allows users to stake and un-stake (after a set period of time) a specified ERC20 token.
Solidity
38
star
33

wasm32-wasi-benchmark

C++
35
star
34

WebAssembly-landscape

The current development of WebAssembly
34
star
35

rust-examples

Simple Rust applications that run in WasmEdge
Rust
32
star
36

wasmedge-rustsdk-examples

Rust
31
star
37

tencent-scf-wasm-runtime

ๅŸบไบŽ WebAssembly ๅฎนๅ™จ้•œๅƒ็š„้ซ˜ๆ€ง่ƒฝ่…พ่ฎฏไบ‘ๅ‡ฝๆ•ฐๅผ€ๅ‘ๆจก็‰ˆใ€‚A template project for building high-performance, portable, and safe serverless functions in Tencent Serverless Cloud Functions.
JavaScript
29
star
38

crunw

Add WasmEdge support to crun so that Docker and k8s tools can manage WasmEdge runtimes side by side with Docker-like application containers.
C
29
star
39

wasmedge-bindgen

Let WebAssembly's exported function support more data types for its parameters and return values.
Rust
29
star
40

wasmedge_tensorflow_interface

Rust
20
star
41

kubecon-eu-2023

20
star
42

substrate-ewasm

A substrate runtime module library (SRML) for Etherem flavored WebAssembly (ewasm)
18
star
43

runw

C++
18
star
44

simple-timelock-smart-contract

A simple timelock smart contract which locks ERC20 tokens for a specific time period and then allows users to unlock when that time period has elapsed
Solidity
17
star
45

netlify-wasm-runtime

A template project for building high-performance, portable, and safe serverless functions in Netlify.
JavaScript
16
star
46

rust-ssvm

Use EVMC binding SSVM and host written in Rust
Rust
15
star
47

serverless-reactor-starter

Rust
15
star
48

hugo-website

A no-code, no-software and no-cost solution to publishing sophisticated web sites managed by non-technical people.
HTML
15
star
49

witc

wasm-interface-types supplement & compiler of wasmedge
Haskell
13
star
50

ssvm-napi

SSVM Node.js Addon
C++
12
star
51

WasmEdge-tensorflow

C++
12
star
52

AI-as-a-Service

Rust
12
star
53

OCR-tesseract-on-Centos7

How to install and use tesseract OCR on Centos7 - without root access
11
star
54

interest-earner-smart-contract

A Solidity smart contract which allows users to stake, earn and un-stake.
Solidity
10
star
55

linear-timelock-smart-contract

Solidity smart contract which disburses ERC20 tokens linearly, over a specific period of time (all values are dynamic and are set by the contract owner)
Solidity
10
star
56

substrate-wasmedge

Substrate on WasmEdge
Rust
10
star
57

ssvm-tencent-starter

Shell
9
star
58

nodejs-helper

Rust
9
star
59

WasmEdge-tensorflow-tools

C++
9
star
60

llm-web-api-server

Rust
8
star
61

wasm-llm

Python
6
star
62

WasmEdge-evmc

Second State WebAssembly VM for EVMC Extension
C++
6
star
63

wasmedge-core

WasmEdge Node.js Addon
C++
6
star
64

wasmedge_plugin_rust_sdk

Rust
5
star
65

tencent-meme-scf

HTML
5
star
66

chatbot-ui

TypeScript
5
star
67

WasmEdge-image

C
5
star
68

qdrant-rest-client

A lightweight Qdrant client library for Rust
Rust
4
star
69

llm_todo

Python
4
star
70

wasmedge-mysql

A repository which provides a MySQL persistent storage solution for the WasmEdge runtime
JavaScript
4
star
71

SSVMRPC

A Remote Procedure Call (RPC) implementation which facilitates both code-deployment and code-execution interactions with SecondState's stateless Virtual Machine (SSVM)
Rust
4
star
72

opendapps

HTML
4
star
73

ssvm-napi-extensions

C++
4
star
74

micro-slots

Storing and accessing multiple integer values in Ethereum, using only one single uint256 slot
Python
4
star
75

libeni

Official C++ implementation of libENI, which is part of the Lity project.
C++
4
star
76

serialize_deserialize_u8_i32

A Rust library that safely converts, back and forward, between u8 and i32
Rust
3
star
77

tencent-ocr-scf

Serverless functions for OCR on Tencent Cloud.
HTML
3
star
78

ssvm-tencent-tensorflow

HTML
3
star
79

wasmedge_hostfunctionexample_interface

This is an example to create a host function interface for calling the WasmEdge internal host functions.
Rust
3
star
80

wasmmark

JavaScript
3
star
81

wasmedge-extensions

WasmEdge for Node.js Addon with extensions
C++
3
star
82

server-side-wasm-video-editing

An example of how to build a third-party application that uses SecondState's Wasm VM to edit video on the server side. This prototype shows how video can undergo frame-by-frame, pixel-by-pixel processing using native Wasm data only i.e. pixel as i32
HTML
3
star
83

docai-hf-rs

Document AI for WasmEdge
2
star
84

linkerd-wasm

A template project to run WebAssembly functions as microservices in Linkerd
2
star
85

wasmedge_process_interface

Rust
2
star
86

rfq-marketplace

Rust
2
star
87

WASI-NN-GGML-PLUGIN-REGISTRY

This is a registry project for storing all released WasmEdge WASI-NN GGML plugin with different llama.cpp versions.
2
star
88

linear-timelock-user-interface

Interface for LinearTimelock.sol smart contract
JavaScript
2
star
89

rust-faas-showcases

HTML
2
star
90

rust_native_storage_library

A library which compiles to `.so` and `.dylib` and facilitates the native storage (and retrieval) of key:value pairs on the host system
Rust
2
star
91

WasmEdge-storage

Second State WebAssembly VM for Rust Storage Extension
C++
2
star
92

simple-timelock-user-interface

A user interface for the simple timelock smart contract
JavaScript
2
star
93

WasmEdge-paratime

An Oasis Paratime using WasmEdge
Rust
2
star
94

SSVMContainer

A Rust application that sits between incoming requests from the network and the SSVM. This application handles the deployment of Wasm applications and manages the execution of services (callable functions inside the Wasm application). The actual execution takes place inside the SSVM. The SSVM is a stack-based Virtual Machine which is stateless. This SSVMContainer application is responsible for fielding incoming deployments and service calls as well as storing application state.
HTML
2
star
95

wasmedge_rustls_api

Rust
1
star
96

libsql_wasi_nn

Rust
1
star
97

haiku-connector

Haiku Connector Runner
Rust
1
star
98

wasmedge_hyper_rustls

A crate similar to rustls-hyper for wasi.
Rust
1
star
99

wasmedge_asyncify

Rust
1
star
100

interest-earner-user-interface

A user interface for the interest earner smart contract
JavaScript
1
star