Slide 1

Slide 1 text

2022-09-23
 
 フェアリーデバイセズ株式会社
 Fairy Devices Inc.
 1 Rust.Tokyo 2022 スポンサーセッション
 
 フェアリーデバイセズがRustを
 採用して3年が過ぎました


Slide 2

Slide 2 text

About me
 ● Twitter/GitHub: @emergent
 ● Since 2018.9
 ○ Manager of Product Development Dept.
 ● Publication
 ○ 『実践Rustプログラミング入門』共著
 ○ WEB+DB PRESS No.129 (interview)
 ○ WEB+DB PRESS No.131 (plan)
 ○ 技術書典『機械学習の炊いたん』
 2 Satoshi Yoshikawa / 吉川哲史

Slide 3

Slide 3 text

3

Slide 4

Slide 4 text

4

Slide 5

Slide 5 text

5 Company history


Slide 6

Slide 6 text

6 Company history


Slide 7

Slide 7 text

Products @2018-2019
 Audio libraries written in C++ WebSocket server in C++ and the others in Python and TypeScript 7 Tumbler

Slide 8

Slide 8 text

Difficulties with services handling audio
 ● Theoretical and implementation difficulties of audio signal processing, speech recognition, etc.
 ● Difficulties in APIs as a pathway for audio data
 8

Slide 9

Slide 9 text

Difficulties with services handling audio
 ● Theoretical and implementation difficulties of audio signal processing, speech recognition, etc.
 ● Difficulties in APIs as a pathway for audio data
 9 Asynchronous communication of audio stream


Slide 10

Slide 10 text

Handling audio streams
 10 audio application speech recognition Audio stream Client
 Server
 Text


Slide 11

Slide 11 text

Handling audio streams
 11 audio application speech recognition Audio stream Client
 Server
 Text
 Asynchronous


Slide 12

Slide 12 text

Products @2018-2019
 Audio libraries written in C++ WebSocket server in C++ and the others in Python and TypeScript 12 Tumbler

Slide 13

Slide 13 text

Hard to maintain with C++...
 13 Write once in C++, run forever. PIEN CEO / CTO
 Masato Fujino
 ※He didn’t say so, (actually). 


Slide 14

Slide 14 text

Is there the alternative of C++?
 ● Want to increase software quality
 ○ No more segmentation fault
 ● but not at the expense of performance
 
 14

Slide 15

Slide 15 text

There is Rust
 15 https://www.rust-lang.org/

Slide 16

Slide 16 text

Road to use Rust to our products
 1. Write codes in Rust
 2. Write codes in Rust
 3. Write codes in Rust
 4. Say “Rust is good!” to collegues
 5. Say “Rust is good!” to CEO
 6. Say “Rust is good!” to CEO
 7. Say “Rust is good!” to CEO
 8. Write codes in Rust
 9. Write codes in Rust
 10. Write codes in Rust
 16

Slide 17

Slide 17 text

Steps with Rust
 17 Small start
 (microservice)
 Replacement
 New product
 Challenges
 
 ・HTTP server
 ・Connecting Redis
 Challenges
 
 ・WebSocket server 
 ・Connection control 
 Challenges
 
 ・HTTP server
 ・WebSocket API
 ・RDBMS
 ・Lambda function
 ・Layered architecture 


Slide 18

Slide 18 text

Products with Rust
 2019 2020 2021 2022 CATS Backend microservice (small start) Nyaprus Speech Recognition API (replacement) LINKLET (new product) Product development
 Personal activity
 WEB+DB PRESS No.131 Publish Interviewed 18 …and many trivial works in Rust
 Publish(plan)

Slide 19

Slide 19 text

Products with Rust
 2019 2020 2021 2022 CATS Backend microservice (small start) Nyaprus Speech Recognition API (replacement) LINKLET (new product) Product development
 Personal activity
 WEB+DB PRESS No.131 Publish Interviewed 19 …and many trivial works in Rust
 Publish(plan)

Slide 20

Slide 20 text

CATS
 Purpose : to throttle simultaneous connections of APIs
 ● Concurrent Access Throttling System
 ● A simple HTTP server with Redis backend
 20 Application using Actix web Cloud Memorystore (on GCP) HTTP request HTTP response ≒ Redis


Slide 21

Slide 21 text

Architecture
 21 CATS API server 1 API server 2 API server 3 Engine 1 Engine 2 Engine i … … Frontend Backend (speech recognition) CATS

Slide 22

Slide 22 text

Wrote many “Future” functions
 22 … We use async/await since 1.39.0 
 CATS

Slide 23

Slide 23 text

Good points
 ● Operates stably than we thought
 ● High performance and high load capacity
 
 ● …And is contributing our business!
 23 CATS

Slide 24

Slide 24 text

First product in Rust 🎉
 24 CATS

Slide 25

Slide 25 text

Side stories
 ● Actix Web: soon to be version 1.0 or not?
 ● Participated in Rust communities and gatherings.
 ○ “Is anyone familiar with Future anywhere?”
 25 CATS

Slide 26

Slide 26 text

Products with Rust
 2019 2020 2021 2022 CATS Backend microservice (small start) Nyaprus Speech Recognition API (replacement) LINKLET (new product) Product development
 Personal activity
 WEB+DB PRESS No.131 Publish Interviewed 26 …and many trivial works in Rust
 Publish(plan)

