Service-Oriented Design with Ruby and Rails

Paperback (Print)
Used and New from Other Sellers
Used and New from Other Sellers
from $21.45
Usually ships in 1-2 business days
(Save 57%)
Other sellers (Paperback)
  • All (7) from $21.45   
  • New (5) from $37.54   
  • Used (2) from $21.45   


The Complete Guide to Building Highly Scalable, Services-Based Rails Applications

Ruby on Rails deployments are growing, and Rails is increasingly being adopted in larger environments. Today, Rails developers and architects need better ways to interface with legacy systems, move into the cloud, and scale to handle higher volumes and greater complexity. In Service-Oriented Design with Ruby and Rails Paul Dix introduces a powerful, services-based design approach geared toward overcoming all these challenges. Using Dix’s techniques, readers can leverage the full benefits of both Ruby and Rails, while overcoming the difficulties of working with larger codebases and teams.

Dix demonstrates how to integrate multiple components within an enterprise application stack; create services that can easily grow and connect; and design systems that are easier to maintain and upgrade. Key concepts are explained with detailed Ruby code built using open source libraries such as ActiveRecord, Sinatra, Nokogiri, and Typhoeus. The book concludes with coverage of security, scaling, messaging, and interfacing with third-party services.

Service-Oriented Design with Ruby and Rails will help you

  • Build highly scalable, Ruby-based service architectures that operate smoothly in the cloud or with legacy systems
  • Scale Rails systems to handle more requests, larger development teams, and more complex code bases
  • Master new best practices for designing and creating services in Ruby
  • Use Ruby to glue together services written in any language
  • Use Ruby libraries to build and consume RESTful Web services
  • Use Ruby JSON parsers to quickly represent resources from HTTP services
  • Write lightweight, well-designed API wrappers around internal or external services
  • Discover powerful non-Rails frameworks that simplify Ruby service implementation
  • Implement standards-based enterprise messaging with Advanced Message Queuing Protocol (AMQP)
  • Optimize performance with load balancing and caching
  • Provide for security and authentication
Read More Show Less

Product Details

  • ISBN-13: 9780321659361
  • Publisher: Addison-Wesley
  • Publication date: 9/3/2010
  • Series: Addison-Wesley Professional Ruby Series
  • Pages: 297
  • Sales rank: 998,604
  • Product dimensions: 7.00 (w) x 9.00 (h) x 0.70 (d)

Meet the Author

Paul Dix is co-founder and CTO at In the past, he has worked at Google, Microsoft, McAfee, Air Force Space Command, and multiple startups, filling positions as a programmer, software tester, and network engineer. He has been a speaker at multiple conferences, including RubyConf, Goruco, and Web 2.0 Expo, on the subjects of service-oriented design, event-driven architectures, machine learning, and collaborative filtering. Paul is the author of multiple open source Ruby libraries. He has a degree in computer science from Columbia University.
Read More Show Less

Table of Contents




About the Author

1 Implementing and Consuming Your First Service 1

What's a Service? 1

Service Requirements 2

The Ruby Tool Set 2

Sinatra 2

ActiveRecord 3


Typhoeus 4

Rspec 4

The User Service Implementation 5

Using GET 6

POSTing a User 11

PUTing a User 13

Deleting a User 15

Verifying a User 16

Implementing the Client Library 18

Finding a User 18

Creating a User 21

Updating a User 22

Destroying a User 24

Verifying a User 24

Putting It All Together 26

Conclusion 26

2 An Introduction to Service-Oriented Design 27

Use of Service-Oriented Design in the Wild 27

Service-Oriented Design Versus Service-Oriented Architecture Versus RESTful-Oriented Architecture 28

Making the Case for Service-Oriented Design 29

Isolation 30

Robustness 34

Scalability 35

Agility 36

Interoperability 37

Reuse 38

Conclusion 38

3 Case Study: Social Feed Reader 41

A Typical Rails Application 41

The Rails Social Feed Reader Application 45

Features 46

Current Setup 46

Converting to Services 54

Segmenting into Services 54

Breaking Up the Application into Services 54

Conclusion 58

4 Service and API Design 59

Partitioning Functionality into Separate Services 59

Partitioning on Iteration Speed 60

Partitioning on Logical Function 61

Partitioning on Read/Write Frequencies 62

Partitioning on Join Frequency 63

Versioning Services 64

