SlideShare a Scribd company logo
SWIFT MICRO-SERVICES
AND AWSTECHNOLOGIES
Simon Pilkington
Senior Software Engineer
CoreTechnology
AmazonVideo
ABOUT ME
• 4 years helping architect, build and
maintain frameworks for Amazon.com
• Recently moved to CoreTechnology in
AmazonVideo
• Grew up in Melbourne,Australia
WHY SWIFT?
WHY IS JAVA PREVALENT?
• Not significant learning curve
• Harder to make mistakes than C++
• Enables higher developer velocity to create
WHY LOOK BEYOND JAVA?
Build Logic What's included
This package includes tools to help with:
• Code Coverage (JaCoco, PIT)
• Code Style (Checkstyle and matching IntelliJ formatter)
• Code Quality (FindBugs, PMD, Copy Paste Detector, JDepend).
CODE GENERATION FOR SWIFT SERVICE
• Code Generation of model objects, operation stubs and unit tests
• Use Codable conformance for serialization and de-serialization
• Swagger document can also be passed to Cloud Formation to create an API Gateway to
front the service.
Generated Code /**
Handler for the HelloWorld operation.
- Parameters:
- input: The validated HelloWorldRequest object being passed to this operation.
- context: The activities context provided for this operation.
- Returns: The HelloWorldResponse object to be passed back from the caller of this operation.
Will be validated before being returned to caller.
*/
func handleHelloWorld(input: HelloWorldModel.HellowWorldRequest,
context: HellowWorldActivitiesContext) -> HelloWorldModel.HellowWorldResponse {
return HelloWorldModel.HelloWorldResponse(greeting: "Hello (input.name)")
}
RUNTIME
• Initial proof of concept as a container running on ECS
• Using an implementation of IBM’s LoggerAPI to write logs to Cloudwatch
• Retrieve AWS credentials from the container with automatic credential
rotation
• Manages health checks, unresponsive containers are automatically
replaced
DATABASE SERIALIZATION
Code
Code
struct Fruit: Codable {
let fruitID: FruitID
let accessRole: AccessRole
let sweet: Int
let sour: Int
}
struct Location: Codable {
let locationID: LocationID
let fruitID: FruitID
let locationPath: String
let locationType: LocationType
let checksum: Int
let checksumType: ChecksumType
}
• Large datasets or fast concurrent access more suited to NOSQL
databases
• Database schema based around data access patterns to enable efficient
queries
• DynamoDb’s DynamoDBMapper in the Java AWS SDK
implements optimistic locking by managing an invisible row
version attribute
• Currently there is a pull request to implement polymorphic
tables similarly using inheritance and managing an invisible
subclass attribute
But Inheritance…
PROTOCOLSTOTHE RESCUE!
Probably look familiar
Swift Language public protocol Encodable {
public func encode(to encoder: Encoder) throws
}
public protocol Decodable {
public init(from decoder: Decoder) throws
}
public typealias Codable = Decodable & Encodable
DYNAMO SPECIFIC ENCODING
JSON {
"Name": {"S": "Citrus"}
"Description": {"S": "They’re alright."}
}
DynamoDb
Codable
Object
Codable
Object
DynamoEncoder JSONEncoder
DynamoDecoder JSONDecoder
OPERATION IMPLEMENTATION
Code func handleRegisterFamily(input: FruitModel.FamilyAttributes,
context: FruitActivitiesContext)
throws -> FruitModel.FamilyIdentity {
let currentID = context.idGenerator()
let partitionKey = familyKeyPrefix + currentID
let key = DefaultIdentityCompositePrimaryKey(partitionKey: partitionKey,
sortKey: partitionKey)
let newDatabaseRow = TypedDatabaseItem.newItem(withKey: key, andValue: input)
try context.dynamoClient.putItem(newDatabaseRow)
return FruitModel.FamilyIdentity(familyID: partitionKey)
}
TYPEDDATABASEITEM
• Handles row type, versioning, create and last modified timestamps.
• Accepts a row value conforming to Codable
• By default a newTypedDatabaseItem will fail to overwrite an existing
row
• CompositePrimaryKey defines row identity - partition and sort keys;
generic in a protocol that defines the key attribute names
Library Code
public struct TypedDatabaseItem<RowIdentity : DynamoRowIdentity, RowType : Codable>: Codable {
...
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
let storedRowTypeName = try values.decode(String.self, forKey: .rowType)
self.createDate = try values.decode(Date.self, forKey: .createDate)
// get the type that is being requested to be decoded into
let requestedRowTypeName = getTypeRowIdentity(type: RowType.self)
// if the stored rowType is not what we should attempt to decode into
guard storedRowTypeName == requestedRowTypeName else {
// throw an error to avoid accidentally decoding into the incorrect type
throw SwiftDynamoError.typeMismatch(expected: storedRowTypeName,
provided: requestedRowTypeName)
}
self.compositePrimaryKey = try CompositePrimaryKey(from: decoder)
self.rowStatus = try RowStatus(from: decoder)
self.rowValue = try RowType(from: decoder)
self.canOverwriteExistingRow = false
self.onlyOverwriteVersionNumber = nil
}
}
• createUpdatedItem function creates a new instance with updated last
modified timestamp and incremented row version.
• By default will fail to overwrite a row version other than the version
it was created from
Code let updatedFruitRow =
fruitDatabaseItem.createUpdatedItem(withValue: updatedFruitAttributes)
do {
try context.dynamoClient.putItem(updatedAccountRow)
} catch SwiftDynamoError.conditionalCheckFailed(_) {
// handle the error
}
BUT WHAT ABOUT QUERIES?
AGAIN PROTOCOLSTOTHE RESCUE
• Similar toTypedDatabaseItem but returns a row type of Codable, de-
serialized according to the type specified in the data row
Library Code public protocol PossibleItemTypes {
static var types: [Codable.Type] { get }
}
public struct PolymorphicDatabaseItem<RowIdentity : DynamoRowIdentity,
PossibleTypes : PossibleItemTypes> : Decodable {
...
}
A FINAL ODETO PROTOCOLS
Generated Code public protocol LocationShape {
associatedtype LocationTypeType : CustomStringConvertible
associatedtype ChecksumTypeType : CustomStringConvertible
var locationPath: String { get }
var locationType: LocationTypeType { get }
var checksum: String { get }
var checksumType: ChecksumTypeType { get }
func asFruitModelLocation() throws -> Location
}
Code extension SaladModel.Location : FruitModel.LocationShape {}
...
let location = try input.location.asFruitModelLocation()

