1 of 62

Building UIs for Microservices

Ethan Garofolo - wroc_love.rb 2019

2 of 62

Microservices

UIs

3 of 62

Who am I?

  • Ethan Garofolo
  • I help companies use microservices
  • ethan at suchsoftware.com
  • I’m writing a book with The Pragmatic Bookshelf
    • It’s a hands-on walkthrough of building a microservices system.

4 of 62

This is not an “answers” talk

  • Some talks send you home with all the answers
  • Systems are unique
  • This talk is about questions and ideas for how to reason about them

"The scientist is not a person who gives the right answers, [the scientist] is one who asks the right questions.”

Ceci n’est pas un Claude Lévi-Strauss,

mais je ne suis pas artiste.

5 of 62

What I mean by “microservices”

6 of 62

“Monolith” is not a deployment strategy. It’s a data model.

7 of 62

“Monolith” is a data model

id

email

password_hash

subscribed_to_newsletter

role

features_used

“users”

8 of 62

“Monolith” is a data model

identity

subscription

authorization

analytics

id

email

password_hash

subscribed_to_newsletter

role

features_used

“users”

Not cohesive.

4 different domains.

This. Is. MONOLITH!

9 of 62

“Monolith” is a data model

users

products

What are these lines?

10 of 62

Even if it’s on different servers

users

products

What are these lines now?

11 of 62

12 of 62

Even if it’s on different servers

users

products

Say it with me...

13 of 62

Even if it’s on different servers

users

products

Distributed

14 of 62

Even if it’s on different servers

users

products

Distributed

+

15 of 62

Even if it’s on different servers

users

products

Distributed

+

Monolith

16 of 62

Even if it’s on different servers

users

products

Distributed

+

Monolith

=

17 of 62

Even if it’s on different servers

users

products

Distributed monolith

18 of 62

Services are autonomous

19 of 62

Services are autonomous

  • No one asks them for anything (you ask databases for things, and that’s called querying)
  • They don’t ask anyone else for things (otherwise they’re dependent on those other things)
  • They are oblivious to the existence of other things

20 of 62

Services communicate via asynchronous messages

2 flavors

  1. Events
  2. Commands

21 of 62

Events and Commands

Events:

{

‘type’: ‘PEN_DROPPED’,

‘payload’: { ‘some’: ‘such’ }

// ...

}

22 of 62

Events and Commands

Events:

{

‘type’: ‘PEN_DROPPED’,

‘payload’: { ‘some’: ‘such’ }

// ...

}

I am past tense

23 of 62

Events and Commands

Events:

{

‘type’: ‘PEN_DROPPED’,

‘payload’: { ‘some’: ‘such’ }

// ...

}

24 of 62

Events and Commands

Events:

{

‘type’: ‘PEN_DROPPED’,

‘payload’: { ‘some’: ‘such’ }

// ...

}

Commands:

{

‘type’: ‘DROP_PEN’,

‘payload’: { ‘other’: ‘such’ }

// ...

}

25 of 62

Events and Commands

Events:

{

‘type’: ‘PEN_DROPPED’,

‘payload’: { ‘some’: ‘such’ }

// ...

}

Commands:

{

‘type’: ‘DROP_PEN’,

‘payload’: { ‘other’: ‘such’ }

// ...

}

I am imperative

26 of 62

Events and Commands

Events:

{

‘type’: ‘PEN_DROPPED’,

‘payload’: { ‘some’: ‘such’ }

// ...

}

Commands:

{

‘type’: ‘DROP_PEN’,

‘payload’: { ‘other’: ‘such’ }

// ...

}

I am imperative

Invalid

commands

Valid

commands

27 of 62

The events literally are the state of the system

This

Not this

PEN_DROPPED

PEN_PICKED_UP

id

status

1

picked up

28 of 62

Basic shape of a system

29 of 62

The services

[

]

30 of 62

The services

Application

[

]

Message Store

31 of 62

Application

[

]

Read model[s]

The services

Message Store

32 of 62

Application

[

]

Read Model[s]

Aggregators

The Services

Message Store

33 of 62

Application

[

]

Read model[s]

Aggregators

The services

NONE OF THIS IMPLIES IT’S A DISTRIBUTED SYSTEM!

34 of 62

Message stores

35 of 62

Building UIs for this kind of system

36 of 62