Including a Version in URIs 64

Using Accept Headers for Versioning 65

URIs and Interface Design 66

Successful Responses 68

HTTP Status Codes 68

HTTP Caching 69

Successful Response Bodies 70

Error Responses 72

HTTP Status Codes 72

Error Response Bodies 72

Handling Joins 73

Storing References 73

Joining at the Highest Level 74

Beware of Call Depth 75

API Complexity 75

Atomic APIs 76

Multi-Gets 76

Multiple Models 77

Conclusion 78

5 Implementing Services 79

The Vote Service 79

A Multi-Get Interface 81

The Vote Interface 82

API Design Guidelines 85

Models 86

Rails 88

Rails 2.3 Routes 88

Rails 3 Routes 89

The Rails Controller 90

Sinatra 95

Rack 100

Conclusion 106

6 Connecting to Services 107

Blocking I/O, Threading, and Parallelism 107

Asynchronous I/O 108

Multi-threading 108

Typhoeus 109

Making Single Requests 109

Making Simultaneous Requests 111

Multi-threaded Requests 113

JRuby 115

Logging for Performance 117

Handling Error Conditions 118

Testing and Mocking Service Calls 119

Requests in Development Environments 121

Conclusion 121

7 Developing Service Client Libraries 123

Packaging 123

Jeweler 124

Building and Deploying a Library 127

Parsing Logic 127

The JSON Gem 128

YAJL Ruby 129

Wrapping Parsed Results 130

ActiveModel 132

Validations 132

Serialization 134

Connection and Request Logic 136

Data Reads 136

Data Writes 142

Mocks, Stubs, and Tests 143

Conclusion 146

8 Load Balancing and Caching 147

Latency and Throughput 147

Load Balancing 148

Load Balancing Algorithms 148

Implementing Load Balancing 152

Caching with Memcached 155

The Memcached Client and ActiveRecord 156

Time-Based Expiration 158

Manual Expiration 159

Generational Cache Keys 160

HTTP Caching 162

Expiration-Based Caching 162

Validation-Based Caching 163

Implementing HTTP Caching 165

Conclusion 166

9 Parsing XML for Legacy Services 167

XML 167


Nokogiri 174

SOAP 177

Exploring Web Services with a WSDL File 177

Making Requests 180

Conclusion 184

10 Security 185

Authentication 185

HTTP Authentication 186

Signing Requests 187

SSL for Authentication 198

Authentication for Rails Applications 199

Authorization 201

Firewalls 201

An RBAC Authorization Service 203

Encryption 209

SSL for Encryption 210

Public/Private Key Pairs for Encryption 210

Conclusion 214

11 Messaging 215

What Is Messaging? 215

Synchronous Versus Asynchronous Messaging 216

Queues 217

Message Formats 217

RabbitMQ and AMQP 217

Queues in RabbitMQ 218

Exchanges and Bindings 218

Durability and Persistence 223

Client Libraries 224

Synchronous Reads, Asynchronous Writes 227

HTTP-Based Reads 227

Messaging-Based Writes 227

The CAP Theorem 230

Eventual Consistency 231

Designing Around Consistency 232

Data is the API 234

Operations on Fields 234

Modifications to Field Operations 235

Conclusion 236

12 Web Hooks and External Services 237

Web Hooks 238

PubSubHubbub 239

Receiving Web Hooks 240

Providing Web Hooks 242

Strategies for Dealing with Failure 244

OAuth 245

Implementing an OAuth Consumer 246

Implementing an OAuth Provider 249

Integrating with External Services 251

Consuming Data 251

Pubshing Data 253

The Request Lifecycle 254

Worker Processes 254

Ensuring Performance and Reliability 258

Segregating Queues 259

Metrics 259

Throttling and Quotas 260

Conclusion 261

Appendix RESTful Primer 263

Roy Fielding's REST 263

Constraints 264

Architectual Elements 264

Architectual Views 265

REST and Resources 265

URIs and Addressability 266

Representations 267

HTTP and the Uniform Interface 268

HTTP Methods 268

HTTP Headers 271

HTTP Status Codes 274

Conclusion 275

Index 277

Read More Show Less

Customer Reviews

Average Rating 5
( 1 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing 1 Customer Reviews
  • Posted September 23, 2010

    Highly Recommended

    Authoritative and well written.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing 1 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)