More Related Content

PPTX
JavaScript Basics - GameCraft Training
ZIP
Cappuccino - A Javascript Application Framework
PDF
Advanced realm in swift
PDF
Ruby On Rails Intro
PDF
Realm database
PDF
Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)
PPTX
Turbo charging v8 engine
ODP
Scal`a`ngular - Scala and Angular
JavaScript Basics - GameCraft Training
Cappuccino - A Javascript Application Framework
Advanced realm in swift
Ruby On Rails Intro
Realm database
Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)
Turbo charging v8 engine
Scal`a`ngular - Scala and Angular

What's hot (20)

PPTX
Groovy on Grails by Ziya Askerov
PDF
Realm of the Mobile Database: an introduction to Realm
PDF
Useful and Practical Functionalities in Realm
PPTX
From Ruby to Scala
PPTX
Guild Prototype
PDF
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
PDF
Slot Composition
PDF
Slot Composition
ODP
jTransfo quickie at JavaZone 2015
PDF
Type Profiler: An Analysis to guess type signatures
PDF
JavaScript Good Practices
PPTX
Node.js code tracing
PPTX
JS Event Loop
PDF
Android course session 5 (Threads & socket)
PDF
Introducing Troy Scala IO 2016
PPT
OOP in JavaScript
PDF
Painless Persistence with Realm
PPTX
Children of Ruby
Groovy on Grails by Ziya Askerov
Realm of the Mobile Database: an introduction to Realm
Useful and Practical Functionalities in Realm
From Ruby to Scala
Guild Prototype
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
Slot Composition
Slot Composition
jTransfo quickie at JavaZone 2015
Type Profiler: An Analysis to guess type signatures
JavaScript Good Practices
Node.js code tracing
JS Event Loop
Android course session 5 (Threads & socket)
Introducing Troy Scala IO 2016
OOP in JavaScript
Painless Persistence with Realm
Children of Ruby
Ad

Similar to Swift Micro-services and AWS Technologies (20)