Slide 27

Slide 27 text

Nyaprus - Speech Recognition API
 Purpose: add functionality to speech recognition API
 ● A frontend server of speech recognition engine
 ● Has WebSocket API
 ● Using warp 27 I want to use tokio-tungstenite

Slide 28

Slide 28 text

● Replaced from C++ and Java
 ● Implemented
 ○ a WebSocket server
 ○ a proxy server having connection pool
 Implementation
 28 Nyaprus Before
 After
 WS server in C++ SR frontend in Java (proprietary) SR engine (proprietary) WS server in Rust Proxy server in Rust SR engine (proprietary) WS: WebSocket 
 SR: Speech Recognition 


Slide 29

Slide 29 text

Techniques on Rust
 ● trait Stream / Sink ( on WebSocket server )
 ● Connection Pooling ( on proxy server )
 29

Slide 30

Slide 30 text

Stream / Sink
 30 Nyaprus Client
 Nyaprus
 Speech
 Recognition
 Engine
 rx tx sink stream

Slide 31

Slide 31 text

Stream / Sink
 31 Nyaprus Stream
 Stream
 Sink
 Sink


Slide 32

Slide 32 text

Stream / Sink
 32 Nyaprus …and join
 Client
 Nyaprus
 Speech
 Recognition
 Engine
 rx tx sink stream

Slide 33

Slide 33 text

Connection pooling
 Problem
 Recognition speed decreases when disconnected
 due to cache discard in the speech recognition engine
 Solution
 Keep and reuse connections in connection pools
 33 Nyaprus

Slide 34

Slide 34 text

Connection pooling with bb8
 34 Nyaprus ……
 ……
 ……
 Implemented trait


Slide 35

Slide 35 text

Connection pooling with bb8
 35 Nyaprus Set up


Slide 36

Slide 36 text

Proxy - using tokio::io::copy
 36 Nyaprus

Slide 37

Slide 37 text

Good points
 ● First replacement 🎉
 ● To improve development productivity
 ○ Used task runner (cargo-make)
 ○ Used container (Docker, CI/CD)
 ○ Created testing tool (in Rust)
 37 Nyaprus

Slide 38

Slide 38 text

Side stories
 ● Cache problems were discovered just before release
 ○ Prototype implemented in 1 day
 ○ After 2 weeks of testing & brushing up
 ○ Managed to release it! 🎉
 38 Nyaprus

Slide 39

Slide 39 text

Products with Rust
 2019 2020 2021 2022 CATS Backend microservice (small start) Nyaprus Speech Recognition API (replacement) LINKLET (new product) Product development
 Personal activity
 WEB+DB PRESS No.131 Publish Interviewed 39 …and many trivial works in Rust
 Publish(plan)

Slide 40

Slide 40 text

LINKLET (backend)
 ● API backend of LINKLET https://linklet.ai/
 40

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

42

Slide 43

Slide 43 text

Challenges
 ● “Web service” development (for me)
 ● Developed by team with multiple people
 ● Continuous development and release
 43 LINKLET

Slide 44

Slide 44 text

Architecture (part)
 44 api-server Web Frontend notification zoom auth0 tlpf-connector mqtt-connector db-connector Auth0 Zoom Device Controller RDBMS httpclient WebSocket notificaiton HTTP(S) Webhook (HTTP(S)) cipher LINKLET

Slide 45

Slide 45 text

Multiple crates in one workspace
 45 LINKLET

Slide 46

Slide 46 text

Challenges
 ● Asynchronous communication with LINKLET devices
 ○ Taking care of the state of devices
 ■ Power ON / OFF
 ■ Online / Offline
 ○ Non-blocking API
 ■ HTTP and WebSocket (push)
 46 LINKLET

Slide 47

Slide 47 text

Challenges (with Rust)
 ● Wrestling with Diesel (and SQL)
 ● Layered architecture (in progress)
 ○ Using mock (mockall crate)
 ● AWS Lambda function in Rust
 47 LINKLET

Slide 48

Slide 48 text

Advantages in Rust
 ● Refactoring with peace of mind😌
 ○ by
 ■ Compilation errors are well attended
 ■ Interfaces are well typed
 48 LINKLET

Slide 49

Slide 49 text

Steps with Rust
 49 Small start
 (microservice)
 Replacement
 New product
 Challenges
 
 ・HTTP server
 ・Connecting Redis
 Challenges
 
 ・WebSocket server 
 ・Connection control 
 Challenges
 
 ・HTTP server
 ・WebSocket API
 ・RDBMS
 ・Lambda function
 ・Layered architecture 


Slide 50

Slide 50 text

Conclusions
 ● Rust is powerful to create web applications
 ○ But still less than 30% of our total products
 50

Slide 51

Slide 51 text

Futures
 ● Grow our products more with Rust (and modern techs)
 ○ more reliable
 ○ more speedy
 ○ higher performance
 51

Slide 52

Slide 52 text

We are hiring!
 ● Frontend / Backend developer
 ● Device Engineer
 ● Product Manager
 ● …and more
 52

Slide 53

Slide 53 text

We are hiring!
 ● Frontend / Backend developer
 ● Device Engineer
 ● Product Manager
 ● …and more
 53 Please check the job board out!


Slide 54

Slide 54 text

Thank you!
 54

Slide 55

Slide 55 text

No content