SlideShare a Scribd company logo
Service Architecture Patterns
Avinash Chugh
Vivek Singh
Rohith Rajagopal
Designs are neither good nor bad.
They are more or less useful.
Martin Fowler
Service = SOA service
External Interface
Interface contracts
Maps service contracts to/from domain entities
Interacts with DDD services
Cross functional responsibility
Service Architecture patterns
SOA
Services
Services
Mappers
Service
Contract
Persistence
Mappings
Repositories
get client
requests as
request/response with
domain objects
Factories Entities
Value
Objects
Aggregates
Domain
Model
find domain objects
orchestrates
business logic
read/write
data source
send request contract to
find/save domain objects
Service = DDD Service
Core business logic
Orchestrates domain layer
Reusable within a SOA service
Simple Banking Application
Customer(1)----(*)Account(1)----(*)Transaction
Opening an account
View transactions across accounts
Account Summary
Customer Profile
Perform transaction
Service Architecture patterns
Service Responsibility Partition
Breaking system into different services
Minimal Distributed System
Architecture
Services
Database
User
Interface
Application
Grows to monolithic services
Single database
Everything gets deployed every time
Test everything every time
Need for smaller sub-systems
Database
Domain
Model
Service A
Database
Domain
Model
Service B
Database
Domain
Model
Service C
Database
Domain
Model
Service D
Data Ownership Driven Services
Advantages
Development decoupling
Independent evolution
Deployment independence
Low testing cost
Disadvantages
Inner loop problem/N+1 problem
Database
Domain
Model
Account
Service
Database
Domain
Model
Transaction
Service
Customer
Acc 1
Acc2
Acc4
Acc3
Txn1
Txn2
Txn3
Txn1
Txn5
Txn1
Txn2
Txn1
AccountService calling TxnService
GetTransactions(acc1)
GetTransactions(acc2)
GetTransactions(acc3)
GetTransactions(acc4)
Batch Request Interface
GetTransactions(acc1, acc2, acc3, acc4)
Use correlation ids instead of order
Doesn’t solve all problems
Transaction Atomicity
Database
Domain
Model
Service A
Database
Domain
Model
Service C
Customer
New
Acc
Txn1
Transaction
No transaction between service operations
Distributed transaction has performance issues
Database
Domain
Model
Service A
Domain
Model
Service C
Domain
Model
Service B
Domain
Model
Service D
Shared Data Services
Database Database
Advantages
Easier resolution of performance issues
Transaction support
Development still quite independent
Disadvantages
Unclear domain boundaries
Fuzzy ownership of data
Code duplication across services
Tradeoffs
Code duplication
Model duplication
Transactions
Service Independence
Performance
Data Ownership
vs
Service Architecture patterns
Service Contract Design
By design & not by side-effect
Service is a product
Contract is user interface for service
Can help in multi-version capability
Banking application contract
class OpenAccountRequest
{
int CustomerId;
DateTime StartingDate;
AccountType AccountType;
Name AccountHolderName;
}
class Name
{
string FirstName;
string LastName;
}
enum AccountType
{
Savings,
Current
}
class OpenAccountRequest
{
string CustomerId;
string StartingDate;
string AccountType;
Name AccountHolderName;
}
class Name
{
string FirstName;
string LastName;
}
class OpenAccountRequest
{
int CustomerId;
DateTime StartingDate;
AccountType AccountType;
Name AccountHolderName;
}
class Name
{
string FirstName;
string LastName;
}
enum AccountType
{
Savings,
Current
}
Possible starting dates
03/11/2010
03/11/10
03-11-2010
03-11-10
03-Nov-2010
3-Nov-10
Possible customer id
008675100004664
100004664
8675100004664
CC008675100004664
Service
Serve as much as possible
class OpenAccountRequest
{
string CustomerId;
string StartingDate;
string AccountType;
string AccountHolderFirstName;
string AccountHolderLastName;
}
class OpenAccountRequest
{
string CustomerId;
string StartingDate;
string AccountType;
Name AccountHolderName;
}
class Name
{
string FirstName;
string LastName;
}
Business doesn’t understand objects
….and definitely not class inheritance
class OpenJointAccountRequest : OpenAccountRequest
{
int AccountNumber;
}
class OpenAccountRequest
{
string CustomerId;
string StartingDate;
string AccountType;
string AccountHolderFirstName;
string AccountHolderLastName;
}
class OpenAccountRequest
{
string CustomerId;
string StartingDate;
string AccountType;
string AccountHolderFirstName
string AccountHolderLastName
string JointAccountNumber;
}
Use flat structure, no nested objects
Nested objects only when using list
Business Readable Contract
Service operations are not methods
public interface PaymentGatewayService
{
bool Authorize(string cardNumber, string verifiedByVisaPassword);
bool Validate(string cardNumber, string holderName, string cvv);
bool PerformTransaction(string cardNumber, string holderName, string cvv, decimal amount
}
interface PaymentGatewayService
{
CreditCardPaymentResponse Process(CreditCardPaymentRequest request);
}
class CreditCardPaymentRequest
{
string CardNumber;
string CVVNumber;
string VBVPassword;
string HolderName;
string Amount;
}
class CreditCardPaymentResponse
{
string ErrorCode;
string ErrorDescription;
string TransactionReferenceNumber;
}
No parameters/return-value/exception
Service Architecture patterns
Late Binding over Fail fast
Service side validation over schema validation
Loose types over strong types
Error message over system exceptions
Also useful in versioning
Service Architecture patterns
Decouple Domain Entities
and Service Contract
Web Services
Database
User
Interface
Application
Data
Transfer
Objects
UI Model
Domain
Model
Extremely Common Architecture
OR
Mapping
objects
Writing different data definition and
mapping them
Can be quite tedious and error prone
What can we do?
Web Services
Database
User
Interface
Application
Data
Transfer
Objects
UI Model
Domain
Model
OR
Mapping
objects
Hibernate
How about?
Web Services
Database
User
Interface
Application
Domain
Model
Domain
Model
Domain
Model
Hibernate
Data
Transfer
Objects
UI Model
Shared Domain Model
public class Customer
{
int id;
Name name;
int age;
IList<Account> accounts;
}
public class Account
{
int id;
string number;
DateTime openingDate;
DateTime closingDate;
decimal balance;
IList<Transaction> transactions;
}
public class Transaction
{
int id;
DateTime date;
decimal amount;
TransactionType type;
}
public enum TransactionType
{
Credit,
Debit
}
public class Name
{
string first;
string middle;
string last;
string title;
}
Domain
Model
public class Customer
{
int id;
string firstName;
string middleName;
string lastName;
string title;
int age;
}
public class Customer
{
int id;
Name name;
int age;
}
public class Name
{
string first;
string middle;
string last;
string title;
}
Domain Model
Contract
Can tolerate this
public class Customer
{
string id;
string firstName;
string middleName;
string lastName;
string title;
string age;
}
public class Customer
{
int id;
Name name;
int age;
}
public class Name
{
string first;
string middle;
string last;
string title;
}
Contract
…even this
Domain Model
public class Customer
{
int id;
int customerId;
string firstName;
string middleName;
string lastName;
string title;
int age;
}
public class Customer
{
int id;
int customerId;
string firstName;
string middleName;
string lastName;
string title;
int age;
}
Contract
Encapsulate service internals
Domain Model
public class Customer
{
public string CustomerId { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string Title { get; set; }
public string Age { get; set; }
}
public class Customer
{
int customerId;
string firstName;
string middleName;
string lastName;
string title;
int age;
}
Encapsulate Domain Model
Contract
Domain Model
public class Customer
{
public string CustomerId { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string Title { get; set; }
public string Age { get; set; }
}
public class Customer
{
int id;
int customerId;
Name name;
int age;
}
public class Name
{
string first;
string middle;
string last;
string title;
Too much mismatch
Contract Domain
Model
Bad contract and domain
public class CustomerService
{
private readonly CustomerRepository customerRepository;
public CustomerService(CustomerRepository customerRepository)
{
this.customerRepository = customerRepository;
}
public Customer Get (CustomerServiceRequest request)
{
try
{
return customerRepository.LoadCustomer(request. Identification);
}
finally
{
customerRepository.Dispose();
}
}
}
Simple Service Implementation
public class Customer
{
Name name;
int age;
}
public class Customer
{
Name name;
IList<Account> accounts;
}
public class Account
{
decimal balance;
IList<Transaction> transactions;
}
public class Transaction
{
int id;
DateTime date;
decimal amount;
TransactionType type;
}
public class Customer
{
Name name;
IList<Account> accounts;
}
public class Account
{
string number;
decimal balance;
}
Customer Profile
Accounts Summary
Transactions Since
No control over data sent
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping >
<class name="Customer" table="Customers" lazy="true">
<id name="Id">
<column name="Id" not-null="true" />
<generator class="identity" />
</id>
<bag name="accounts" lazy="true" cascade="all-delete-orphan" access="field">
<key column="CustomerId" />
<one-to-many class="Account"/>
</bag>
</class>
<class name="Account" table="Accounts" lazy="true">
<id name="Id">
<column name="Id" not-null="true" />
<generator class="identity" />
</id>
</class>
</hibernate-mapping>
Serializing lazy domain object
Create
Session Load
Customer
Return
Customer
Close
Session
Get
Customer
Customer
Response
Lazy entities not loaded
Account 2
Id
Balance
Account 1
Id
Balance
Customer
Id
Name
Age
hacks…
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping >
<class name="Customer" table="Customers" lazy=“false">
<id name="Id">
<column name="Id" not-null="true" />
<generator class="identity" />
</id>
<bag name="accounts" lazy=“false" cascade="all-delete-orphan" access="field">
<key column="CustomerId" />
<one-to-many class="Account"/>
</bag>
</class>
<class name="Account" table="Accounts" lazy=“false">
<id name="Id">
<column name="Id" not-null="true" />
<generator class="identity" />
</id>
</class>
</hibernate-mapping>
isn’t this smart
public Customer Get(CustomerIdentification customerIdentification)
{
try
{
Customer customer = customerRepository.LoadCustomer(customerIdentification);
ForceLoad(customer);
return customer;
}
finally
{
customerRepository.Dispose();
}
}
private void ForceLoad(Customer customer)
{
customer.ToString();
customer.Accounts.ForEach(account => account.ToString());
//.....so on
}
no…may be should have used
reflection
Tradeoffs
Code reuse
Less code
Mapping simplicity
Design compromise
Decoupling
Control serialized data
Performance
vs
Service Architecture patterns
Thank you!

More Related Content

Viewers also liked (9)

PDF
Agile, architecture and architects
Vivek Singh
 
ODP
Simple design/programming nuggets
Vivek Singh
 
PPTX
Effective use of time
Vivek Singh
 
PPTX
Product over project
Vivek Singh
 
PPT
Small is beautiful
Vivek Singh
 
PPT
Bahmni Introduction
Vivek Singh
 
PDF
Bahmni, Scaling in multiple countries
Vivek Singh
 
PDF
EIT-Digital_Annual-Report-2015-Digital-Version
Edna Ayme-Yahil, PhD
 
PDF
Structured Approach to Solution Architecture
Alan McSweeney
 
Agile, architecture and architects
Vivek Singh
 
Simple design/programming nuggets
Vivek Singh
 
Effective use of time
Vivek Singh
 
Product over project
Vivek Singh
 
Small is beautiful
Vivek Singh
 
Bahmni Introduction
Vivek Singh
 
Bahmni, Scaling in multiple countries
Vivek Singh
 
EIT-Digital_Annual-Report-2015-Digital-Version
Edna Ayme-Yahil, PhD
 
Structured Approach to Solution Architecture
Alan McSweeney
 

Similar to Service Architecture patterns (20)

PPT
introduction to Windows Comunication Foundation
redaxe12
 
PPTX
Domain Driven Design 101
Richard Dingwall
 
PPTX
Domain-Driven Design with SeedStack
SeedStack
 
PPT
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
CHOOSE
 
PDF
Introduction to Event Sourcing and CQRS
Vladik Khononov
 
PPTX
C#Portfolio
Jeriel_Mikell
 
PPT
Linq 090701233237 Phpapp01
google
 
PPTX
Introduction to Event Sourcing and CQRS (IASA-IL)
Vladik Khononov
 
PPTX
Share pointtechies linqtosp-andsbs
Shakir Majeed Khan
 
PDF
Mind Your Business. And Its Logic
Vladik Khononov
 
PPT
Soa Symposium Expressing Service Capabilities Uniformly 2009 10 14 Bc
fuzzyBSc
 
PDF
Dont call me cache java version
Avisi B.V.
 
PPTX
Designing DDD Aggregates
Andrew McCaughan
 
PPTX
Greg Demo Slides
Gregory Renard
 
PDF
Writing good code
Ishti Gupta
 
PPT
Contract First Modeling Services Using Uml
Rody Middelkoop
 
PDF
Jasigsakai12 columbia-customizes-cas
ellentuck
 
PPT
Web Services Part 2
patinijava
 
PPT
Esposito Ajax Remote
ask bills
 
PDF
GraphQL - when REST API is not enough - lessons learned
MarcinStachniuk
 
introduction to Windows Comunication Foundation
redaxe12
 
Domain Driven Design 101
Richard Dingwall
 
Domain-Driven Design with SeedStack
SeedStack
 
Ralf Laemmel - Not quite a sales pitch for C# 3.0 and .NET's LINQ - 2008-03-05
CHOOSE
 
Introduction to Event Sourcing and CQRS
Vladik Khononov
 
C#Portfolio
Jeriel_Mikell
 
Linq 090701233237 Phpapp01
google
 
Introduction to Event Sourcing and CQRS (IASA-IL)
Vladik Khononov
 
Share pointtechies linqtosp-andsbs
Shakir Majeed Khan
 
Mind Your Business. And Its Logic
Vladik Khononov
 
Soa Symposium Expressing Service Capabilities Uniformly 2009 10 14 Bc
fuzzyBSc
 
Dont call me cache java version
Avisi B.V.
 
Designing DDD Aggregates
Andrew McCaughan
 
Greg Demo Slides
Gregory Renard
 
Writing good code
Ishti Gupta
 
Contract First Modeling Services Using Uml
Rody Middelkoop
 
Jasigsakai12 columbia-customizes-cas
ellentuck
 
Web Services Part 2
patinijava
 
Esposito Ajax Remote
ask bills
 
GraphQL - when REST API is not enough - lessons learned
MarcinStachniuk
 
Ad

Recently uploaded (20)

PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
July Patch Tuesday
Ivanti
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Ad

Service Architecture patterns

Editor's Notes

