OutSystsems User Group Netherlands September 2024.pdf
mail496323
294 views
58 slides
Sep 26, 2024
Slide 1 of 58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
About This Presentation
The slides of both presentations at the September 2024 edition of the Dutch OSUG.
Size: 3.12 MB
Language: en
Added: Sep 26, 2024
Slides: 58 pages
Slide Content
September 2024
How touseGraphQL in
Outsystems
About GraphQL
Overview | Basic concepts | Key components
Integration
How to connect to GraphQL | Best Practices
Demo
Considerations
Q&A
01
02
03
04
05
Performance metrics | Use cases | GraphQL vs REST
GraphQL is a runtime for APIs and query
language that lets clients ask exactly what
they need
Alternative to using REST APIs
query {
books {
title,
author,
year
}
}
GraphQL
Over fetching
Getting back more data than we need
REST API
example.com/books
[
{
"id": "91571854-d196-4470-939f",
"isbn": "978-0060935467",
"title": "The Fellowship of the Ring",
"author": "J.R.R. Tolkien",
"year": 1954,
"genre": "Fantasy",
"publisher": "George Allen & Unwin"
}
]
Under fetching
Getting back less data than we need
REST API
example.com/books/Id
Additional request
example.com/books/id/reviews
{
"id": "91571854-d196-4470-939f",
"isbn": "978-0060935467",
"title": "The Fellowship of the Ring",
"author": "J.R.R. Tolkien",
"year": 1954,
"genre": "Fantasy",
"publisher": "George Allen & Unwin"
}
Single endpoint
The graph object is a building block
GraphQL
example.com/graphQL
query {
books {
title
author
reviews {
rating
}
}
}
Type system
Schema
Resolvers
GraphQL
Abstraction layer
HTTP
Database
Third-party API
Microservice
Client-side Server-side
Select
Insert | Update | Delete
Where | Order By | Limit
Views | Subqueries
Query
Mutations
Arguments
Fragments
GraphQL
Schema definition
First, define your data with a
schema
The schema describes the
shape of the graph and the
data available on it
GraphQL
Resolvers
Next, implement resolvers for
each schema field
Operate at the level of individual
object properties
Load balancers for improved
performance
GraphQL
Query language
Finally, you can interact with the
GraphQL API
The query describes the data
requirements
GraphQL
Data returned
The data is provided as
requested in the query
Payload includes the errors,
providing details about what
part of the query failed and
why
GraphQL
Error
handling
Errors on the
query execution
are split from
HTTP errors
HTTP status shows if the GraphQL
server processed the request, NOT
the success of the query execution
- Returns HTTP200 for all responses,
including errors
- Partial success: Available data and error
details are returned without discarding
the entire response
GraphQL
Consume a
POST REST
method
1
Wrap your
method
2
Use your
integration
3
Query
Operation name
Variables
Authentication
Response
query {
query string...
}
data {
string...
}
Integration
GraphQL IDEs
GraphiQL
GraphQL
Playground
Apollo Studio
Postman
Tools to simplify the process of
writing, testing & debugging
- Schema exploration
- Interactive query building
- Track query execution times
GraphiQL
Best Practices
Abstract your integration
Wrap your method with a server
action:
- Library
- Authentication
- Request
Best Practices
Don’t hardcode your
queries
Use a Backoffice to configure your
queries
-Query string
-Operation name
-Code
Best Practices
Name all operations
Naming isn't required for single
operations but helps with tracing
and debugging
Best Practices
Don’t extend existing
queries
Balancing query reuse is important
for maintainability, but in the long
run, it may not be sustainable
DRY Principle
Best Practices
Fetch what you need, when
you need
Offset-based pagination and limit
to build infinite scroll
Cursor-based pagination for larger
datasets
Fragmented query for rendering
several UI components
synchronously
Demo time
Because seeing is believing
Connecting with GraphQL
Using your connection
GraphQL is 27% faster than REST
Performance Metrics
Reduced
data size
Use Cases
Need to access data from
multiple endpoints?
GraphQL lets you gather it all in a single call
1
Building complex solutions that
are user-story driven?
GraphQL asks the server to get only what
the client needs
2
Dealing with many external
sources?
GraphQL can provide a consistent pathway
to access it all
3
Building mobile apps?
GraphQL allows you to have control on the
data transferred over the network
4
Is your API simple, with clear
endpoints and few data types?
Stick to REST if you want well-documented,
easy-to-understand APIs
5
Does your solution depend a lot
on caching?
REST endpoints are stateless and
predictable, which simplifies caching
6
It’s a wrap…
Which one fits best?
Q&A
Thanksforyourtime
WELCOME
Event-Driven
Architecture
in OutSystems
ODC
OSUG
September 2024
Basics
Concepts
What’s under the hood?
In Practice
01
02
03
Best ways to implement EDA… and its challenges
What is it?
Working with Events in ODC & Demo
Q & A
04
05
Basics
Modularity: a global trend
6
microservices vs. monolith
Producing events
in the system where something has just changed
- a user action, a sensor reading, a database update, a trigger from an external system, …
Event-Driven Architecture is about
Detecting events
in an intermediary (router) system
-Collects data about the event and dispatches to the handlers
Reacting to events
by systems “curious” about a particular change in another system
- Doesn’t listen to the changed system directly, but rather the “change dispatcher”
7
OutSystems already applies event-driven architecture in many aspects.
•We trigger events in blocks to notify the parent screen that something has changed
•With RWA, we have client-side event handlers such as OnInitialize, OnReady, OnRender, OnDestroy, OnParametersChanged,
OnAfterFetch, OnAppReady... triggered when a change with UI blocks or data occurs
Sounds familiar?
8
Concepts
Coupled services respond synchronously to
sequential updates
Coupled services, sequential updates
User purchases a concert ticket online
Their seat is reserved at the venue
The order details are mailed to the user
Courier company is notified for physical tickets
Earned extra points in loyalty program
All steps should run without an issue for the
operation to complete
10
Decoupled services respond asynchronously to events
Decoupled services, event-driven updates
User purchases a concert ticket online
This triggers an update to different systems
Courier company is notified for
physical tickets
Mailing system is notified
Loyalty system is notified
Allows flexibility, scalability and
real-time responsiveness
11
Venue reservation
logic is executed
Message router
Handler_ReserveSeat
GUID, GuestID, EventID
Handler_AddPointsToGuest
GUID, GuestID, EventID
Handler_SendConfirmationEmail
GUID, GuestID, EventID
Handler_NewCourierRequest
GUID, GuestID, EventID
TicketPurchasedAm I ESB?
Event-Driven Communication
Event notification = publish-subscribe (pub-sub)
Brings publishers together with
subscribers
Downstream event-driven activity by
reacting to subscriptions
Publishes an event as a result of
an action
12
Event channel
Event consumer
Event producer
Event processing engine
•Senses a change and represents the change as an event message
•Agnostic of consumers
•Unique event IDs & timestamps, immutable events
•A producer system can also be the consumer of another system in a chain
Producer
13
Publishes an event as a result of
an action
Event producer
a.k.a. Broker, Broadcaster, Router, …
•Mechanism of propagatingthe collected events, or just streaming
•Multiple asynchronous event channels
•Can be any type of input (XML, JSON etc.) as long as agreed upon
•Message queue systems such as Apache Kafka, AWS Lambda, RabbitMQ (in O11), NATS (in ODC)
•Events are stored in a message queue, waiting to be processed later by the event processing engine
•Should have high observability (robust logging, monitoring, tracing)and good documentation
•Can be expanded to act as an Enterprise Service Bus, for sharing more data bi-directionally
Channel
14
Brings publishers together with
subscribers
Event channel
Event processing engine
•Reacts asynchronously: receive order might not be the same as produced order
•Good to have internal event management
•Free to process at its own pace; can do non-real-time processing, too
•Idempotent(same results for the same/duplicate messages received)
•Can trigger an event as a result of handling another event(chain of events)
Consumer
15
Downstream event-driven activity by
reacting to subscriptions
Event consumer
In
Practice
Designing Services & Events
Three levels to Service-Oriented Architecture (SOA)
1.Identify components
2.Define conversations between them (events & handlers)
3.Identify linking concepts (keys, IDs) across multiple services
17
Do event storming with business to figure out domain events of a business process
(with post-its on the wall)
•Clearer domain and event definitions
•Promotes more independent and atomic teams
•Reveals complexity of the ecosystem and individual domains
Advantages
•Flexibility: decoupled nature makes it more adaptable
•Can scalesystems horizontally
•Asynchronouscommunication
•Agility: no custom code for polling, filtering or routing events; standard schemas
•Real-time responsiveness (especially visible in frontends)
•Monitor & Configurewith easeand in detail
•Fault tolerance: Retry or re-route mechanism in event broker
•Fail independently
18
Challenges
•Possible microservices overload, deadlocks
•Data inconsistency risk: independent transactions need rollback mechanisms
•Security concerns
•Latency risk
•Complex event chains
•Event schema evolution
•More complex deployments, monitoring, debugging and error handling
•Extra layer for message routing; which team is responsible for it?
•Maintenance overhead
19
Evaluate if it make sense to start with microservices & EDA!
Working with
Events in ODC
& Demo
The 2 business use caseswe solved
1.As a direct replacement for Light-BPT: near real-time, asynchronous execution of business logic, manipulating
considerable amounts of data (order lines).
Whenever data is created/updated via an exposed REST API, the application needs to run a set of validations
based on specific business rules.
2.Publisher/subscriber (pub/sub) model: one application exposes a public event, letting consumer applications
handle it as they see fit.
As the order lines transition between the different possible statuses, the application needs to keep a detailed
logging of those transitions.
21
ODC Application 1
Use case 1 – Implementation Details
22
Create task
Task Type
Get tasks
Trigger event
1 2 3
Implements
business logic
ODC Application 1
Use case 2 – Implementation Details
23
Declares public event
Triggers event
ODC Application 2
Consumes public event
Implements event handler
Lessons learned
●Handle transactions carefully.
●Be careful with large text inputs, as there's a 2000-character limit.
●Be aware of event timeouts (2 minutes only).
●Debugging can be tricky.
●Out-of-the-box logging is limited, so you might need to add custom logging.
●Always handle exceptions in your event handlers.
24
Comparison with BPT in O11
BPT (Processes) in O11
Human & automatic act., wait, conditional start, decision
Light BPT can have max 20 threads per FE by default
Light BPT timeout is 3 mins
Possible to automatically trigger an event with a
database create operation
25
Events for Light BPT and Workflows for BPT in ODC
Only human & automatic activities, decisions (in Workflows)
No instance limit with Events
Events timeout is 2 mins
We need to trigger an Event manually after each operation