PPTX
Silicon Valley JUG - How to generate customized java 8 code from your database
PPTX
How to generate customized java 8 code from your database
PPTX
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
PPTX
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
PDF
Painless Persistence in a Disconnected World
PDF
Spark schema for free with David Szakallas
PPTX
Jdbc presentation
PDF
Variables in Pharo5
PDF
First class Variables in Pharo
PDF
Spring Day | Spring and Scala | Eberhard Wolff
PDF
Scala and Spring
PPT
Auto cad 2006_api_overview
PDF
Raffaele Rialdi
PDF
Big Data, Data Lake, Fast Data - Dataserialiation-Formats
PDF
Moder Java-WeAreDevelopers - Berlin - 2024.pdf
PPTX
Grails
PPTX
Grails
PPTX
Intro to node and mongodb 1
PPTX
Using the Tooling API to Generate Apex SOAP Web Service Clients
PDF
Naver_alternative_to_jpa
Silicon Valley JUG - How to generate customized java 8 code from your database
How to generate customized java 8 code from your database
JavaOne2016 - How to Generate Customized Java 8 Code from Your Database [TUT4...
How to JavaOne 2016 - Generate Customized Java 8 Code from Your Database [TUT...
Painless Persistence in a Disconnected World
Spark schema for free with David Szakallas
Jdbc presentation
Variables in Pharo5
First class Variables in Pharo
Spring Day | Spring and Scala | Eberhard Wolff
Scala and Spring
Auto cad 2006_api_overview
Raffaele Rialdi
Big Data, Data Lake, Fast Data - Dataserialiation-Formats
Moder Java-WeAreDevelopers - Berlin - 2024.pdf
Grails
Grails
Intro to node and mongodb 1
Using the Tooling API to Generate Apex SOAP Web Service Clients
Naver_alternative_to_jpa
Ad

Recently uploaded (20)

PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
ai tools demonstartion for schools and inter college
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Online Work Permit System for Fast Permit Processing
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPT
Introduction Database Management System for Course Database
PDF
AI in Product Development-omnex systems
PDF
medical staffing services at VALiNTRY
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
history of c programming in notes for students .pptx
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
ai tools demonstartion for schools and inter college
Design an Analysis of Algorithms II-SECS-1021-03
Upgrade and Innovation Strategies for SAP ERP Customers
2025 Textile ERP Trends: SAP, Odoo & Oracle
Which alternative to Crystal Reports is best for small or large businesses.pdf
Online Work Permit System for Fast Permit Processing
Operating system designcfffgfgggggggvggggggggg
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Introduction Database Management System for Course Database
AI in Product Development-omnex systems
medical staffing services at VALiNTRY
Odoo POS Development Services by CandidRoot Solutions
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Design an Analysis of Algorithms I-SECS-1021-03
history of c programming in notes for students .pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
How to Choose the Right IT Partner for Your Business in Malaysia

Swift Micro-services and AWS Technologies

  • 1. SWIFT MICRO-SERVICES AND AWSTECHNOLOGIES Simon Pilkington Senior Software Engineer CoreTechnology AmazonVideo
  • 2. ABOUT ME • 4 years helping architect, build and maintain frameworks for Amazon.com • Recently moved to CoreTechnology in AmazonVideo • Grew up in Melbourne,Australia
  • 4. WHY IS JAVA PREVALENT? • Not significant learning curve • Harder to make mistakes than C++ • Enables higher developer velocity to create
  • 5. WHY LOOK BEYOND JAVA? Build Logic What's included This package includes tools to help with: • Code Coverage (JaCoco, PIT) • Code Style (Checkstyle and matching IntelliJ formatter) • Code Quality (FindBugs, PMD, Copy Paste Detector, JDepend).
  • 6. CODE GENERATION FOR SWIFT SERVICE • Code Generation of model objects, operation stubs and unit tests • Use Codable conformance for serialization and de-serialization • Swagger document can also be passed to Cloud Formation to create an API Gateway to front the service. Generated Code /** Handler for the HelloWorld operation. - Parameters: - input: The validated HelloWorldRequest object being passed to this operation. - context: The activities context provided for this operation. - Returns: The HelloWorldResponse object to be passed back from the caller of this operation. Will be validated before being returned to caller. */ func handleHelloWorld(input: HelloWorldModel.HellowWorldRequest, context: HellowWorldActivitiesContext) -> HelloWorldModel.HellowWorldResponse { return HelloWorldModel.HelloWorldResponse(greeting: "Hello (input.name)") }
  • 7. RUNTIME • Initial proof of concept as a container running on ECS • Using an implementation of IBM’s LoggerAPI to write logs to Cloudwatch • Retrieve AWS credentials from the container with automatic credential rotation • Manages health checks, unresponsive containers are automatically replaced
  • 8. DATABASE SERIALIZATION Code Code struct Fruit: Codable { let fruitID: FruitID let accessRole: AccessRole let sweet: Int let sour: Int } struct Location: Codable { let locationID: LocationID let fruitID: FruitID let locationPath: String let locationType: LocationType let checksum: Int let checksumType: ChecksumType }
  • 9. • Large datasets or fast concurrent access more suited to NOSQL databases • Database schema based around data access patterns to enable efficient queries
  • 10. • DynamoDb’s DynamoDBMapper in the Java AWS SDK implements optimistic locking by managing an invisible row version attribute • Currently there is a pull request to implement polymorphic tables similarly using inheritance and managing an invisible subclass attribute
  • 12. PROTOCOLSTOTHE RESCUE! Probably look familiar Swift Language public protocol Encodable { public func encode(to encoder: Encoder) throws } public protocol Decodable { public init(from decoder: Decoder) throws } public typealias Codable = Decodable & Encodable
  • 13. DYNAMO SPECIFIC ENCODING JSON { "Name": {"S": "Citrus"} "Description": {"S": "They’re alright."} } DynamoDb Codable Object Codable Object DynamoEncoder JSONEncoder DynamoDecoder JSONDecoder
  • 14. OPERATION IMPLEMENTATION Code func handleRegisterFamily(input: FruitModel.FamilyAttributes, context: FruitActivitiesContext) throws -> FruitModel.FamilyIdentity { let currentID = context.idGenerator() let partitionKey = familyKeyPrefix + currentID let key = DefaultIdentityCompositePrimaryKey(partitionKey: partitionKey, sortKey: partitionKey) let newDatabaseRow = TypedDatabaseItem.newItem(withKey: key, andValue: input) try context.dynamoClient.putItem(newDatabaseRow) return FruitModel.FamilyIdentity(familyID: partitionKey) }
  • 15. TYPEDDATABASEITEM • Handles row type, versioning, create and last modified timestamps. • Accepts a row value conforming to Codable • By default a newTypedDatabaseItem will fail to overwrite an existing row • CompositePrimaryKey defines row identity - partition and sort keys; generic in a protocol that defines the key attribute names
  • 16. Library Code public struct TypedDatabaseItem<RowIdentity : DynamoRowIdentity, RowType : Codable>: Codable { ... public init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) let storedRowTypeName = try values.decode(String.self, forKey: .rowType) self.createDate = try values.decode(Date.self, forKey: .createDate) // get the type that is being requested to be decoded into let requestedRowTypeName = getTypeRowIdentity(type: RowType.self) // if the stored rowType is not what we should attempt to decode into guard storedRowTypeName == requestedRowTypeName else { // throw an error to avoid accidentally decoding into the incorrect type throw SwiftDynamoError.typeMismatch(expected: storedRowTypeName, provided: requestedRowTypeName) } self.compositePrimaryKey = try CompositePrimaryKey(from: decoder) self.rowStatus = try RowStatus(from: decoder) self.rowValue = try RowType(from: decoder) self.canOverwriteExistingRow = false self.onlyOverwriteVersionNumber = nil } }
  • 17. • createUpdatedItem function creates a new instance with updated last modified timestamp and incremented row version. • By default will fail to overwrite a row version other than the version it was created from Code let updatedFruitRow = fruitDatabaseItem.createUpdatedItem(withValue: updatedFruitAttributes) do { try context.dynamoClient.putItem(updatedAccountRow) } catch SwiftDynamoError.conditionalCheckFailed(_) { // handle the error }
  • 18. BUT WHAT ABOUT QUERIES?
  • 19. AGAIN PROTOCOLSTOTHE RESCUE • Similar toTypedDatabaseItem but returns a row type of Codable, de- serialized according to the type specified in the data row Library Code public protocol PossibleItemTypes { static var types: [Codable.Type] { get } } public struct PolymorphicDatabaseItem<RowIdentity : DynamoRowIdentity, PossibleTypes : PossibleItemTypes> : Decodable { ... }
  • 20. A FINAL ODETO PROTOCOLS Generated Code public protocol LocationShape { associatedtype LocationTypeType : CustomStringConvertible associatedtype ChecksumTypeType : CustomStringConvertible var locationPath: String { get } var locationType: LocationTypeType { get } var checksum: String { get } var checksumType: ChecksumTypeType { get } func asFruitModelLocation() throws -> Location } Code extension SaladModel.Location : FruitModel.LocationShape {} ... let location = try input.location.asFruitModelLocation()