Mental models - Kind of like texture maps

37 of 62

Mental models - Kind of like texture maps

38 of 62

Mental models - Kind of like texture maps

?

39 of 62

Don’t wait until you have HTTP forms on top of database tables to consider the UI/UX of a microservices system.

40 of 62

Figure out the desired experience, then figure out the technology

41 of 62

Sometimes nothing is enough

Ignore the async

Possible situations: analytics, when you hate your users

42 of 62

Video view Analytics

  • Display the total number of views
  • No real-time requirement
    • Users don’t care, lag is acceptable
    • We may want to validate views
  • Flow:
    • Application writes view event
    • Aggregator aggregates it
  • Solution:
    • Don’t worry about the async
    • Let it flow!

43 of 62

Stalling for time

A light disguise

Possible situations: user registration, e-commerce order, bank transfer

44 of 62

wow.

such grace.

very bird.

Have you ever watched their legs when they swim?

45 of 62

User registration

  • Need time for background processing
  • Show user that something is happening
  • Flow:
    • Users submit registration
    • Send an email
  • Solution:
    • Present them with a static screen letting them know when next to take action
    • Use expected delay to mask background processing
    • Look like a swan

Submits Registration

Application writes RegisterUser command

“Check your email”

Registration service writes SendEmail command

Email service sends email

46 of 62

Embrace the domain model

Validation is part of the domain model!

Possible situations: Operations that need validation, real-time-ish response

47 of 62

Naming an uploaded video

  • Rules around valid names
  • Those rules live in a service
  • Services process messages asynchronously
  • Flow:
    • Users submit name
    • Service validates name
    • Aggregators aggregate
  • Solution:
    • Embrace evented model
    • DON’T display invalid name to viewers
    • DO show it to owners (so they can fix it)

48 of 62

This is

Mr. Grumpy Pants

49 of 62

CRUDe approach

id

name

etc

884cd10c-32db-4eca-af3b-9c8217700b2e

Lovely name

---

Bad words

50 of 62

CRUDe approach

id

name

etc

884cd10c-32db-4eca-af3b-9c8217700b2e

Lovely name

---

Bad words

STOP

51 of 62

CRUDe approach

id

name

etc

884cd10c-32db-4eca-af3b-9c8217700b2e

Bad words

---

otherwise...

!!1!

*evil laughter*

52 of 62

Better approach

videos-884cd10c-32db-4eca-af3b-9c8217700b2e

VideoUploaded

Bad words

53 of 62

Better approach

videos-884cd10c-32db-4eca-af3b-9c8217700b2e

VideoUploaded

InvalidlyNamed

54 of 62

Different views

Lovely name

VideoUploaded

InvalidlyNamed

55 of 62

Different views

Lovely name

You need to fix that name, bucko.

VideoUploaded

InvalidlyNamed

56 of 62

1. Send name

App

Message store

2. Write command

3. Render response

Publishing service

57 of 62

App

Message store

Publishing service

4. Observe command

Process and validate

5. Write success or failure event

4. Begin polling to see if command processed

Aggregator

6. Observe event and update read model

58 of 62

Naming an uploaded video

  • Event model lets us show different views based on the same data. USE THAT!
  • Feels responsive to the user
  • Knowledge of video publishing localized to video publishing service

59 of 62

Takeaways

  • Waiting until you have CRUD-style UI before thinking through use cases => you’re going to have a bad time
  • Leverage the event model
  • Discuss with your business and UX team
  • Ask the right questions to discover the experience, then the technology solution will reveal itself

60 of 62

More info

  • The Eventide Project - https://eventide-project.org/
    • Reading all about this will give you superpowers in microservices, even if you don’t end up using it. It has me wanting come back to Ruby.
  • My mailing list - https://tinyurl.com/microservices-mailing-list (information about the book will be here)
  • These slides (so I can link this later in Twitter) - https://tinyurl.com/ethan-garofolo-wroclaw-2019

61 of 62

Additional resources

People to follow:

Scott Bellware - https://twitter.com/sbellware

Nathan Ladd - https://twitter.com/realntl

Greg Young on event sourcing - https://www.youtube.com/watch?v=JHGkaShoyNs?t=2062

CQRS in Node - https://www.youtube.com/watch?v=4k7bLtqXb8c

62 of 62

Happy Coding!