Building for Success and Failure with Disqus

A presentation at AtlantaPHP in October 2014 in Atlanta, GA, USA by Jonathon Hill

Slide 1

Slide 1

Building for Success and Failure with AtlantaPHP, October 2014

Slide 2

Slide 2

“Let’s Build a Blog!” Says Every Developer Ever

Slide 3

Slide 3

Slide 4

Slide 4

Slide 5

Slide 5

What is it? • Discussion web service • Free as in beer • Integrates with everything • Quality content • OAuth and SSO • Embeddable widget • Web API

Slide 6

Slide 6

Slide 7

Slide 7

Slide 8

Slide 8

Slide 9

Slide 9

Slide 10

Slide 10

Fundamentals A crash course

Slide 11

Slide 11

Forum Thread Post

Slide 12

Slide 12

Category Limitations • Categories may only be created using the API. • Moderation may not be performed on posts by Category, only by Forum and Thread.

Slide 13

Slide 13

Disqus API threads/create threads/list posts/create posts/list posts/report Full documentation is available at http://disqus.com/api

Slide 14

Slide 14

Registering Your App https://disqus.com/api/applications /register/ 1. Specify Domains 2. Set Permissions Read Read and Write Read, Write, and Manage 3. Save Tokens Access Token API Key API Secret

Slide 15

Slide 15

Create a Forum https://disqus.com/admin/create/ 1. Name your site 2. Specify a unique domain Creating an application does not implicitly create a forum!

Slide 16

Slide 16

Posting to Disqus As a user Authenticate via OAuth As a guest 1. Enable “Allow guests to comment” (Settings > General) 2. Application domain must be set correctly 3. Use the magic API key: E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7 C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F

Slide 17

Slide 17

drexarj/disqus-php github.com/disqus/disqus-php Composer: drexarj/disqus-php

Slide 18

Slide 18

Slide 19

Slide 19

What could possibly go wrong?

Slide 20

Slide 20

Slide 21

Slide 21

Slide 22

Slide 22

Slide 23

Slide 23

Caching to the Rescue

Slide 24

Slide 24

Caching to the Rescue

Slide 25

Slide 25

It’s Dynamic Data… • New posts submitted • Moderator approves post • Moderator disapproves post • User flags a post as objectionable

Slide 26

Slide 26

Conflicting Objectives • High load • • Short cache expiration Failover • No cache expiration • How to synchronize?

Slide 27

Slide 27

Adding a Failover Cache burst cache 1 2 3 failover cache

Slide 28

Slide 28

Failing Over burst cache 1 2 3 failover cache

Slide 29

Slide 29

Adding a Health Check burst cache 1 2 3 4 failover cache

Slide 30

Slide 30

Caching Health Status • If health status expires, everything just fails over • Adjust the health status expiration to back off: • FAIL 1: expiration=2 minutes • FAIL 2: expiration=4 minutes • FAIL 3: expiration=8 minutes • …etc

Slide 31

Slide 31

“Is it worth it?” –You

Slide 32

Slide 32

Slide 33

Slide 33

Implementation: Cache Servers • Burst: memcached • Failover: MongoDB (or Redis)

Slide 34

Slide 34

Implementation: Scripts • Health check • Cache warmup • Thread creation

Slide 35

Slide 35

Implementation: API Client • Guzzle-based client (compwright/disguz) • Custom Guzzle Cache adapters

Slide 36

Slide 36

Building for Success and Failure with AtlantaPHP, October 2014

Slide 37

Slide 37

Thank you! • https://github.com/compwright/disqus-demo • https://github.com/compwright/disguz • https://github.com/compwright/disqus-cli Feedback: https://joind.in/12119