microservices using python and oracle - proligence › pres › ioug18 › microservices.pdf ·...

29
Microservices using Python and Oracle Arup Nanda Longtime Oracle DBA And Explorer of New Things

Upload: others

Post on 30-May-2020

22 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Microservices

using Python and OracleArup Nanda

Longtime Oracle DBAAnd

Explorer of New Things

Page 2: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Agenda

Microservices with Python and Oracle2

What’s the problem we are trying to solve?

How microservices solves the problem?

How is it different from regular process

How to do it in python and Oracle? Why?

When not to do it

Next Steps to Learn More.

Page 3: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Microservices with Python and Oracle3

procedure my_entire_app (

parameter1 …,

parameter2 …

) is

var1 …;

var200 …;

begin

code line 1;

code line 2;

…..

code line 1000

end;

procedure my_entire_app (

parameter1 …,

parameter2 …,

parameter20 …

) is

var1 …;

var500 …;

begin

code line 1;

code line 2;

…..

code line 5000;

end;

procedure my_entire_app (

parameter1 …,

parameter2 …,

parameter50 …

) is

var1 …;

var2000 …;

begin

code line 1;

code line 2;

…..

code line 10000;

end;

Page 4: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Microservices with Python and Oracle4

procedure my_entire_app (

parameter1 …,

parameter2 …,

parameter50 …

) is

var1 …;

var2000 …;

begin

code line 1;

code line 2;

…..

code line 10000;

end;

package my_entire_app (

procedure manage_cust;

procedure manage_order;

procedure manage_payment;

Page 5: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

package

Microservices with Python and Oracle5

Procedure 1

Procedure 2

Procedure 3

Procedure 4

Page 6: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Scaling up

Microservices with Python and Oracle6

Page 7: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Problems with monoliths

• Risk of change to any functionality

• Lack of innovation

• Compile time

• Exposure to failure

• Scalability.

Microservices with Python and Oracle7

Page 8: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

package

Microservices with Python and Oracle8

Procedure 1

Procedure 2

Procedure 3

Procedure 4

Page 9: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

package4

package3package2

package1

Microservices with Python and Oracle9

Procedure 1

Procedure 2

Procedure 3

Procedure 4Asynchronous

Page 10: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Stateful Problem

• Typical application

– Connect to database

– Fetch something

– Let the database handle where the last fetch was done

Microservices with Python and Oracle10

Page 11: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Microservices with Python and Oracle11

package4

package3package2

package1

Procedure 1

Procedure 2

Procedure 3

Procedure 4Asynchronous

Stateless

API Call

Page 12: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

API Call Example

Microservices with Python and Oracle12

Browser

Google API

Page 13: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Analogy to a typical app

Microservices with Python and Oracle13

C

R

U

D

CREATE

READ

UPDATE

DELETE

POST

GET

PUT

DELETEhttp

REST APIInsert

Select

Update

Delete

Page 14: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Structure of HTTP Requests

Microservices with Python and Oracle14

Request Response

MethodGET

POST

PUT

DELETE

Path/get/prod

uct

Query?product_

id=12

HeaderType of language

cookies

Bodyjson {}

Status Code200 OK

404 Not Found

HeaderType of language

Bodyjson {}

Page 15: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

package4

package3package2

package1

Microservices with Python and Oracle15

Procedure 1

Procedure 2

Procedure 3

Procedure 4

REST API

REST API

REST API

REST API

Page 16: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Microservices with Python and Oracle16

package4

package3package2

package1

Procedure 1

Procedure 2

Procedure 3

Procedure 4

REST API

REST API

REST API

REST API

Microservice

Page 17: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

service–oriented

architecture

composed of

loosely coupled

elements

that have

bounded contexts

Microservices with Python and Oracle17

package4

package3package2

package1

Procedure 1

Procedure 2

Procedure 3

Procedure 4

REST API

REST API

REST API

REST API

Page 18: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Do One Thing Only, and Well

Microservices with Python and Oracle18

Page 19: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Microservices with Python and Oracle19

Page 20: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Microservices with Python and Oracle20

Microservice 1 Microservice 2 Microservice 3

APIAPI API

Application

http requestjsonresponse

Page 21: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Putting it Together

Microservices with Python and Oracle21

Microservice 1

Microservice 2

Microservice 3

APIAPI API

http requestjsonresponse

Python for the actual microservices code

HTTP processing: Flask

Database Connectivity: cx_Oraclepython –m pip install Flask

python –m pip install cx_Oracle

Page 22: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Python Codefrom flask import Flask, redirect, url_for, request, render_template

app = Flask(__name__)

hotelavail={

1:

{'Room1':10,'Room2':5,'Room3':7},

2:

{'Room1':9,'Room2':2,'Room3':0},

3:

{'Room1':6,'Room2':11,'Room3':3}

}

@app.route('/avail', methods= ['GET'])

def avail():

if request.method == 'GET':

hotelid = int(request.args.get('hotelid'))

return render_template('list_avail.html',dict=hotelavail[hotelid])

else:

Null

if __name__ == '__main__':

app.run(debug=1)

Microservices with Python and Oracle22

C:\> python hotel.py

Page 23: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Code to Get from Databasefrom flask import Flask, redirect, url_for, request, render_template

import cx_Oracle as cxo

app = Flask(__name__)

def getHotelAvail(hotelid):

conn = cxo.connect('hr','hr','10.12.8.43:1521/orcl')

c1 = conn.cursor()

c1.prepare('select room_type, avail from avail where hotel_id = :hotelid')

c1.execute(None,{'hotelid':int(hotelid)})

hotelavail = dict(c1.fetchall())

return hotelavail

@app.route('/avail', methods= ['POST','GET'])

def avail():

if request.method == 'GET':

hotelid = int(request.args.get('hotelid'))

hotelavail = getHotelAvail(hotelid)

return render_template('list_avail.html',dict=hotelavail)

else:

return Null

if __name__ == '__main__':

app.run(debug=1)

Microservices with Python and Oracle23

Page 24: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Python for PL/SQL Professionals

http://bit.ly/python4plsql

Microservices with Python and Oracle24

Page 25: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Microservices with Python and Oracle25

How is it different from

Service Oriented

Architecture

Page 26: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Microservices with Python and Oracle26

SOA Microservices

Page 27: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Microservices with Python and Oracle27

Service 1 Service 2

Service 3 Service 4

Message Broker

REST MQ

RESTMQ

MicroservicesSOA

Service 1 Service 2

Service 3 Service 4

REST REST

Page 28: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

When it’s NOT good

• When you don’t need to scale

• When the database transactions are important across the services

Microservices with Python and Oracle28

Pay money Get money

BALANCE

Saga

Page 29: Microservices using Python and Oracle - Proligence › pres › ioug18 › microservices.pdf · Microservices with Python and Oracle 2 What’s the problem we are trying to solve?

Thank You!

Blog: arup.blogspot.comTweeter: @ArupNandaFacebook.com/ArupKNandaGoogle Plus: +ArupNanda

29Microservices with Python and Oracle