  • #7: Webservices get requests from the client, converts them to domain objects with the help of mappers/repositories, call services with these domain objects, these services orchestrate the domain logic and they will use the repository to write to the database
  • #12: monolithic architecture diagram (also draw front end box) test, deploy....no decoupling....small pieces, easier to understand, can be worked upon independently.
  • #17: Customer/Accounts and Transactions. Caching, batched request might work. Sometimes join at database level is the only resolution.
  • #21: Opening account with starting balance. AccountService and TransactionService
  • #25: Multiple domain representation Need to fix write ownership Services coupling via database
  • #54: We haven’t used sub-classes
  • #65: Accidental or essential
  • #70: Add more members
  • #71: Need code sample for Dynamic Proxy here.
  • #76: I still have duplication. And I have to modify my equals method to look at any new members added – this is error prone. Equals might have a specific meaning – Id equality for example. Use a method like MemberEquals.
  • #77: Complicated to implement – with lists, nested objects.
  • #78: Easy to implement. Memory intensive if you have a deep object graph - Avoid deep object graphs on the UI. Or clone only that portion of the object graph which is different – problem: You’ll need a special equals which you have to keep in sync when new members are added, etc.
  • #80: Should this be CLOBs and/or BLOBs in the DB?
  • #86: If the XML Schema changes or if the Class definition changes. When could you use it: if the data is stored only for reference (eg:. Quotes from the quoting engine are valid for 30 days if the accompanying XML response is stored untampered for that period) - probably store the digitally signed message from the other system. Might consider also storing the data in a normalised form if you need to do anything else with it. Storing presentations/attachments - if the object is really large, consider moving it out of the DB and on to the file system with a reference to the location. Problem with this is that you are trading off the DB performance/size with consistency issues and more complexity dealing with two different places where the truth is stored. pros: performance and development simplicity Eg: Insurecom - we were getting XML from a quoting engine. Had to update the XML with new values and send it across. The logic to do this became fairly painful even tho' we only had to update a couple of places in the XML. Also we only ever had to deal with one policy at a time - the user never wanted to deal with all the policies which have a risk rating above 0.8 in one shot, etc.
  • #87: Eg. Quotes from a quoting engine are valid for 30 days if the accompanying XML response is stored untampered for that period – you probably want to store the message signed by the quoting engine’s private key in your DB as a BLOB. If the blob is really large, consider storing it outside the DB with a link to the location.
  • #89: Should this be CLOBs and/or BLOBs in the DB?