Logging service design

32
Logging Service Design For Web Application

Transcript of Logging service design

Page 1: Logging service design

Logging Service DesignFor Web Application

Page 2: Logging service design

Contents● Logging

● What is Logging?● Web application architecture● Problem● Centralizing● Middleware● Application log● Microservice● Events to log● Technical pitfalls

○ Disk space○ Transport protocols○ Choosing Log Storage

● Processing○ Lambda architecture

Page 3: Logging service design

What is Logging?When application writing activities or events to somewhere. generally writing in file system.

Page 4: Logging service design

Web Application Architecture

web server app server database

Page 5: Logging service design

Web Application Architecture

web server app server database

Log Log Log

Page 6: Logging service design

Logging Purposes

web server

Log

Monitoring on server status access/error/redirect.Commonly in the form of STDOUT/STDERR

Page 7: Logging service design

Logging Purposes

app server

Log

Monitor events within application

Page 8: Logging service design

Logging Purposes

Database

Log

Searching for underlying problems that happened in database level

E.g. Duplicate transactions

Page 9: Logging service design

Web Application Architecture(cluster)

web server app server database

web server

web server app server

app server

database

database

Page 10: Logging service design

Web Application Architecture(cluster)

web server app server database

web server

web server app server

app server

database

database

LogLogLog LogLogLog LogLogLog

Page 11: Logging service design

Problem?Logging seperately in each instances cost extra work searching for problems and lack flexiblity to log other meaningful events.

Page 12: Logging service design

Centralizing

web server

web server

web server

LogMiddleware

Page 13: Logging service design

MiddlewareSet of tools that manage underlying work for software

E.g. a middleware to manage HTTP request, redirect assets path.

In this case, we use middleware to interrupt and send log to somewhere else

Page 14: Logging service design

Centralizing example: NGINX

nginx

nginx

nginx

redisOpenrestyredis2-nginx

Page 15: Logging service design

Centralizing example: NGINX(2)

nginx

nginx

nginx

ElasticsearchLogstashOpenresty

Page 16: Logging service design

Application logLog all events in application

Using similar strategy to web server log.By modifying appication middleware and send log to somewhere else

Page 17: Logging service design

Application log example: NodeJS(Express)

express

express

express

redisCustom

ExpressJSMidddleware

Page 18: Logging service design

Other middleware to use?Rack in Ruby server

net/http in Go server

Etc. (existed in all popular programming langauge and framework)

Page 19: Logging service design

Application log(custom)Log other meaningful events

Using different strategy.By modifying appication itself and insert log statement when events actually occur.

imagine console.log(‘other’); in browser

Page 20: Logging service design

Events to logUser Sign-in

User Register

User select something

User click on something

Referer to that page

Typical everything you could, you wouldn’t know what problem you’ll want to solve in the future.

Page 21: Logging service design

Application log(custom): ProblemInserting log statement directly in the application will used up computing, I/O resources and obstruct actual flows, may cause discomfort for users.

Page 22: Logging service design

Microservice: How can it solve the problem?Only for 1 purpose, log processing.

Instead of compute directly, send keys and values to microservice and let it handle in another resources

Page 23: Logging service design

Why Microservice?Application log need some processing to format log statement

Cause the obstruction

Can be distributed

Decoupled computing resources

Page 24: Logging service design

Example: User sign-out with log

User sign-out

Sign-outcompleted

● Destroy User session from database● Create log statement object saying User

signing-out at certain time● Format log statement, save only user_id,

format datetime● Save log statement on storage● Redirect to sign-out completed

Page 25: Logging service design

Example: User sign-out with log on microservice

User sign-out

Sign-outcompleted

● Destroy User session from database● Send log params to service● Redirect to sign-out completed

● Create log statement object saying User signing-out at certain time

● Format log statement, save only user_id, format datetime

● Save log statement on storage

Page 26: Logging service design

Web Application Architecture (now)

web server app server database

middleware

Log storage (elasticsearch, redis, etc)

middleware middleware

service

Page 27: Logging service design

Technical pitfall: Transport protocolUDP

TCP

HTTP

HTTPS/SSL

Page 28: Logging service design

Technical pitfall: Transport protocolWhen sending log parameters to service

Use UDP with non-critical and have massive amount E.g. User clicked at navbar

Use TCP/HTTP connection in crucial informationE.g User go to checkout page

Use HTTPS/SSL when connecting to logging service directly from clients

No need for HTTPS/SSL in between infrastructure

Page 29: Logging service design

Technical pitfall: Disk spacePrepare counter-measures for disk space management

When running out of disk space

When storage instances are down

When migrate old log statements to new storage

Warning: It used up a lot when in production.

Page 30: Logging service design

Technical pitfall: Choosing Log StorageFile system is a no-no, consider using tool that can scale easily.

Redis

Elasticsearch

Cassandra

MongoDB

etc.

Page 31: Logging service design

Where to go from here

Log Storage

Storm

Spark

ServingDatabase

Query from app

Page 32: Logging service design

Q&A